Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply fixes from StyleCI #1

Merged
merged 1 commit into from
Dec 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Contracts/WebhookEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

interface WebhookEvent
{

}
9 changes: 4 additions & 5 deletions src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
namespace BinaryCats\MailgunWebhooks;

use BinaryCats\MailgunWebhooks\Contracts\WebhookEvent;
use Illuminate\Support\Arr;

class Event implements WebhookEvent
{
/**
* Attributes from the event
* Attributes from the event.
*
* @var array
*/
public $attributes = [];

/**
* Create new Event
* Create new Event.
*
* @param array $attributes
*/
Expand All @@ -25,11 +24,11 @@ public function __construct($attributes)
}

/**
* Construct the event
* Construct the event.
*
* @return Event
*/
public static function constructFrom($data) : Event
public static function constructFrom($data) : self
{
return new static($data);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Exceptions/WebhookFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

class WebhookFailed extends Exception
{
public static function signingSecretNotSet() : WebhookFailed
public static function signingSecretNotSet() : self
{
return new static('The webhook signing secret is not set. Make sure that the `signing_secret` config key is set to the correct value.');
}

public static function jobClassDoesNotExist(string $jobClass, WebhookCall $webhookCall): WebhookFailed
public static function jobClassDoesNotExist(string $jobClass, WebhookCall $webhookCall): self
{
return new static("Could not process webhook id `{$webhookCall->id}` of type `{$webhookCall->type} because the configured jobclass `$jobClass` does not exist.");
}

public static function missingType(WebhookCall $webhookCall): WebhookFailed
public static function missingType(WebhookCall $webhookCall): self
{
return new static("Webhook call id `{$webhookCall->id}` did not contain a type. Valid Mailgun webhook calls should always contain a type.");
}
Expand Down
5 changes: 2 additions & 3 deletions src/Jobs/HandleDelivered.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class HandleDelivered
use Dispatchable, SerializesModels;

/**
* Bind the implementation
* Bind the implementation.
*
* @var Spatie\WebhookClient\Models\WebhookCall
*/
protected $webhookCall;

/**
* Create new Job
* Create new Job.
*
* @param Spatie\WebhookClient\Models\WebhookCall $webhookCall
*/
Expand All @@ -34,6 +34,5 @@ public function __construct(WebhookCall $webhookCall)
*/
public function handle()
{

}
}
11 changes: 5 additions & 6 deletions src/MailgunSignatureValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,33 @@
namespace BinaryCats\MailgunWebhooks;

use Exception;
use BinaryCats\MailgunWebhooks\Webhook;
use Illuminate\Http\Request;
use Spatie\WebhookClient\WebhookConfig;
use Spatie\WebhookClient\SignatureValidator\SignatureValidator;
use Spatie\WebhookClient\WebhookConfig;

class MailgunSignatureValidator implements SignatureValidator
{
/**
* Bind the implemetation
* Bind the implemetation.
*
* @var Illuminate\Http\Request
*/
protected $request;

/**
* Inject the config
* Inject the config.
*
* @var Spatie\WebhookClient\WebhookConfig
*/
protected $config;

/**
* True if the signature has been valiates
* True if the signature has been valiates.
*
* @param Illuminate\Http\Request $request
* @param Spatie\WebhookClient\WebhookConfig $config
*
* @return boolean
* @return bool
*/
public function isValid(Request $request, WebhookConfig $config): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/MailgunWebhooksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class MailgunWebhooksController
{
/**
* Invoke controller method
* Invoke controller method.
*
* @param \Illuminate\Http\Request $request
* @param string|null $configKey
Expand Down
2 changes: 1 addition & 1 deletion src/MailgunWebhooksServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class MailgunWebhooksServiceProvider extends ServiceProvider
{
/**
* Boot application services
* Boot application services.
*
* @return void
*/
Expand Down
4 changes: 2 additions & 2 deletions src/ProcessMailgunWebhookJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
class ProcessMailgunWebhookJob extends ProcessWebhookJob
{
/**
* Name of the payload key to contain the type of event
* Name of the payload key to contain the type of event.
*
* @var string
*/
protected $key = 'event-data.event';

/**
* Handle the process
* Handle the process.
*
* @return void
*/
Expand Down
8 changes: 3 additions & 5 deletions src/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

namespace BinaryCats\MailgunWebhooks;

use BinaryCats\MailgunWebhooks\Exceptions\UnexpectedValueException;

class Webhook
{
/**
* Validate and raise an appropriate event
* Validate and raise an appropriate event.
*
* @param $payload
* @param array $signature
Expand All @@ -16,9 +14,9 @@ class Webhook
*/
public static function constructEvent(array $payload, array $signature, string $secret) : Event
{
# verify we are good, else throw an expection
// verify we are good, else throw an expection
WebhookSignature::make($signature, $secret)->verify();
# Make an event
// Make an event
return Event::constructFrom($payload);
}
}
17 changes: 8 additions & 9 deletions src/WebhookSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@

namespace BinaryCats\MailgunWebhooks;

use BinaryCats\MailgunWebhooks\Exceptions\WebhookFailed;
use Illuminate\Support\Arr;

class WebhookSignature
{
/**
* Signature array
* Signature array.
*
* @var array
*/
protected $signatureArray;

/**
* Signature secret
* Signature secret.
*
* @var string
*/
protected $secret;

/**
* Create new Signature
* Create new Signature.
*
* @param array $signatureArray
* @param string $secret
Expand All @@ -34,7 +33,7 @@ public function __construct(array $signatureArray, string $secret)
}

/**
* Statis accessor into the class constructor
* Statis accessor into the class constructor.
*
* @param array $signatureArray
* @param string $secret
Expand All @@ -46,17 +45,17 @@ public static function make($signatureArray, string $secret)
}

/**
* True if the signature is valid
* True if the signature is valid.
*
* @return boolean
* @return bool
*/
public function verify() : bool
{
return hash_equals($this->signature, $this->computeSignature());
}

/**
* Compute expected signature
* Compute expected signature.
*
* @return string
*/
Expand All @@ -71,7 +70,7 @@ protected function computeSignature()
}

/**
* Magically access items from signature array
* Magically access items from signature array.
*
* @param string $attribute
* @return mixed
Expand Down
6 changes: 3 additions & 3 deletions tests/DummyJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
class DummyJob
{
/**
* Bind the implementation
* Bind the implementation.
*
* @var Spatie\WebhookClient\Models\WebhookCall
*/
public $webhookCall;

/**
* Create new Job
* Create new Job.
*
* @param Spatie\WebhookClient\Models\WebhookCall $webhookCall
*/
Expand All @@ -24,7 +24,7 @@ public function __construct(WebhookCall $webhookCall)
}

/**
* Handle the job
* Handle the job.
*
* @return void
*/
Expand Down
8 changes: 4 additions & 4 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace BinaryCats\MailgunWebhooks\Tests;

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Arr;
use Spatie\WebhookClient\Models\WebhookCall;

class IntegrationTest extends TestCase
Expand All @@ -29,7 +29,7 @@ public function it_can_handle_a_valid_request()
'event-data' => [
'event' => 'my.type',
'key' => 'value',
]
],
];

Arr::set($payload, 'signature', $this->determineMailgunSignature($payload));
Expand Down Expand Up @@ -63,7 +63,7 @@ public function a_request_with_an_invalid_signature_wont_be_logged()
'event-data' => [
'event' => 'my.type',
'key' => 'value',
]
],
];

Arr::set($payload, 'signature', 'invalid_signature');
Expand Down Expand Up @@ -119,7 +119,7 @@ public function a_request_with_a_config_key_will_use_the_correct_signing_secret(
'event-data' => [
'event' => 'my.type',
'key' => 'value',
]
],
];

Arr::set($payload, 'signature', $this->determineMailgunSignature($payload));
Expand Down
4 changes: 2 additions & 2 deletions tests/MailgunWebhookCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace BinaryCats\MailgunWebhooks\Tests;

use BinaryCats\MailgunWebhooks\ProcessMailgunWebhookJob;
use Illuminate\Support\Facades\Event;
use Spatie\WebhookClient\Models\WebhookCall;
use BinaryCats\MailgunWebhooks\ProcessMailgunWebhookJob;

class MailgunWebhookCallTest extends TestCase
{
Expand All @@ -28,7 +28,7 @@ public function setUp(): void
'event-data' => [
'event' => 'my.type',
'key' => 'value',
]
],
],
]);

Expand Down
15 changes: 7 additions & 8 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace BinaryCats\MailgunWebhooks\Tests;

use Exception;
use BinaryCats\MailgunWebhooks\MailgunWebhooksServiceProvider;
use CreateWebhookCallsTable;
use Illuminate\Foundation\Exceptions\Handler;
use Exception;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Foundation\Exceptions\Handler;
use Orchestra\Testbench\TestCase as OrchestraTestCase;
use BinaryCats\MailgunWebhooks\MailgunWebhooksServiceProvider;

abstract class TestCase extends OrchestraTestCase
{
Expand Down Expand Up @@ -56,8 +56,7 @@ protected function getPackageProviders($app)

protected function disableExceptionHandling()
{
$this->app->instance(ExceptionHandler::class, new class extends Handler
{
$this->app->instance(ExceptionHandler::class, new class extends Handler {
public function __construct()
{
}
Expand Down Expand Up @@ -86,9 +85,9 @@ protected function determineMailgunSignature(array $payload, string $configKey =
$token = hash_hmac('sha256', $timestampedPayload, $secret);

return [
"timestamp" => $timestamp,
"token" => $token,
"signature" => hash_hmac('sha256', "{$timestamp}.{$token}", $secret),
'timestamp' => $timestamp,
'token' => $token,
'signature' => hash_hmac('sha256', "{$timestamp}.{$token}", $secret),
];
}
}