Skip to content

Commit 6972480

Browse files
authored
Updated Dependencies (#16)
- upgraded composer dependencies - Added types for formatting updates - fixed phpunit deprecations - updated pipelines
1 parent f711858 commit 6972480

10 files changed

+103
-115
lines changed

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
language: php
22

33
php:
4-
- 7.2
5-
- 7.3
6-
- 7.4
4+
- 8.2
5+
- 8.3
6+
- 8.4
77

88
env:
99
matrix:

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/pagerduty/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/pagerduty/?branch=master)
1010
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/pagerduty.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/pagerduty)
1111

12-
This package makes it easy to send notification events to [PagerDuty](https://www.pagerduty.com) with Laravel 5.5+, 6.x and 7.x
12+
This package makes it easy to send notification events to [PagerDuty](https://www.pagerduty.com) with Laravel 11.x+
1313

1414
## Contents
1515

composer.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">=7.1",
17-
"guzzlehttp/guzzle": "~6.0|^7.0",
18-
"illuminate/notifications": "~5.5 || ~6.0 || ~7.0 || ^8.0",
19-
"illuminate/support": "~5.5 || ~6.0 || ~7.0 || ^8.0"
16+
"php": ">=8.2",
17+
"guzzlehttp/guzzle": "^7.8.2",
18+
"illuminate/notifications": "^11.0",
19+
"illuminate/support": "^11.0"
2020
},
2121
"require-dev": {
22-
"illuminate/queue": "~5.5 || ~6.0 || ~7.0 || ^8.0",
23-
"mockery/mockery": "^1.2",
24-
"phpunit/phpunit": "^8.5|^9.0"
22+
"illuminate/queue": "^11.0",
23+
"mockery/mockery": "^1.6.10",
24+
"phpunit/phpunit": "^10.5.35|^11.3.6"
2525
},
2626
"autoload": {
2727
"psr-4": {

phpunit.xml.dist

+19-17
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
3-
backupGlobals="false"
4-
backupStaticAttributes="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
55
colors="true"
6-
verbose="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
6+
failOnIncomplete="true"
7+
failOnSkipped="true"
118
stopOnFailure="false">
9+
1210
<testsuites>
1311
<testsuite name="PagerDuty Test Suite">
1412
<directory>tests</directory>
1513
</testsuite>
1614
</testsuites>
17-
<filter>
18-
<whitelist>
15+
<source>
16+
<include>
1917
<directory suffix=".php">src/</directory>
20-
</whitelist>
21-
</filter>
18+
</include>
19+
</source>
20+
<coverage>
21+
<report>
22+
<text outputFile="build/coverage.txt"/>
23+
<clover outputFile="build/logs/clover.xml"/>
24+
<html outputDirectory="build/coverage"/>
25+
</report>
26+
</coverage>
27+
2228
<logging>
23-
<log type="tap" target="build/report.tap"/>
24-
<log type="junit" target="build/report.junit.xml"/>
25-
<log type="coverage-html" target="build/coverage"/>
26-
<log type="coverage-text" target="build/coverage.txt"/>
27-
<log type="coverage-clover" target="build/logs/clover.xml"/>
29+
<junit outputFile="build/report.junit.xml"/>
2830
</logging>
2931
</phpunit>

src/Exceptions/ApiError.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@
22

33
namespace NotificationChannels\PagerDuty\Exceptions;
44

5-
class ApiError extends \Exception
5+
use Exception;
6+
7+
class ApiError extends Exception
68
{
7-
public static function serviceBadRequest($response)
9+
public static function serviceBadRequest(string $response): static
810
{
911
$response = json_decode($response, true);
1012

11-
$message = isset($response['message']) ? $response['message'] : '';
13+
$message = $response['message'] ?? '';
1214
$errors = isset($response['errors']) ? implode(',', $response['errors']) : '';
1315

1416
return new static("PagerDuty returned 400 Bad Request: $message - $errors");
1517
}
1618

17-
public static function rateLimit()
19+
public static function rateLimit(): static
1820
{
1921
// https://v2.developer.pagerduty.com/docs/errors
2022
return new static('PagerDuty returned 429 Too Many Requests');
2123
}
2224

23-
public static function unknownError($code)
25+
public static function unknownError(int $code): static
2426
{
2527
return new static("PagerDuty responded with an unexpected HTTP Status: $code");
2628
}

src/Exceptions/CouldNotSendNotification.php

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

33
namespace NotificationChannels\PagerDuty\Exceptions;
44

5-
class CouldNotSendNotification extends \Exception
5+
use Exception;
6+
7+
class CouldNotSendNotification extends Exception
68
{
7-
public static function create(\Exception $e)
9+
public static function create(Exception $e): static
810
{
911
return new static("Cannot send message to PagerDuty: {$e->getMessage()}", 0, $e);
1012
}

src/PagerDutyChannel.php

+13-16
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,55 @@
22

33
namespace NotificationChannels\PagerDuty;
44

5+
use Exception;
56
use GuzzleHttp\Client;
7+
use GuzzleHttp\Exception\GuzzleException;
68
use Illuminate\Notifications\Notification;
79
use NotificationChannels\PagerDuty\Exceptions\ApiError;
810
use NotificationChannels\PagerDuty\Exceptions\CouldNotSendNotification;
11+
use Psr\Http\Message\ResponseInterface;
912

1013
class PagerDutyChannel
1114
{
12-
/**
13-
* @var Client
14-
*/
15-
protected $client;
16-
17-
public function __construct(Client $client)
15+
public function __construct(protected Client $client)
1816
{
19-
$this->client = $client;
2017
}
2118

2219
/**
2320
* Send the given notification.
2421
*
25-
* @param mixed $notifiable
26-
* @param \Illuminate\Notifications\Notification $notification
22+
* @param mixed $notifiable
23+
* @param Notification $notification
2724
*
28-
* @throws \NotificationChannels\PagerDuty\Exceptions\CouldNotSendNotification
25+
* @throws ApiError|GuzzleException|CouldNotSendNotification
2926
*/
30-
public function send($notifiable, Notification $notification)
27+
public function send(mixed $notifiable, Notification $notification): void
3128
{
32-
if (! $routing_key = $notifiable->routeNotificationFor('PagerDuty')) {
29+
if (! $routingKey = $notifiable->routeNotificationFor('PagerDuty')) {
3330
return;
3431
}
3532

3633
/** @var PagerDutyMessage $data */
3734
$data = $notification->toPagerDuty($notifiable);
38-
$data->setRoutingKey($routing_key);
35+
$data->setRoutingKey($routingKey);
3936

4037
try {
4138
$response = $this->client->post('https://events.pagerduty.com/v2/enqueue', [
4239
'body' => json_encode($data->toArray()),
4340
]);
44-
} catch (\Exception $e) {
41+
} catch (Exception $e) {
4542
throw CouldNotSendNotification::create($e);
4643
}
4744

4845
$this->handleResponse($response);
4946
}
5047

5148
/**
52-
* @param \Psr\Http\Message\ResponseInterface $response
49+
* @param ResponseInterface $response
5350
*
5451
* @throws ApiError
5552
*/
56-
public function handleResponse($response)
53+
public function handleResponse(ResponseInterface $response): void
5754
{
5855
switch ($response->getStatusCode()) {
5956
case 200:

src/PagerDutyMessage.php

+17-18
Original file line numberDiff line numberDiff line change
@@ -9,92 +9,91 @@ class PagerDutyMessage
99
const EVENT_TRIGGER = 'trigger';
1010
const EVENT_RESOLVE = 'resolve';
1111

12-
protected $payload = [];
13-
protected $meta = [];
12+
protected array $payload = [];
13+
protected array $meta = [];
1414

15-
public static function create()
15+
public static function create(): self
1616
{
1717
return new static();
1818
}
1919

2020
public function __construct()
2121
{
2222
Arr::set($this->meta, 'event_action', self::EVENT_TRIGGER);
23-
2423
Arr::set($this->payload, 'source', gethostname());
2524
Arr::set($this->payload, 'severity', 'critical');
2625
}
2726

28-
public function setRoutingKey($value)
27+
public function setRoutingKey(string $value): self
2928
{
3029
return $this->setMeta('routing_key', $value);
3130
}
3231

33-
public function resolve()
32+
public function resolve(): self
3433
{
3534
return $this->setMeta('event_action', self::EVENT_RESOLVE);
3635
}
3736

38-
public function setDedupKey($key)
37+
public function setDedupKey(string $key): self
3938
{
4039
return $this->setMeta('dedup_key', $key);
4140
}
4241

43-
public function setSummary($value)
42+
public function setSummary(string $value): self
4443
{
4544
return $this->setPayload('summary', $value);
4645
}
4746

48-
public function setSource($value)
47+
public function setSource(string $value): self
4948
{
5049
return $this->setPayload('source', $value);
5150
}
5251

53-
public function setSeverity($value)
52+
public function setSeverity(string $value): self
5453
{
5554
return $this->setPayload('severity', $value);
5655
}
5756

58-
public function setTimestamp($value)
57+
public function setTimestamp(string $value): self
5958
{
6059
return $this->setPayload('timestamp', $value);
6160
}
6261

63-
public function setComponent($value)
62+
public function setComponent(string $value): self
6463
{
6564
return $this->setPayload('component', $value);
6665
}
6766

68-
public function setGroup($value)
67+
public function setGroup(string $value): self
6968
{
7069
return $this->setPayload('group', $value);
7170
}
7271

73-
public function setClass($value)
72+
public function setClass(string $value): self
7473
{
7574
return $this->setPayload('class', $value);
7675
}
7776

78-
public function addCustomDetail($key, $value)
77+
public function addCustomDetail(string $key, string $value): self
7978
{
8079
return $this->setPayload("custom_details.$key", $value);
8180
}
8281

83-
protected function setPayload($key, $value)
82+
protected function setPayload(string $key, mixed $value): self
8483
{
8584
Arr::set($this->payload, $key, $value);
8685

8786
return $this;
8887
}
8988

90-
protected function setMeta($key, $value)
89+
protected function setMeta(string $key, mixed $value): self
9190
{
9291
Arr::set($this->meta, $key, $value);
9392

9493
return $this;
9594
}
9695

97-
public function toArray()
96+
public function toArray(): array
9897
{
9998
return Arr::collapse([$this->meta, ['payload' => $this->payload]]);
10099
}

0 commit comments

Comments
 (0)