From be2bee9e74f34359885ead99f19ae6eae29765de Mon Sep 17 00:00:00 2001 From: Cyrill Kalita Date: Sat, 28 Dec 2019 19:59:41 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/Contracts/WebhookEvent.php | 1 - src/Event.php | 9 ++++----- src/Exceptions/WebhookFailed.php | 6 +++--- src/Jobs/HandleDelivered.php | 5 ++--- src/MailgunSignatureValidator.php | 11 +++++------ src/MailgunWebhooksController.php | 2 +- src/MailgunWebhooksServiceProvider.php | 2 +- src/ProcessMailgunWebhookJob.php | 4 ++-- src/Webhook.php | 8 +++----- src/WebhookSignature.php | 17 ++++++++--------- tests/DummyJob.php | 6 +++--- tests/IntegrationTest.php | 8 ++++---- tests/MailgunWebhookCallTest.php | 4 ++-- tests/TestCase.php | 15 +++++++-------- 14 files changed, 45 insertions(+), 53 deletions(-) diff --git a/src/Contracts/WebhookEvent.php b/src/Contracts/WebhookEvent.php index c7ff5b7..8fd31bf 100644 --- a/src/Contracts/WebhookEvent.php +++ b/src/Contracts/WebhookEvent.php @@ -4,5 +4,4 @@ interface WebhookEvent { - } diff --git a/src/Event.php b/src/Event.php index c1e605b..da818f8 100644 --- a/src/Event.php +++ b/src/Event.php @@ -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 */ @@ -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); } diff --git a/src/Exceptions/WebhookFailed.php b/src/Exceptions/WebhookFailed.php index 381ee1d..7200d99 100644 --- a/src/Exceptions/WebhookFailed.php +++ b/src/Exceptions/WebhookFailed.php @@ -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."); } diff --git a/src/Jobs/HandleDelivered.php b/src/Jobs/HandleDelivered.php index 8f24bf2..de1929e 100644 --- a/src/Jobs/HandleDelivered.php +++ b/src/Jobs/HandleDelivered.php @@ -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 */ @@ -34,6 +34,5 @@ public function __construct(WebhookCall $webhookCall) */ public function handle() { - } } diff --git a/src/MailgunSignatureValidator.php b/src/MailgunSignatureValidator.php index 4508b25..0628327 100644 --- a/src/MailgunSignatureValidator.php +++ b/src/MailgunSignatureValidator.php @@ -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 { diff --git a/src/MailgunWebhooksController.php b/src/MailgunWebhooksController.php index 4e841eb..1db6ddc 100644 --- a/src/MailgunWebhooksController.php +++ b/src/MailgunWebhooksController.php @@ -10,7 +10,7 @@ class MailgunWebhooksController { /** - * Invoke controller method + * Invoke controller method. * * @param \Illuminate\Http\Request $request * @param string|null $configKey diff --git a/src/MailgunWebhooksServiceProvider.php b/src/MailgunWebhooksServiceProvider.php index ba2901f..41d7509 100644 --- a/src/MailgunWebhooksServiceProvider.php +++ b/src/MailgunWebhooksServiceProvider.php @@ -8,7 +8,7 @@ class MailgunWebhooksServiceProvider extends ServiceProvider { /** - * Boot application services + * Boot application services. * * @return void */ diff --git a/src/ProcessMailgunWebhookJob.php b/src/ProcessMailgunWebhookJob.php index 6dd6b99..bd3efb2 100644 --- a/src/ProcessMailgunWebhookJob.php +++ b/src/ProcessMailgunWebhookJob.php @@ -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 */ diff --git a/src/Webhook.php b/src/Webhook.php index 8e1c97b..c399527 100644 --- a/src/Webhook.php +++ b/src/Webhook.php @@ -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 @@ -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); } } diff --git a/src/WebhookSignature.php b/src/WebhookSignature.php index fd8b6f9..2de5098 100644 --- a/src/WebhookSignature.php +++ b/src/WebhookSignature.php @@ -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 @@ -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 @@ -46,9 +45,9 @@ 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 { @@ -56,7 +55,7 @@ public function verify() : bool } /** - * Compute expected signature + * Compute expected signature. * * @return string */ @@ -71,7 +70,7 @@ protected function computeSignature() } /** - * Magically access items from signature array + * Magically access items from signature array. * * @param string $attribute * @return mixed diff --git a/tests/DummyJob.php b/tests/DummyJob.php index 752c031..1677e4b 100644 --- a/tests/DummyJob.php +++ b/tests/DummyJob.php @@ -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 */ @@ -24,7 +24,7 @@ public function __construct(WebhookCall $webhookCall) } /** - * Handle the job + * Handle the job. * * @return void */ diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 5ad9038..358d650 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -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 @@ -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)); @@ -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'); @@ -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)); diff --git a/tests/MailgunWebhookCallTest.php b/tests/MailgunWebhookCallTest.php index 1a75e58..8ebbde5 100644 --- a/tests/MailgunWebhookCallTest.php +++ b/tests/MailgunWebhookCallTest.php @@ -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 { @@ -28,7 +28,7 @@ public function setUp(): void 'event-data' => [ 'event' => 'my.type', 'key' => 'value', - ] + ], ], ]); diff --git a/tests/TestCase.php b/tests/TestCase.php index 940be2e..624ccbe 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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 { @@ -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() { } @@ -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), ]; } }