Skip to content

Commit 8cb6ac1

Browse files
authored
Support PHP 8.5 (#439)
- Parameters that are `null` by default must be declared nullable. - Replace deprecated methods of `SplObjectStorage`. - Avoid using `null` as an array offset. - Replace deprecated constant `PDO::MYSQL_ATTR_INIT_COMMAND`. - Replace usage of abandoned package `clue/block-react` with `react/async`.
2 parents f0a5717 + c5de5e6 commit 8cb6ac1

13 files changed

Lines changed: 26 additions & 17 deletions

File tree

application/forms/MoveRotationForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class MoveRotationForm extends Form
3535
*
3636
* @param ?Connection $db
3737
*/
38-
public function __construct(Connection $db = null)
38+
public function __construct(?Connection $db = null)
3939
{
4040
$this->db = $db;
4141
}

application/forms/RotationConfigForm.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,9 +584,11 @@ public function removeRotation(int $id): void
584584
/**
585585
* Remove all versions of the rotation from the database
586586
*
587+
* @param ?int $priority
588+
*
587589
* @return void
588590
*/
589-
public function wipeRotation(int $priority = null): void
591+
public function wipeRotation(?int $priority = null): void
590592
{
591593
$priority = $priority ?? $this->getValue('priority');
592594
if ($priority === null) {

library/Notifications/Api/Middleware/MiddlewarePipeline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
8282
*
8383
* @return ResponseInterface
8484
*/
85-
public function execute(ServerRequestInterface $request = null): ResponseInterface
85+
public function execute(?ServerRequestInterface $request = null): ResponseInterface
8686
{
8787
if ($request === null) {
8888
$request = new ServerRequest('GET', '/'); // initial dummy request

library/Notifications/Api/OpenApiDescriptionElement/Response/Error404Response.php

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

1414
class Error404Response extends Response
1515
{
16-
public function __construct(string $endpointName = null)
16+
public function __construct(?string $endpointName = null)
1717
{
1818
parent::__construct(
1919
response: 404,

library/Notifications/Api/V1/ContactGroups.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ public function prepareRow(stdClass $row): void
763763
*
764764
* @throws HttpException if the username already exists
765765
*/
766-
private function assertUniqueName(string $name, int $contactgroupId = null): void
766+
private function assertUniqueName(string $name, ?int $contactgroupId = null): void
767767
{
768768
$stmt = (new Select())
769769
->from('contactgroup')

library/Notifications/Api/V1/Contacts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ private function removeContact(int $id): void
860860
*
861861
* @throws HttpException if the username already exists
862862
*/
863-
private function assertUniqueUsername(string $username, int $contactId = null): void
863+
private function assertUniqueUsername(string $username, ?int $contactId = null): void
864864
{
865865
$stmt = (new Select())
866866
->from('contact')

library/Notifications/Common/Database.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,15 @@ private static function getConnection(): Connection
7878

7979
$config->options = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ];
8080
if ($config->db === 'mysql') {
81-
$config->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES"
81+
// As of PHP 8.5, driver-specific constants of the PDO class are deprecated,
82+
// but the replacement constants are only available since PHP 8.4.
83+
if (version_compare(PHP_VERSION, '8.4.0', '<')) {
84+
$mysqlAttrInitCommand = PDO::MYSQL_ATTR_INIT_COMMAND;
85+
} else {
86+
$mysqlAttrInitCommand = Pdo\Mysql::ATTR_INIT_COMMAND;
87+
}
88+
89+
$config->options[$mysqlAttrInitCommand] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES"
8290
. ",NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'";
8391
}
8492

library/Notifications/Daemon/Daemon.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
use React\EventLoop\Loop;
2323
use React\EventLoop\LoopInterface;
2424

25-
use function Clue\React\Block\await;
26-
use function React\Promise\Timer\sleep;
25+
use function React\Async\delay;
2726

2827
class Daemon extends EventEmitter
2928
{
@@ -264,7 +263,7 @@ protected function processNotifications(): void
264263
/** @var IncidentHistory $notification */
265264
$notificationsToProcess = [];
266265
foreach ($notifications as $notification) {
267-
if (isset($connections[$notification->contact_id])) {
266+
if ($notification->contact_id !== null && isset($connections[$notification->contact_id])) {
268267
ObjectsRendererHook::register($notification->incident->object);
269268
$notificationsToProcess[] = $notification;
270269

@@ -323,8 +322,8 @@ protected function run(): void
323322

324323
$endMs = (int) (microtime(true) * 1000);
325324
if (($endMs - $beginMs) < 3000) {
326-
// run took less than 3 seconds; sleep for the remaining duration to prevent heavy db loads
327-
await(sleep((3000 - ($endMs - $beginMs)) / 1000));
325+
// run took less than 3 seconds; delay for the remaining duration to prevent heavy db loads
326+
delay((3000 - ($endMs - $beginMs)) / 1000);
328327
}
329328
}
330329
self::$logger::debug(self::PREFIX . "cancellation triggered; exiting loop");

library/Notifications/Web/Form/ContactForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ protected function assemble()
176176

177177
$contact->registerElement($defaultChannel);
178178

179-
$this->addAddressElements($availableTypes, $channelTypes[$defaultChannel->getValue()] ?? null);
179+
$this->addAddressElements($availableTypes, $channelTypes[$defaultChannel->getValue() ?? ''] ?? null);
180180

181181
$this->addHtml(new HtmlElement('hr'));
182182

library/Notifications/Widget/Detail/IncidentQuickActions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ protected function unsubscribe(IncidentContact $incidentContact): void
221221
*
222222
* @return void
223223
*/
224-
protected function updateHistory(IncidentContact $incidentContact, string $newRole = null): void
224+
protected function updateHistory(IncidentContact $incidentContact, ?string $newRole = null): void
225225
{
226226
$oldRole = $incidentContact->role;
227227
$contactId = $incidentContact->contact_id ?? $this->currentUserId;

0 commit comments

Comments
 (0)