Skip to content

Commit ed236ae

Browse files
authored
Merge pull request #1 from binary-cats/analysis-OMM4OL
Apply fixes from StyleCI
2 parents 4f55746 + be2bee9 commit ed236ae

14 files changed

+45
-53
lines changed

src/Contracts/WebhookEvent.php

-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44

55
interface WebhookEvent
66
{
7-
87
}

src/Event.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
namespace BinaryCats\MailgunWebhooks;
44

55
use BinaryCats\MailgunWebhooks\Contracts\WebhookEvent;
6-
use Illuminate\Support\Arr;
76

87
class Event implements WebhookEvent
98
{
109
/**
11-
* Attributes from the event
10+
* Attributes from the event.
1211
*
1312
* @var array
1413
*/
1514
public $attributes = [];
1615

1716
/**
18-
* Create new Event
17+
* Create new Event.
1918
*
2019
* @param array $attributes
2120
*/
@@ -25,11 +24,11 @@ public function __construct($attributes)
2524
}
2625

2726
/**
28-
* Construct the event
27+
* Construct the event.
2928
*
3029
* @return Event
3130
*/
32-
public static function constructFrom($data) : Event
31+
public static function constructFrom($data) : self
3332
{
3433
return new static($data);
3534
}

src/Exceptions/WebhookFailed.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

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

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

20-
public static function missingType(WebhookCall $webhookCall): WebhookFailed
20+
public static function missingType(WebhookCall $webhookCall): self
2121
{
2222
return new static("Webhook call id `{$webhookCall->id}` did not contain a type. Valid Mailgun webhook calls should always contain a type.");
2323
}

src/Jobs/HandleDelivered.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ class HandleDelivered
1111
use Dispatchable, SerializesModels;
1212

1313
/**
14-
* Bind the implementation
14+
* Bind the implementation.
1515
*
1616
* @var Spatie\WebhookClient\Models\WebhookCall
1717
*/
1818
protected $webhookCall;
1919

2020
/**
21-
* Create new Job
21+
* Create new Job.
2222
*
2323
* @param Spatie\WebhookClient\Models\WebhookCall $webhookCall
2424
*/
@@ -34,6 +34,5 @@ public function __construct(WebhookCall $webhookCall)
3434
*/
3535
public function handle()
3636
{
37-
3837
}
3938
}

src/MailgunSignatureValidator.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,33 @@
33
namespace BinaryCats\MailgunWebhooks;
44

55
use Exception;
6-
use BinaryCats\MailgunWebhooks\Webhook;
76
use Illuminate\Http\Request;
8-
use Spatie\WebhookClient\WebhookConfig;
97
use Spatie\WebhookClient\SignatureValidator\SignatureValidator;
8+
use Spatie\WebhookClient\WebhookConfig;
109

1110
class MailgunSignatureValidator implements SignatureValidator
1211
{
1312
/**
14-
* Bind the implemetation
13+
* Bind the implemetation.
1514
*
1615
* @var Illuminate\Http\Request
1716
*/
1817
protected $request;
1918

2019
/**
21-
* Inject the config
20+
* Inject the config.
2221
*
2322
* @var Spatie\WebhookClient\WebhookConfig
2423
*/
2524
protected $config;
2625

2726
/**
28-
* True if the signature has been valiates
27+
* True if the signature has been valiates.
2928
*
3029
* @param Illuminate\Http\Request $request
3130
* @param Spatie\WebhookClient\WebhookConfig $config
3231
*
33-
* @return boolean
32+
* @return bool
3433
*/
3534
public function isValid(Request $request, WebhookConfig $config): bool
3635
{

src/MailgunWebhooksController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class MailgunWebhooksController
1111
{
1212
/**
13-
* Invoke controller method
13+
* Invoke controller method.
1414
*
1515
* @param \Illuminate\Http\Request $request
1616
* @param string|null $configKey

src/MailgunWebhooksServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class MailgunWebhooksServiceProvider extends ServiceProvider
99
{
1010
/**
11-
* Boot application services
11+
* Boot application services.
1212
*
1313
* @return void
1414
*/

src/ProcessMailgunWebhookJob.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
class ProcessMailgunWebhookJob extends ProcessWebhookJob
1010
{
1111
/**
12-
* Name of the payload key to contain the type of event
12+
* Name of the payload key to contain the type of event.
1313
*
1414
* @var string
1515
*/
1616
protected $key = 'event-data.event';
1717

1818
/**
19-
* Handle the process
19+
* Handle the process.
2020
*
2121
* @return void
2222
*/

src/Webhook.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
namespace BinaryCats\MailgunWebhooks;
44

5-
use BinaryCats\MailgunWebhooks\Exceptions\UnexpectedValueException;
6-
75
class Webhook
86
{
97
/**
10-
* Validate and raise an appropriate event
8+
* Validate and raise an appropriate event.
119
*
1210
* @param $payload
1311
* @param array $signature
@@ -16,9 +14,9 @@ class Webhook
1614
*/
1715
public static function constructEvent(array $payload, array $signature, string $secret) : Event
1816
{
19-
# verify we are good, else throw an expection
17+
// verify we are good, else throw an expection
2018
WebhookSignature::make($signature, $secret)->verify();
21-
# Make an event
19+
// Make an event
2220
return Event::constructFrom($payload);
2321
}
2422
}

src/WebhookSignature.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22

33
namespace BinaryCats\MailgunWebhooks;
44

5-
use BinaryCats\MailgunWebhooks\Exceptions\WebhookFailed;
65
use Illuminate\Support\Arr;
76

87
class WebhookSignature
98
{
109
/**
11-
* Signature array
10+
* Signature array.
1211
*
1312
* @var array
1413
*/
1514
protected $signatureArray;
1615

1716
/**
18-
* Signature secret
17+
* Signature secret.
1918
*
2019
* @var string
2120
*/
2221
protected $secret;
2322

2423
/**
25-
* Create new Signature
24+
* Create new Signature.
2625
*
2726
* @param array $signatureArray
2827
* @param string $secret
@@ -34,7 +33,7 @@ public function __construct(array $signatureArray, string $secret)
3433
}
3534

3635
/**
37-
* Statis accessor into the class constructor
36+
* Statis accessor into the class constructor.
3837
*
3938
* @param array $signatureArray
4039
* @param string $secret
@@ -46,17 +45,17 @@ public static function make($signatureArray, string $secret)
4645
}
4746

4847
/**
49-
* True if the signature is valid
48+
* True if the signature is valid.
5049
*
51-
* @return boolean
50+
* @return bool
5251
*/
5352
public function verify() : bool
5453
{
5554
return hash_equals($this->signature, $this->computeSignature());
5655
}
5756

5857
/**
59-
* Compute expected signature
58+
* Compute expected signature.
6059
*
6160
* @return string
6261
*/
@@ -71,7 +70,7 @@ protected function computeSignature()
7170
}
7271

7372
/**
74-
* Magically access items from signature array
73+
* Magically access items from signature array.
7574
*
7675
* @param string $attribute
7776
* @return mixed

tests/DummyJob.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
class DummyJob
88
{
99
/**
10-
* Bind the implementation
10+
* Bind the implementation.
1111
*
1212
* @var Spatie\WebhookClient\Models\WebhookCall
1313
*/
1414
public $webhookCall;
1515

1616
/**
17-
* Create new Job
17+
* Create new Job.
1818
*
1919
* @param Spatie\WebhookClient\Models\WebhookCall $webhookCall
2020
*/
@@ -24,7 +24,7 @@ public function __construct(WebhookCall $webhookCall)
2424
}
2525

2626
/**
27-
* Handle the job
27+
* Handle the job.
2828
*
2929
* @return void
3030
*/

tests/IntegrationTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace BinaryCats\MailgunWebhooks\Tests;
44

5+
use Illuminate\Support\Arr;
56
use Illuminate\Support\Facades\Event;
67
use Illuminate\Support\Facades\Route;
7-
use Illuminate\Support\Arr;
88
use Spatie\WebhookClient\Models\WebhookCall;
99

1010
class IntegrationTest extends TestCase
@@ -29,7 +29,7 @@ public function it_can_handle_a_valid_request()
2929
'event-data' => [
3030
'event' => 'my.type',
3131
'key' => 'value',
32-
]
32+
],
3333
];
3434

3535
Arr::set($payload, 'signature', $this->determineMailgunSignature($payload));
@@ -63,7 +63,7 @@ public function a_request_with_an_invalid_signature_wont_be_logged()
6363
'event-data' => [
6464
'event' => 'my.type',
6565
'key' => 'value',
66-
]
66+
],
6767
];
6868

6969
Arr::set($payload, 'signature', 'invalid_signature');
@@ -119,7 +119,7 @@ public function a_request_with_a_config_key_will_use_the_correct_signing_secret(
119119
'event-data' => [
120120
'event' => 'my.type',
121121
'key' => 'value',
122-
]
122+
],
123123
];
124124

125125
Arr::set($payload, 'signature', $this->determineMailgunSignature($payload));

tests/MailgunWebhookCallTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace BinaryCats\MailgunWebhooks\Tests;
44

5+
use BinaryCats\MailgunWebhooks\ProcessMailgunWebhookJob;
56
use Illuminate\Support\Facades\Event;
67
use Spatie\WebhookClient\Models\WebhookCall;
7-
use BinaryCats\MailgunWebhooks\ProcessMailgunWebhookJob;
88

99
class MailgunWebhookCallTest extends TestCase
1010
{
@@ -28,7 +28,7 @@ public function setUp(): void
2828
'event-data' => [
2929
'event' => 'my.type',
3030
'key' => 'value',
31-
]
31+
],
3232
],
3333
]);
3434

tests/TestCase.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace BinaryCats\MailgunWebhooks\Tests;
44

5-
use Exception;
5+
use BinaryCats\MailgunWebhooks\MailgunWebhooksServiceProvider;
66
use CreateWebhookCallsTable;
7-
use Illuminate\Foundation\Exceptions\Handler;
7+
use Exception;
88
use Illuminate\Contracts\Debug\ExceptionHandler;
9+
use Illuminate\Foundation\Exceptions\Handler;
910
use Orchestra\Testbench\TestCase as OrchestraTestCase;
10-
use BinaryCats\MailgunWebhooks\MailgunWebhooksServiceProvider;
1111

1212
abstract class TestCase extends OrchestraTestCase
1313
{
@@ -56,8 +56,7 @@ protected function getPackageProviders($app)
5656

5757
protected function disableExceptionHandling()
5858
{
59-
$this->app->instance(ExceptionHandler::class, new class extends Handler
60-
{
59+
$this->app->instance(ExceptionHandler::class, new class extends Handler {
6160
public function __construct()
6261
{
6362
}
@@ -86,9 +85,9 @@ protected function determineMailgunSignature(array $payload, string $configKey =
8685
$token = hash_hmac('sha256', $timestampedPayload, $secret);
8786

8887
return [
89-
"timestamp" => $timestamp,
90-
"token" => $token,
91-
"signature" => hash_hmac('sha256', "{$timestamp}.{$token}", $secret),
88+
'timestamp' => $timestamp,
89+
'token' => $token,
90+
'signature' => hash_hmac('sha256', "{$timestamp}.{$token}", $secret),
9291
];
9392
}
9493
}

0 commit comments

Comments
 (0)