From 64e05442a85b548bbe586626badea5a376294869 Mon Sep 17 00:00:00 2001 From: Tom Arbesser-Rastburg Date: Fri, 13 Dec 2024 20:46:05 +1100 Subject: [PATCH] Fix PHP 8.4 deprecation warnings --- PhpcsChanged/CacheManager.php | 2 +- PhpcsChanged/Cli.php | 2 +- PhpcsChanged/LintMessages.php | 2 +- PhpcsChanged/PhpcsMessages.php | 4 ++-- PhpcsChanged/PhpcsMessagesHelpers.php | 4 ++-- PhpcsChanged/UnixShell.php | 2 +- tests/helpers/SvnFixture.php | 2 +- tests/helpers/TestShell.php | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/PhpcsChanged/CacheManager.php b/PhpcsChanged/CacheManager.php index 139862f..0d037e1 100644 --- a/PhpcsChanged/CacheManager.php +++ b/PhpcsChanged/CacheManager.php @@ -45,7 +45,7 @@ class CacheManager { */ private $debug; - public function __construct(CacheInterface $cache, callable $debug = null) { + public function __construct(CacheInterface $cache, ?callable $debug = null) { $this->cache = $cache; $noopDebug = /** @param string[] $output */ diff --git a/PhpcsChanged/Cli.php b/PhpcsChanged/Cli.php index 0c2a646..a2597a6 100644 --- a/PhpcsChanged/Cli.php +++ b/PhpcsChanged/Cli.php @@ -451,7 +451,7 @@ function fileHasValidExtension(\SplFileInfo $file, string $phpcsExtensions = '') // phpcs:enable } -function shouldIgnorePath(string $path, string $patternOption = null): bool { +function shouldIgnorePath(string $path, ?string $patternOption = null): bool { if (null===$patternOption) { return false; } diff --git a/PhpcsChanged/LintMessages.php b/PhpcsChanged/LintMessages.php index 6d6af64..859226d 100644 --- a/PhpcsChanged/LintMessages.php +++ b/PhpcsChanged/LintMessages.php @@ -33,7 +33,7 @@ public static function merge(array $messages) { /** * @return static */ - public static function fromLintMessages(array $messages, string $fileName = null) { + public static function fromLintMessages(array $messages, ?string $fileName = null) { return new static(array_map(function(LintMessage $message) use ($fileName) { if (is_string($fileName) && strlen($fileName) > 0) { $message->setFile($fileName); diff --git a/PhpcsChanged/PhpcsMessages.php b/PhpcsChanged/PhpcsMessages.php index 5bbad49..43d1ae4 100644 --- a/PhpcsChanged/PhpcsMessages.php +++ b/PhpcsChanged/PhpcsMessages.php @@ -11,11 +11,11 @@ public function toPhpcsJson(): string { return PhpcsMessagesHelpers::toPhpcsJson($this); } - public static function fromPhpcsJson(string $messages, string $forcedFileName = null): self { + public static function fromPhpcsJson(string $messages, ?string $forcedFileName = null): self { return PhpcsMessagesHelpers::fromPhpcsJson($messages, $forcedFileName); } - public static function fromArrays(array $messages, string $fileName = null): self { + public static function fromArrays(array $messages, ?string $fileName = null): self { return PhpcsMessagesHelpers::fromArrays($messages, $fileName); } } diff --git a/PhpcsChanged/PhpcsMessagesHelpers.php b/PhpcsChanged/PhpcsMessagesHelpers.php index befc9b4..d2e24fe 100644 --- a/PhpcsChanged/PhpcsMessagesHelpers.php +++ b/PhpcsChanged/PhpcsMessagesHelpers.php @@ -8,7 +8,7 @@ use PhpcsChanged\JsonReporter; class PhpcsMessagesHelpers { - public static function fromPhpcsJson(string $messages, string $forcedFileName = null): PhpcsMessages { + public static function fromPhpcsJson(string $messages, ?string $forcedFileName = null): PhpcsMessages { if (! boolval($messages)) { return self::fromArrays([], $forcedFileName ?? 'STDIN'); } @@ -43,7 +43,7 @@ public static function toPhpcsJson(PhpcsMessages $messages): string { return $reporter->getFormattedMessages($messages, []); } - public static function fromArrays(array $messages, string $fileName = null): PhpcsMessages { + public static function fromArrays(array $messages, ?string $fileName = null): PhpcsMessages { return new PhpcsMessages(array_map(function(array $messageArray) use ($fileName) { return new LintMessage($messageArray['line'] ?? 0, $fileName, $messageArray['type'] ?? 'ERROR', $messageArray); }, $messages)); diff --git a/PhpcsChanged/UnixShell.php b/PhpcsChanged/UnixShell.php index 55688b8..cc10aeb 100644 --- a/PhpcsChanged/UnixShell.php +++ b/PhpcsChanged/UnixShell.php @@ -94,7 +94,7 @@ private function getVendorPhpcsPath(): string { return 'vendor/bin/phpcs'; } - protected function executeCommand(string $command, int &$return_val = null): string { + protected function executeCommand(string $command, ?int &$return_val = null): string { $output = []; exec($command, $output, $return_val); return implode(PHP_EOL, $output) . PHP_EOL; diff --git a/tests/helpers/SvnFixture.php b/tests/helpers/SvnFixture.php index 9cda3b9..340b9b7 100644 --- a/tests/helpers/SvnFixture.php +++ b/tests/helpers/SvnFixture.php @@ -44,7 +44,7 @@ public function getNewFileDiff(string $filename): string { EOF; } - public function getSvnInfo(string $filename, string $revision = '188280', string $lastChangedRevision = null): string { + public function getSvnInfo(string $filename, string $revision = '188280', ?string $lastChangedRevision = null): string { $lastChangedRevision = $lastChangedRevision ?? $revision; return <<fileHashes[$fileName] ?? $fileName; } - protected function executeCommand(string $command, int &$return_val = null): string { + protected function executeCommand(string $command, ?int &$return_val = null): string { foreach ($this->commands as $registeredCommand => $return) { if ($registeredCommand === substr($command, 0, strlen($registeredCommand)) ) { $return_val = $return['return_val'];