Skip to content

Commit

Permalink
Merge pull request #1 from spatie/analysis-86EQPP
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
freekmurze authored Jun 13, 2019
2 parents 5e16ced + 821a82d commit 10ac927
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 42 deletions.
2 changes: 1 addition & 1 deletion config/webhook-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@
* This should be set to a class that extends \Spatie\WebhookClient\Spatie\WebhookClient.
*/
'process_webhook_job' => '',
]
],
];
1 change: 0 additions & 1 deletion src/Events/InvalidSignatureEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ public function __construct(Request $request, ?string $invalidSignature)
$this->invalidSignature = $invalidSignature;
}
}

3 changes: 1 addition & 2 deletions src/Exceptions/InvalidConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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}`.");
}
}

1 change: 0 additions & 1 deletion src/Models/WebhookCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ public function clearException()
return $this;
}
}

2 changes: 0 additions & 2 deletions src/ProcessWebhookClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

class ProcessWebhookClass
{

}

5 changes: 2 additions & 3 deletions src/ProcessWebhookJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,4 +23,3 @@ public function __construct(WebhookCall $webhookCall)

abstract public function handle();
}

3 changes: 1 addition & 2 deletions src/SignatureValidator/DefaultSignatureValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -27,4 +27,3 @@ public function isValid(Request $request, WebhookConfig $config)
return hash_equals($signature, $computedSignature);
}
}

5 changes: 2 additions & 3 deletions src/WebhookConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 */
Expand Down Expand Up @@ -55,4 +55,3 @@ public function __construct(array $properties)
$this->processWebhookJob = app($properties['process_webhook_job']);
}
}

3 changes: 1 addition & 2 deletions src/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,4 +36,3 @@ protected function getConfig(): WebhookConfig
return new WebhookConfig($config);
}
}

14 changes: 5 additions & 9 deletions src/WebhookProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -30,7 +27,7 @@ public function process()
{
$this->guardAgainstInvalidSignature();

if (!$this->config->webhookProfile->shouldProcess($this->request)) {
if (! $this->config->webhookProfile->shouldProcess($this->request)) {
return;
}

Expand All @@ -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);
Expand Down Expand Up @@ -82,4 +79,3 @@ protected function processWebhook(WebhookCall $webhookCall): void
}
}
}

1 change: 0 additions & 1 deletion src/WebhookProfile/ProcessEverythingWebhookProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ public function shouldProcess(Request $request): bool
return true;
}
}

2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 0 additions & 1 deletion tests/TestClasses/ProcessNothingWebhookProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ public function shouldProcess(Request $request): bool
return false;
}
}

2 changes: 0 additions & 2 deletions tests/TestClasses/ProcessWebhookJobTestClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ class ProcessWebhookJobTestClass extends ProcessWebhookJob
{
public function handle()
{

}
}

5 changes: 2 additions & 3 deletions tests/WebhookConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,4 +73,3 @@ protected function getValidConfig(): array
];
}
}

15 changes: 7 additions & 8 deletions tests/WebhookControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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),
];
}

Expand All @@ -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;
});
}

Expand Down Expand Up @@ -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
Expand All @@ -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];
}
}

0 comments on commit 10ac927

Please sign in to comment.