From 821a82d109d62df5594790559903d39d0ff29973 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Thu, 13 Jun 2019 23:29:33 +0000 Subject: [PATCH] Apply fixes from StyleCI --- config/webhook-client.php | 2 +- src/Events/InvalidSignatureEvent.php | 1 - src/Exceptions/InvalidConfig.php | 3 +-- src/Models/WebhookCall.php | 1 - src/ProcessWebhookClass.php | 2 -- src/ProcessWebhookJob.php | 5 ++--- .../DefaultSignatureValidator.php | 3 +-- src/WebhookConfig.php | 5 ++--- src/WebhookController.php | 3 +-- src/WebhookProcessor.php | 14 +++++--------- .../ProcessEverythingWebhookProfile.php | 1 - tests/TestCase.php | 2 +- .../TestClasses/ProcessNothingWebhookProfile.php | 1 - tests/TestClasses/ProcessWebhookJobTestClass.php | 2 -- tests/WebhookConfigTest.php | 5 ++--- tests/WebhookControllerTest.php | 15 +++++++-------- 16 files changed, 23 insertions(+), 42 deletions(-) diff --git a/config/webhook-client.php b/config/webhook-client.php index f791087..3a81f87 100644 --- a/config/webhook-client.php +++ b/config/webhook-client.php @@ -44,5 +44,5 @@ * This should be set to a class that extends \Spatie\WebhookClient\Spatie\WebhookClient. */ 'process_webhook_job' => '', - ] + ], ]; diff --git a/src/Events/InvalidSignatureEvent.php b/src/Events/InvalidSignatureEvent.php index a41be21..686bfd9 100644 --- a/src/Events/InvalidSignatureEvent.php +++ b/src/Events/InvalidSignatureEvent.php @@ -19,4 +19,3 @@ public function __construct(Request $request, ?string $invalidSignature) $this->invalidSignature = $invalidSignature; } } - diff --git a/src/Exceptions/InvalidConfig.php b/src/Exceptions/InvalidConfig.php index 7641444..cdb5d1b 100644 --- a/src/Exceptions/InvalidConfig.php +++ b/src/Exceptions/InvalidConfig.php @@ -4,8 +4,8 @@ use Exception; use Spatie\WebhookClient\ProcessWebhookJob; -use Spatie\WebhookClient\SignatureValidator\SignatureValidator; use Spatie\WebhookClient\WebhookProfile\WebhookProfile; +use Spatie\WebhookClient\SignatureValidator\SignatureValidator; class InvalidConfig extends Exception { @@ -35,4 +35,3 @@ public static function invalidProcessWebhookJob(string $processWebhookJob) return new static("`{$processWebhookJob}` is not a valid process webhook job class. A valid class should implement `{$abstractProcessWebhookJob}`."); } } - diff --git a/src/Models/WebhookCall.php b/src/Models/WebhookCall.php index 55a52ff..45b1400 100644 --- a/src/Models/WebhookCall.php +++ b/src/Models/WebhookCall.php @@ -36,4 +36,3 @@ public function clearException() return $this; } } - diff --git a/src/ProcessWebhookClass.php b/src/ProcessWebhookClass.php index 4fa4ef5..7797f51 100644 --- a/src/ProcessWebhookClass.php +++ b/src/ProcessWebhookClass.php @@ -4,6 +4,4 @@ class ProcessWebhookClass { - } - diff --git a/src/ProcessWebhookJob.php b/src/ProcessWebhookJob.php index bc8072b..590dd1b 100644 --- a/src/ProcessWebhookJob.php +++ b/src/ProcessWebhookJob.php @@ -3,10 +3,10 @@ namespace Spatie\WebhookClient; use Illuminate\Bus\Queueable; +use Illuminate\Queue\SerializesModels; +use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; -use Illuminate\Queue\InteractsWithQueue; -use Illuminate\Queue\SerializesModels; use Spatie\WebhookClient\Models\WebhookCall; abstract class ProcessWebhookJob implements ShouldQueue @@ -23,4 +23,3 @@ public function __construct(WebhookCall $webhookCall) abstract public function handle(); } - diff --git a/src/SignatureValidator/DefaultSignatureValidator.php b/src/SignatureValidator/DefaultSignatureValidator.php index 4895c18..eaebdac 100644 --- a/src/SignatureValidator/DefaultSignatureValidator.php +++ b/src/SignatureValidator/DefaultSignatureValidator.php @@ -3,8 +3,8 @@ namespace Spatie\WebhookClient\SignatureValidator; use Illuminate\Http\Request; -use Spatie\WebhookClient\Exceptions\WebhookFailed; use Spatie\WebhookClient\WebhookConfig; +use Spatie\WebhookClient\Exceptions\WebhookFailed; class DefaultSignatureValidator implements SignatureValidator { @@ -27,4 +27,3 @@ public function isValid(Request $request, WebhookConfig $config) return hash_equals($signature, $computedSignature); } } - diff --git a/src/WebhookConfig.php b/src/WebhookConfig.php index fdc5604..c2b7869 100644 --- a/src/WebhookConfig.php +++ b/src/WebhookConfig.php @@ -3,8 +3,8 @@ namespace Spatie\WebhookClient; use Spatie\WebhookClient\Exceptions\InvalidConfig; -use Spatie\WebhookClient\SignatureValidator\SignatureValidator; use Spatie\WebhookClient\WebhookProfile\WebhookProfile; +use Spatie\WebhookClient\SignatureValidator\SignatureValidator; class WebhookConfig { @@ -17,7 +17,7 @@ class WebhookConfig /** @var string */ public $signatureHeaderName; - /** @var \Spatie\WebhookClient\SignatureValidator\SignatureValidator */ + /** @var \Spatie\WebhookClient\SignatureValidator\SignatureValidator */ public $signatureValidator; /** @var \Spatie\WebhookClient\WebhookProfile\WebhookProfile */ @@ -55,4 +55,3 @@ public function __construct(array $properties) $this->processWebhookJob = app($properties['process_webhook_job']); } } - diff --git a/src/WebhookController.php b/src/WebhookController.php index e1755b1..8e10bf1 100644 --- a/src/WebhookController.php +++ b/src/WebhookController.php @@ -2,9 +2,9 @@ namespace Spatie\WebhookClient; +use Illuminate\Support\Str; use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; -use Illuminate\Support\Str; use Spatie\WebhookClient\Exceptions\InvalidConfig; class WebhookController @@ -36,4 +36,3 @@ protected function getConfig(): WebhookConfig return new WebhookConfig($config); } } - diff --git a/src/WebhookProcessor.php b/src/WebhookProcessor.php index 19bb707..7e107da 100644 --- a/src/WebhookProcessor.php +++ b/src/WebhookProcessor.php @@ -4,12 +4,9 @@ use Exception; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Route; -use Illuminate\Support\Str; -use Spatie\WebhookClient\Events\InvalidSignatureEvent; -use Spatie\WebhookClient\Exceptions\WebhookFailed; -use Spatie\WebhookClient\Exceptions\InvalidConfig; use Spatie\WebhookClient\Models\WebhookCall; +use Spatie\WebhookClient\Exceptions\WebhookFailed; +use Spatie\WebhookClient\Events\InvalidSignatureEvent; class WebhookProcessor { @@ -30,7 +27,7 @@ public function process() { $this->guardAgainstInvalidSignature(); - if (!$this->config->webhookProfile->shouldProcess($this->request)) { + if (! $this->config->webhookProfile->shouldProcess($this->request)) { return; } @@ -45,12 +42,12 @@ protected function guardAgainstInvalidSignature() $signature = $this->request->header($headerName); - if (!$signature) { + if (! $signature) { event(new InvalidSignatureEvent($this->request, $signature)); throw WebhookFailed::missingSignature($headerName); } - if (!$this->config->signatureValidator->isValid($this->request, $this->config)) { + if (! $this->config->signatureValidator->isValid($this->request, $this->config)) { event(new InvalidSignatureEvent($this->request, $signature)); throw WebhookFailed::invalidSignature($signature, $this->config->signatureHeaderName); @@ -82,4 +79,3 @@ protected function processWebhook(WebhookCall $webhookCall): void } } } - diff --git a/src/WebhookProfile/ProcessEverythingWebhookProfile.php b/src/WebhookProfile/ProcessEverythingWebhookProfile.php index 2b647c8..5fcadde 100644 --- a/src/WebhookProfile/ProcessEverythingWebhookProfile.php +++ b/src/WebhookProfile/ProcessEverythingWebhookProfile.php @@ -11,4 +11,3 @@ public function shouldProcess(Request $request): bool return true; } } - diff --git a/tests/TestCase.php b/tests/TestCase.php index 3579b49..d54494e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -34,7 +34,7 @@ protected function getEnvironmentSetUp($app) protected function setUpDatabase() { - include_once __DIR__ . '/../migrations/create_webhook_calls_table.php.stub'; + include_once __DIR__.'/../migrations/create_webhook_calls_table.php.stub'; (new CreateWebhookCallsTable())->up(); } diff --git a/tests/TestClasses/ProcessNothingWebhookProfile.php b/tests/TestClasses/ProcessNothingWebhookProfile.php index 8aab60e..195a672 100644 --- a/tests/TestClasses/ProcessNothingWebhookProfile.php +++ b/tests/TestClasses/ProcessNothingWebhookProfile.php @@ -12,4 +12,3 @@ public function shouldProcess(Request $request): bool return false; } } - diff --git a/tests/TestClasses/ProcessWebhookJobTestClass.php b/tests/TestClasses/ProcessWebhookJobTestClass.php index 2163c0f..1c7feb4 100644 --- a/tests/TestClasses/ProcessWebhookJobTestClass.php +++ b/tests/TestClasses/ProcessWebhookJobTestClass.php @@ -8,7 +8,5 @@ class ProcessWebhookJobTestClass extends ProcessWebhookJob { public function handle() { - } } - diff --git a/tests/WebhookConfigTest.php b/tests/WebhookConfigTest.php index 2a63c6f..03aa4d6 100644 --- a/tests/WebhookConfigTest.php +++ b/tests/WebhookConfigTest.php @@ -2,11 +2,11 @@ namespace Spatie\WebhookClient\Tests; -use Spatie\WebhookClient\Exceptions\InvalidConfig; +use Spatie\WebhookClient\WebhookConfig; use Spatie\WebhookClient\Models\WebhookCall; +use Spatie\WebhookClient\Exceptions\InvalidConfig; use Spatie\WebhookClient\SignatureValidator\DefaultSignatureValidator; use Spatie\WebhookClient\Tests\TestClasses\ProcessWebhookJobTestClass; -use Spatie\WebhookClient\WebhookConfig; use Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile; class WebhookConfigTest extends TestCase @@ -73,4 +73,3 @@ protected function getValidConfig(): array ]; } } - diff --git a/tests/WebhookControllerTest.php b/tests/WebhookControllerTest.php index 51db7de..84f4642 100644 --- a/tests/WebhookControllerTest.php +++ b/tests/WebhookControllerTest.php @@ -2,15 +2,14 @@ namespace Spatie\WebhookClient\Tests; -use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Route; -use Spatie\WebhookClient\Events\InvalidSignatureEvent; use Spatie\WebhookClient\Models\WebhookCall; -use Spatie\WebhookClient\Tests\TestClasses\ProcessNothingWebhookProfile; +use Spatie\WebhookClient\Events\InvalidSignatureEvent; use Spatie\WebhookClient\Tests\TestClasses\ProcessWebhookJobTestClass; +use Spatie\WebhookClient\Tests\TestClasses\ProcessNothingWebhookProfile; class WebhookControllerTest extends TestCase { @@ -39,7 +38,7 @@ public function setUp(): void $this->payload = ['a' => 1]; $this->headers = [ - config('webhook-client.0.signature_header_name') => $this->determineSignature($this->payload) + config('webhook-client.0.signature_header_name') => $this->determineSignature($this->payload), ]; } @@ -57,7 +56,8 @@ public function it_can_process_a_webhook_request() Queue::assertPushed(ProcessWebhookJobTestClass::class, function (ProcessWebhookJobTestClass $job) { $this->assertEquals(1, $job->webhookCall->id); - return true; + + return true; }); } @@ -104,7 +104,6 @@ public function it_can_work_with_an_alternative_config() $this ->postJson('incoming-webhooks-alternative-config', $this->payload, $this->headers) ->assertSuccessful(); - } private function determineSignature(array $payload): string @@ -122,9 +121,9 @@ protected function getValidPayloadAndHeaders(): array $payload = ['a' => 1]; $headers = [ - config('webhook-client.0.signature_header_name') => $this->determineSignature($payload) + config('webhook-client.0.signature_header_name') => $this->determineSignature($payload), ]; + return [$payload, $headers]; } } -