Skip to content

Commit ce4b9c3

Browse files
committed
Apply static analysis
1 parent 48f8a3f commit ce4b9c3

15 files changed

+131
-43
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
build
2+
.idea/
3+
.phpunit.result.cache
24
composer.lock
35
docs
46
vendor

.phpunit.result.cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
C:37:"PHPUnit\Runner\DefaultTestResultCache":987:{a:2:{s:7:"defects";a:0:{}s:5:"times";a:8:{s:75:"BinaryCats\LobWebhooks\Tests\IntegrationTest::it_can_handle_a_valid_request";d:3.495;s:96:"BinaryCats\LobWebhooks\Tests\IntegrationTest::a_request_with_an_invalid_signature_wont_be_logged";d:3.433;s:137:"BinaryCats\LobWebhooks\Tests\IntegrationTest::a_request_with_an_invalid_payload_will_be_logged_but_events_and_jobs_will_not_be_dispatched";d:4.031;s:109:"BinaryCats\LobWebhooks\Tests\IntegrationTest::a_request_with_a_config_key_will_use_the_correct_signing_secret";d:3.309;s:84:"BinaryCats\LobWebhooks\Tests\LobWebhookCallTest::it_will_fire_off_the_configured_job";d:2.829;s:92:"BinaryCats\LobWebhooks\Tests\LobWebhookCallTest::it_will_not_dispatch_a_job_for_another_type";d:2.741;s:102:"BinaryCats\LobWebhooks\Tests\LobWebhookCallTest::it_will_not_dispatch_jobs_when_no_jobs_are_configured";d:2.781;s:117:"BinaryCats\LobWebhooks\Tests\LobWebhookCallTest::it_will_dispatch_events_even_when_no_corresponding_job_is_configured";d:2.74;}}}
1+
{"version":1,"defects":{"Tests\\IntegrationTest::it_can_handle_a_valid_request":3,"Tests\\IntegrationTest::a_request_with_an_invalid_payload_will_be_logged_but_events_and_jobs_will_not_be_dispatched":3,"Tests\\IntegrationTest::a_request_with_a_config_key_will_use_the_correct_signing_secret":3,"Tests\\LobWebhookCallTest::it_will_fire_off_the_configured_job":4,"Tests\\LobWebhookCallTest::it_will_not_dispatch_a_job_for_another_type":4,"Tests\\LobWebhookCallTest::it_will_not_dispatch_jobs_when_no_jobs_are_configured":4,"Tests\\LobWebhookCallTest::it_will_dispatch_events_even_when_no_corresponding_job_is_configured":4},"times":{"Tests\\IntegrationTest::it_can_handle_a_valid_request":0.272,"Tests\\IntegrationTest::a_request_with_an_invalid_signature_wont_be_logged":0.227,"Tests\\IntegrationTest::a_request_with_an_invalid_payload_will_be_logged_but_events_and_jobs_will_not_be_dispatched":0.23,"Tests\\IntegrationTest::a_request_with_a_config_key_will_use_the_correct_signing_secret":0.228,"Tests\\LobWebhookCallTest::it_will_fire_off_the_configured_job":0.193,"Tests\\LobWebhookCallTest::it_will_not_dispatch_a_job_for_another_type":0.256,"Tests\\LobWebhookCallTest::it_will_not_dispatch_jobs_when_no_jobs_are_configured":0.217,"Tests\\LobWebhookCallTest::it_will_dispatch_events_even_when_no_corresponding_job_is_configured":0.244}}

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22

33
All notable changes to `laravel-lob-webhooks` will be documented in this file
44

5+
## 9.0.0 - 2022-01-26
6+
7+
- Drop support for PHP 7
8+
- Upgrade spatie/laravel-webhook-client to version 2.0
9+
- Test Laravel 9 integration
10+
511
## 1.2.0 - 2020-11-07
612

713
- Update dependencies to support Laravel 8
8-
- Add Github tests
14+
- Add github tests
915
- Joe Biden will be 46th president of USA
1016

1117
## 1.0.0 - 2020-01-27

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ return [
4242
*
4343
* You can find a list of Lob.com webhook types here:
4444
* https://lob.com/docs#all_event_types
45+
*
46+
* The package will automatically convert the keys to lowercase, but you should
47+
* be congnisant of the fact that array keys are case sensitive
4548
*/
4649
'jobs' => [
4750
// 'letter_delivered' => \BinaryCats\LobWebhooks\Jobs\HandleDelivered::class,
@@ -106,6 +109,8 @@ If something goes wrong during the webhook request the thrown exception will be
106109

107110
There are two ways this package enables you to handle webhook requests: you can opt to queue a job or listen to the events the package will fire.
108111

112+
**Due to the apparent differences between MailGun sandbox and production environment event casing, the package will ALWAYS cast mailgun events to lowercase - so your configured keys must be lowercase, too**
113+
109114
### Handling webhook requests using jobs
110115
If you want to do something when a specific event type comes in you can define a job that does the work. Here's an example of such a job:
111116

UPGRADING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
# Upgrading
2+
3+
## v1 -> v9
4+
5+
If you are upgrading from previous version, please note that spatie/laravel-webhook-client has been upgraded to ^3.0 - which adds an extra field into the webhooks table. Read [upgrading instructions](https://github.com/spatie/laravel-webhook-client/blob/main/UPGRADING.md) for more details.

composer.json

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,40 @@
1919
}
2020
],
2121
"require": {
22-
"php": "^7.2",
23-
"illuminate/support": "~5.8.0|^6.0|^7.0|^8.0",
24-
"spatie/laravel-webhook-client": "^2.0"
22+
"php": "^8.0",
23+
"illuminate/support": "^8.0|^9.0",
24+
"spatie/laravel-webhook-client": "^3.0"
2525
},
2626
"require-dev": {
27-
"orchestra/testbench": "~3.8.0|^4.0|^5.0|^6.0",
28-
"phpunit/phpunit": "^8.2|^9.0"
27+
"orchestra/testbench": "^6.0|^7.0",
28+
"phpunit/phpunit": "^9.4"
2929
},
3030
"autoload": {
3131
"psr-4": {
32-
"BinaryCats\\LobWebhooks\\": "src"
32+
"BinaryCats\\LobWebhooks\\": "src/"
3333
}
3434
},
3535
"autoload-dev": {
3636
"psr-4": {
37-
"BinaryCats\\LobWebhooks\\Tests\\": "tests"
37+
"Tests\\": "tests/"
3838
}
3939
},
4040
"suggest": {
4141
"binary-cats/laravel-mailgun-webhooks": "Handle Mailgun webhooks in your Laravel application"
4242
},
4343
"scripts": {
44-
"test": "vendor/bin/phpunit --color=always",
45-
"check": [
46-
"php-cs-fixer fix --ansi --dry-run --diff",
47-
"phpcs --report-width=200 --report-summary --report-full src/ tests/ --standard=PSR2 -n",
48-
"phpmd src/,tests/ text ./phpmd.xml.dist"
49-
],
50-
"fix": [
51-
"php-cs-fixer fix --ansi"
52-
]
44+
"analyze": "./vendor/bin/phpstan analyse src --memory-limit=2G",
45+
"coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html coverage -d pcov.enabled",
46+
"test": "./vendor/bin/phpunit --color=always -vvv"
5347
},
5448
"config": {
49+
"optimize-autoloader": true,
5550
"sort-packages": true
5651
},
5752
"extra": {
53+
"branch-alias": {
54+
"dev-master": "9.x-dev"
55+
},
5856
"laravel": {
5957
"providers": [
6058
"BinaryCats\\LobWebhooks\\LobWebhooksServiceProvider"

config/lob-webhooks.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*
1717
* You can find a list of Lob.com webhook types here:
1818
* https://lob.com/docs#all_event_types
19+
*
20+
* The package will automatically convert the keys to lowercase, but you should
21+
* be congnisant of the fact that array keys are case sensitive
1922
*/
2023
'jobs' => [
2124
// 'letter.created' => \BinaryCats\LobWebhooks\Jobs\HandleLetter_Created::class,

src/Event.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use BinaryCats\LobWebhooks\Contracts\WebhookEvent;
66

7-
class Event implements WebhookEvent
7+
final class Event implements WebhookEvent
88
{
99
/**
1010
* Attributes from the event.

src/Exceptions/WebhookFailed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Exception;
66
use Spatie\WebhookClient\Models\WebhookCall;
77

8-
class WebhookFailed extends Exception
8+
final class WebhookFailed extends Exception
99
{
1010
public static function signingSecretNotSet(): self
1111
{

src/ProcessLobWebhookJob.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
use BinaryCats\LobWebhooks\Exceptions\WebhookFailed;
66
use Illuminate\Support\Arr;
7-
use Spatie\WebhookClient\ProcessWebhookJob;
7+
use Illuminate\Support\Str;
8+
use Spatie\WebhookClient\Jobs\ProcessWebhookJob;
89

910
class ProcessLobWebhookJob extends ProcessWebhookJob
1011
{
@@ -28,11 +29,11 @@ public function handle()
2829
throw WebhookFailed::missingType($this->webhookCall);
2930
}
3031

31-
event("lob-webhooks::{$type}", $this->webhookCall);
32+
event($this->determineEventKey($type), $this->webhookCall);
3233

3334
$jobClass = $this->determineJobClass($type);
3435

35-
if ($jobClass === '') {
36+
if ('' === $jobClass) {
3637
return;
3738
}
3839

@@ -43,10 +44,35 @@ public function handle()
4344
dispatch(new $jobClass($this->webhookCall));
4445
}
4546

47+
/**
48+
* @param string $eventType
49+
* @return string
50+
*/
4651
protected function determineJobClass(string $eventType): string
4752
{
48-
$jobConfigKey = str_replace('.', '_', $eventType);
53+
return config($this->determineJobConfigKey($eventType), '');
54+
}
4955

50-
return config("lob-webhooks.jobs.{$jobConfigKey}", '');
56+
/**
57+
* @param string $eventType
58+
* @return string
59+
*/
60+
protected function determineJobConfigKey(string $eventType): string
61+
{
62+
return Str::of($eventType)
63+
->replace('.', '_')
64+
->prepend('lob-webhooks.jobs.')
65+
->lower();
66+
}
67+
68+
/**
69+
* @param string $eventType
70+
* @return string
71+
*/
72+
protected function determineEventKey(string $eventType): string
73+
{
74+
return Str::of($eventType)
75+
->prepend('lob-webhooks::')
76+
->lower();
5177
}
5278
}

0 commit comments

Comments
 (0)