From dc5d39800c13a1c03f1a4f08ffa44f47280ebd84 Mon Sep 17 00:00:00 2001 From: Andreas Wahlen Date: Tue, 8 Oct 2024 09:57:46 +0200 Subject: [PATCH] Fix PHP 8.4 explicit nullable compatibility --- src/Loader/Loader.php | 6 +++--- src/Loader/LoaderInterface.php | 4 ++-- src/Loader/MoLoader.php | 2 +- src/Loader/PoLoader.php | 2 +- src/Loader/StrictPoLoader.php | 2 +- src/References.php | 2 +- src/Scanner/ParsedFunction.php | 2 +- src/Translation.php | 2 +- src/Translations.php | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Loader/Loader.php b/src/Loader/Loader.php index 684f7cab..3ad072da 100644 --- a/src/Loader/Loader.php +++ b/src/Loader/Loader.php @@ -12,14 +12,14 @@ */ abstract class Loader implements LoaderInterface { - public function loadFile(string $filename, Translations $translations = null): Translations + public function loadFile(string $filename, ?Translations $translations = null): Translations { $string = static::readFile($filename); return $this->loadString($string, $translations); } - public function loadString(string $string, Translations $translations = null): Translations + public function loadString(string $string, ?Translations $translations = null): Translations { return $translations ?: $this->createTranslations(); } @@ -29,7 +29,7 @@ protected function createTranslations(): Translations return Translations::create(); } - protected function createTranslation(?string $context, string $original, string $plural = null): ?Translation + protected function createTranslation(?string $context, string $original, ?string $plural = null): ?Translation { $translation = Translation::create($context, $original); diff --git a/src/Loader/LoaderInterface.php b/src/Loader/LoaderInterface.php index 4f330d3b..0d884e4b 100644 --- a/src/Loader/LoaderInterface.php +++ b/src/Loader/LoaderInterface.php @@ -7,7 +7,7 @@ interface LoaderInterface { - public function loadFile(string $filename, Translations $translations = null): Translations; + public function loadFile(string $filename, ?Translations $translations = null): Translations; - public function loadString(string $string, Translations $translations = null): Translations; + public function loadString(string $string, ?Translations $translations = null): Translations; } diff --git a/src/Loader/MoLoader.php b/src/Loader/MoLoader.php index c5079048..57406813 100644 --- a/src/Loader/MoLoader.php +++ b/src/Loader/MoLoader.php @@ -19,7 +19,7 @@ final class MoLoader extends Loader private const MAGIC2 = -569244523; private const MAGIC3 = 2500072158; - public function loadString(string $string, Translations $translations = null): Translations + public function loadString(string $string, ?Translations $translations = null): Translations { $translations = parent::loadString($string, $translations); $this->init($string); diff --git a/src/Loader/PoLoader.php b/src/Loader/PoLoader.php index d7e4da02..e7e706c7 100644 --- a/src/Loader/PoLoader.php +++ b/src/Loader/PoLoader.php @@ -11,7 +11,7 @@ */ final class PoLoader extends Loader { - public function loadString(string $string, Translations $translations = null): Translations + public function loadString(string $string, ?Translations $translations = null): Translations { $translations = parent::loadString($string, $translations); diff --git a/src/Loader/StrictPoLoader.php b/src/Loader/StrictPoLoader.php index 08233b5f..5a9c1152 100644 --- a/src/Loader/StrictPoLoader.php +++ b/src/Loader/StrictPoLoader.php @@ -41,7 +41,7 @@ final class StrictPoLoader extends Loader /** * Generates a Translations object from a .po based string */ - public function loadString(string $data, Translations $translations = null): Translations + public function loadString(string $data, ?Translations $translations = null): Translations { $this->data = $data; $this->position = 0; diff --git a/src/References.php b/src/References.php index 8a0a6351..b6758b17 100644 --- a/src/References.php +++ b/src/References.php @@ -29,7 +29,7 @@ public function __debugInfo() return $this->toArray(); } - public function add(string $filename, int $line = null): self + public function add(string $filename, ?int $line = null): self { $fileReferences = $this->references[$filename] ?? []; diff --git a/src/Scanner/ParsedFunction.php b/src/Scanner/ParsedFunction.php index 5e7aff05..255df4d1 100644 --- a/src/Scanner/ParsedFunction.php +++ b/src/Scanner/ParsedFunction.php @@ -16,7 +16,7 @@ final class ParsedFunction private $comments = []; private $flags = []; - public function __construct(string $name, string $filename, int $line, int $lastLine = null) + public function __construct(string $name, string $filename, int $line, ?int $lastLine = null) { $this->name = $name; $this->filename = $filename; diff --git a/src/Translation.php b/src/Translation.php index 6f590c42..f4c86adb 100644 --- a/src/Translation.php +++ b/src/Translation.php @@ -194,7 +194,7 @@ public function translatePlural(string ...$translations): self return $this; } - public function getPluralTranslations(int $size = null): array + public function getPluralTranslations(?int $size = null): array { if ($size === null) { return $this->pluralTranslations; diff --git a/src/Translations.php b/src/Translations.php index f0a5964f..761851b5 100644 --- a/src/Translations.php +++ b/src/Translations.php @@ -20,7 +20,7 @@ class Translations implements Countable, IteratorAggregate protected $headers; protected $flags; - public static function create(string $domain = null, string $language = null): Translations + public static function create(?string $domain = null, ?string $language = null): Translations { $translations = new static();