From a0887b968bf7bd0b60c0b6dc0f33a21f3be044b3 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Mon, 1 Dec 2025 08:54:02 +0100 Subject: [PATCH 01/27] Mark param explicitly as nullable Errors like: - Deprecated: ipl\Stdlib\Str::trimSplit(): Implicitly marking parameter $limit as nullable is deprecated, the explicit nullable type must be used instead --- src/BaseFilter.php | 4 ++-- src/Str.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BaseFilter.php b/src/BaseFilter.php index 267decb..e24f514 100644 --- a/src/BaseFilter.php +++ b/src/BaseFilter.php @@ -32,11 +32,11 @@ public function getBaseFilter() /** * Set the base filter * - * @param Rule $baseFilter + * @param ?Rule $baseFilter * * @return $this */ - public function setBaseFilter(Rule $baseFilter = null): self + public function setBaseFilter(?Rule $baseFilter = null): self { $this->baseFilter = $baseFilter; diff --git a/src/Str.php b/src/Str.php index b1cd19c..b48663a 100644 --- a/src/Str.php +++ b/src/Str.php @@ -76,7 +76,7 @@ public static function symmetricSplit(?string $subject, string $delimiter, int $ * * @return array */ - public static function trimSplit(?string $subject, string $delimiter = ',', int $limit = null) + public static function trimSplit(?string $subject, string $delimiter = ',', ?int $limit = null) { if ($subject === null || empty($delimiter)) { return []; From 415ad2b019b02f8258d1501b30ec73c1383a4af7 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Mon, 1 Dec 2025 14:49:15 +0100 Subject: [PATCH 02/27] PriorityQueue: Ensure compatibility of return type with SplPriorityQueue --- src/PriorityQueue.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PriorityQueue.php b/src/PriorityQueue.php index 1992ec5..2c3f448 100644 --- a/src/PriorityQueue.php +++ b/src/PriorityQueue.php @@ -25,9 +25,9 @@ class PriorityQueue extends SplPriorityQueue * @param TValue $value * @param TPriority $priority * - * @return bool + * @return true */ - public function insert($value, $priority): bool + public function insert($value, $priority): true { return parent::insert($value, [$priority, $this->serial--]); } From ff553e018a5ca4698fe0d14aad094121a0f4cf3f Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 10 Dec 2025 13:25:08 +0100 Subject: [PATCH 03/27] phpstan.neon: Remove now superfluous `scanDirectories` - https://github.com/Icinga/ipl-stdlib/pull/62 makes it superfluous for github actions --- phpstan.neon | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index b95427a..ef6cdd2 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -11,9 +11,6 @@ parameters: paths: - src - scanDirectories: - - /usr/share/icinga-php - ignoreErrors: - messages: From 8ce944b72841bd1ad093a90535d1585cc60ebb1e Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Thu, 11 Dec 2025 09:01:36 +0100 Subject: [PATCH 04/27] Fix Unit test warning about undefined property PhpUnit Test: ``` - 1 test triggered 2 PHP warnings: 1) /home/runner/work/ipl-stdlib/ipl-stdlib/src/Filter.php:540 Undefined property: stdClass::$foo Triggered by: * ipl\Tests\Stdlib\FilterTest::testConditionsHandleMissingColumnsProperly (6 times) /home/runner/work/ipl-stdlib/ipl-stdlib/tests/FilterTest.php:624 ... ``` --- src/Filter.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Filter.php b/src/Filter.php index 3bbdd36..c5f7902 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -536,11 +536,7 @@ protected function performMatch(Rule $rule, $row) */ protected function extractValue($column, $row) { - try { - return $row->{$column}; - } catch (Throwable $_) { - return null; - } + return $row->$column ?? null; } /** From 475ab2701819d07b5330a5cc981921870cdce601 Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Mon, 8 Dec 2025 14:53:01 +0100 Subject: [PATCH 05/27] Add types in classes that are not extended properties, parameters and returntypes --- src/BaseFilter.php | 4 +- src/Data.php | 14 +++---- src/Filter.php | 56 +++++++++++++------------- src/Filter/Equal.php | 6 +-- src/Filter/Like.php | 6 +-- src/Filter/Unequal.php | 6 +-- src/Filter/Unlike.php | 6 +-- src/Loader/AutoloadingPluginLoader.php | 10 ++--- src/PriorityQueue.php | 4 +- src/Seq.php | 8 ++-- src/Str.php | 8 ++-- src/functions.php | 8 ++-- 12 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/BaseFilter.php b/src/BaseFilter.php index e24f514..7ef4cfa 100644 --- a/src/BaseFilter.php +++ b/src/BaseFilter.php @@ -7,7 +7,7 @@ trait BaseFilter { /** @var Rule Base filter */ - private $baseFilter; + private Rule $baseFilter; /** * Get whether a base filter has been set @@ -24,7 +24,7 @@ public function hasBaseFilter(): bool * * @return ?Rule */ - public function getBaseFilter() + public function getBaseFilter(): ?Rule { return $this->baseFilter; } diff --git a/src/Data.php b/src/Data.php index b12306c..d54d598 100644 --- a/src/Data.php +++ b/src/Data.php @@ -5,14 +5,14 @@ class Data { /** @var array */ - protected $data = []; + protected array $data = []; /** * Check whether there's any data * * @return bool */ - public function isEmpty() + public function isEmpty(): bool { return empty($this->data); } @@ -24,7 +24,7 @@ public function isEmpty() * * @return bool */ - public function has($name) + public function has(string $name): bool { return array_key_exists($name, $this->data); } @@ -37,7 +37,7 @@ public function has($name) * * @return mixed */ - public function get($name, $default = null) + public function get(string $name, mixed $default = null): mixed { if ($this->has($name)) { return $this->data[$name]; @@ -54,7 +54,7 @@ public function get($name, $default = null) * * @return $this */ - public function set($name, $value) + public function set(string $name, mixed $value): static { $this->data[$name] = $value; @@ -68,7 +68,7 @@ public function set($name, $value) * * @return $this */ - public function merge(self $with) + public function merge(self $with): static { $this->data = array_merge($this->data, $with->data); @@ -80,7 +80,7 @@ public function merge(self $with) * * @return $this */ - public function clear() + public function clear(): static { $this->data = []; diff --git a/src/Filter.php b/src/Filter.php index c5f7902..40972b8 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -36,7 +36,7 @@ protected function __construct() * * @return bool */ - public static function match(Rule $rule, $row) + public static function match(Rule $rule, array|object $row): bool { if (! is_object($row)) { if (is_array($row)) { @@ -59,7 +59,7 @@ public static function match(Rule $rule, $row) * * @return Chain */ - public static function all(Rule ...$rules) + public static function all(Rule ...$rules): Chain { return new All(...$rules); } @@ -72,7 +72,7 @@ public static function all(Rule ...$rules) * * @return bool */ - protected function matchAll(All $rules, $row) + protected function matchAll(All $rules, object $row): bool { foreach ($rules as $rule) { if (! $this->performMatch($rule, $row)) { @@ -90,7 +90,7 @@ protected function matchAll(All $rules, $row) * * @return Chain */ - public static function any(Rule ...$rules) + public static function any(Rule ...$rules): Chain { return new Any(...$rules); } @@ -103,7 +103,7 @@ public static function any(Rule ...$rules) * * @return bool */ - protected function matchAny(Any $rules, $row) + protected function matchAny(Any $rules, object $row): bool { foreach ($rules as $rule) { if ($this->performMatch($rule, $row)) { @@ -121,7 +121,7 @@ protected function matchAny(Any $rules, $row) * * @return Chain */ - public static function none(Rule ...$rules) + public static function none(Rule ...$rules): Chain { return new None(...$rules); } @@ -134,7 +134,7 @@ public static function none(Rule ...$rules) * * @return bool */ - protected function matchNone(None $rules, $row) + protected function matchNone(None $rules, object $row): bool { foreach ($rules as $rule) { if ($this->performMatch($rule, $row)) { @@ -153,7 +153,7 @@ protected function matchNone(None $rules, $row) * * @return Condition */ - public static function equal($column, $value) + public static function equal(string $column, array|bool|float|int|string $value): Condition { return new Equal($column, $value); } @@ -166,7 +166,7 @@ public static function equal($column, $value) * * @return bool */ - protected function matchEqual($rule, $row) + protected function matchEqual(Equal|Unequal $rule, object $row): bool { if (! $rule instanceof Equal && ! $rule instanceof Unequal) { throw new InvalidArgumentException(sprintf( @@ -204,7 +204,7 @@ protected function matchEqual($rule, $row) * * @return Condition */ - public static function like($column, $value) + public static function like(string $column, string|array $value): Condition { return new Like($column, $value); } @@ -217,7 +217,7 @@ public static function like($column, $value) * * @return bool */ - protected function matchSimilar($rule, $row) + protected function matchSimilar(Like|Unlike $rule, object $row): bool { if (! $rule instanceof Like && ! $rule instanceof Unlike) { throw new InvalidArgumentException(sprintf( @@ -254,7 +254,7 @@ protected function matchSimilar($rule, $row) * * @return bool */ - protected function performEqualityMatch($value, $rowValue, $ignoreCase = false) + protected function performEqualityMatch(mixed $value, mixed $rowValue, bool $ignoreCase = false): bool { if ($ignoreCase && is_string($rowValue)) { $rowValue = strtolower($rowValue); @@ -280,7 +280,7 @@ protected function performEqualityMatch($value, $rowValue, $ignoreCase = false) * * @return bool */ - protected function performSimilarityMatch($value, $rowValue, $ignoreCase = false) + protected function performSimilarityMatch(mixed $value, mixed $rowValue, bool $ignoreCase = false): bool { if ($ignoreCase && is_string($rowValue)) { $rowValue = strtolower($rowValue); @@ -323,7 +323,7 @@ protected function performSimilarityMatch($value, $rowValue, $ignoreCase = false * * @return Condition */ - public static function unequal($column, $value) + public static function unequal(string $column, array|bool|float|int|string $value): Condition { return new Unequal($column, $value); } @@ -336,7 +336,7 @@ public static function unequal($column, $value) * * @return bool */ - protected function matchUnequal(Unequal $rule, $row) + protected function matchUnequal(Unequal $rule, object $row): bool { return ! $this->matchEqual($rule, $row); } @@ -351,7 +351,7 @@ protected function matchUnequal(Unequal $rule, $row) * * @return Condition */ - public static function unlike($column, $value) + public static function unlike(string $column, string|array $value): Condition { return new Unlike($column, $value); } @@ -364,7 +364,7 @@ public static function unlike($column, $value) * * @return bool */ - protected function matchUnlike(Unlike $rule, $row) + protected function matchUnlike(Unlike $rule, object $row): bool { return ! $this->matchSimilar($rule, $row); } @@ -377,7 +377,7 @@ protected function matchUnlike(Unlike $rule, $row) * * @return Condition */ - public static function greaterThan($column, $value) + public static function greaterThan(string $column, float|int|string $value): Condition { return new GreaterThan($column, $value); } @@ -390,7 +390,7 @@ public static function greaterThan($column, $value) * * @return bool */ - protected function matchGreaterThan(GreaterThan $rule, $row) + protected function matchGreaterThan(GreaterThan $rule, object $row): bool { $rowValue = $this->extractValue($rule->getColumn(), $row); $value = $rule->getValue(); @@ -406,7 +406,7 @@ protected function matchGreaterThan(GreaterThan $rule, $row) * * @return Condition */ - public static function lessThan($column, $value) + public static function lessThan(string $column, float|int|string $value): Condition { return new LessThan($column, $value); } @@ -419,7 +419,7 @@ public static function lessThan($column, $value) * * @return bool */ - protected function matchLessThan(LessThan $rule, $row) + protected function matchLessThan(LessThan $rule, object $row): bool { $rowValue = $this->extractValue($rule->getColumn(), $row); $value = $rule->getValue(); @@ -435,7 +435,7 @@ protected function matchLessThan(LessThan $rule, $row) * * @return Condition */ - public static function greaterThanOrEqual($column, $value) + public static function greaterThanOrEqual(string $column, float|int|string $value): Condition { return new GreaterThanOrEqual($column, $value); } @@ -448,7 +448,7 @@ public static function greaterThanOrEqual($column, $value) * * @return bool */ - protected function matchGreaterThanOrEqual(GreaterThanOrEqual $rule, $row) + protected function matchGreaterThanOrEqual(GreaterThanOrEqual $rule, object $row): bool { $rowValue = $this->extractValue($rule->getColumn(), $row); $value = $rule->getValue(); @@ -464,7 +464,7 @@ protected function matchGreaterThanOrEqual(GreaterThanOrEqual $rule, $row) * * @return Condition */ - public static function lessThanOrEqual($column, $value) + public static function lessThanOrEqual(string $column, float|int|string $value): Condition { return new LessThanOrEqual($column, $value); } @@ -477,7 +477,7 @@ public static function lessThanOrEqual($column, $value) * * @return bool */ - protected function matchLessThanOrEqual(LessThanOrEqual $rule, $row) + protected function matchLessThanOrEqual(LessThanOrEqual $rule, object $row): bool { $rowValue = $this->extractValue($rule->getColumn(), $row); $value = $rule->getValue(); @@ -493,7 +493,7 @@ protected function matchLessThanOrEqual(LessThanOrEqual $rule, $row) * * @return bool */ - protected function performMatch(Rule $rule, $row) + protected function performMatch(Rule $rule, object $row): bool { switch (true) { case $rule instanceof All: @@ -534,7 +534,7 @@ protected function performMatch(Rule $rule, $row) * * @return mixed */ - protected function extractValue($column, $row) + protected function extractValue(string $column, object $row): mixed { return $row->$column ?? null; } @@ -550,7 +550,7 @@ protected function extractValue($column, $row) * * @return void */ - protected function normalizeTypes($rowValue, &$value) + protected function normalizeTypes(mixed $rowValue, mixed &$value): void { if ($rowValue === null || $value === null) { return; diff --git a/src/Filter/Equal.php b/src/Filter/Equal.php index 71da490..f5f22de 100644 --- a/src/Filter/Equal.php +++ b/src/Filter/Equal.php @@ -5,14 +5,14 @@ class Equal extends Condition { /** @var bool */ - protected $ignoreCase = false; + protected bool $ignoreCase = false; /** * Ignore case on both sides of the equation * * @return $this */ - public function ignoreCase() + public function ignoreCase(): static { $this->ignoreCase = true; @@ -24,7 +24,7 @@ public function ignoreCase() * * @return bool */ - public function ignoresCase() + public function ignoresCase(): bool { return $this->ignoreCase; } diff --git a/src/Filter/Like.php b/src/Filter/Like.php index 7a06279..d720c71 100644 --- a/src/Filter/Like.php +++ b/src/Filter/Like.php @@ -5,14 +5,14 @@ class Like extends Condition { /** @var bool */ - protected $ignoreCase = false; + protected bool $ignoreCase = false; /** * Ignore case on both sides of the equation * * @return $this */ - public function ignoreCase() + public function ignoreCase(): static { $this->ignoreCase = true; @@ -24,7 +24,7 @@ public function ignoreCase() * * @return bool */ - public function ignoresCase() + public function ignoresCase(): bool { return $this->ignoreCase; } diff --git a/src/Filter/Unequal.php b/src/Filter/Unequal.php index 5e37cbd..7742dfe 100644 --- a/src/Filter/Unequal.php +++ b/src/Filter/Unequal.php @@ -5,14 +5,14 @@ class Unequal extends Condition { /** @var bool */ - protected $ignoreCase = false; + protected bool $ignoreCase = false; /** * Ignore case on both sides of the equation * * @return $this */ - public function ignoreCase() + public function ignoreCase(): static { $this->ignoreCase = true; @@ -24,7 +24,7 @@ public function ignoreCase() * * @return bool */ - public function ignoresCase() + public function ignoresCase(): bool { return $this->ignoreCase; } diff --git a/src/Filter/Unlike.php b/src/Filter/Unlike.php index 16b9fb3..df8936d 100644 --- a/src/Filter/Unlike.php +++ b/src/Filter/Unlike.php @@ -5,14 +5,14 @@ class Unlike extends Condition { /** @var bool */ - protected $ignoreCase = false; + protected bool $ignoreCase = false; /** * Ignore case on both sides of the equation * * @return $this */ - public function ignoreCase() + public function ignoreCase(): static { $this->ignoreCase = true; @@ -24,7 +24,7 @@ public function ignoreCase() * * @return bool */ - public function ignoresCase() + public function ignoresCase(): bool { return $this->ignoreCase; } diff --git a/src/Loader/AutoloadingPluginLoader.php b/src/Loader/AutoloadingPluginLoader.php index ba195c6..0f4a996 100644 --- a/src/Loader/AutoloadingPluginLoader.php +++ b/src/Loader/AutoloadingPluginLoader.php @@ -10,10 +10,10 @@ class AutoloadingPluginLoader implements PluginLoader { /** @var string Namespace of the plugins */ - protected $namespace; + protected string $namespace; /** @var string Class name postfix */ - protected $postfix; + protected string $postfix; /** * Create a new autoloading plugin loader @@ -21,7 +21,7 @@ class AutoloadingPluginLoader implements PluginLoader * @param string $namespace Namespace of the plugins * @param string $postfix Class name postfix */ - public function __construct($namespace, $postfix = '') + public function __construct(string $namespace, string $postfix = '') { $this->namespace = $namespace; $this->postfix = $postfix; @@ -34,12 +34,12 @@ public function __construct($namespace, $postfix = '') * * @return string */ - protected function getFqn($name) + protected function getFqn(string $name): string { return $this->namespace . '\\' . ucfirst($name) . $this->postfix; } - public function load($name) + public function load($name): false|string { $class = $this->getFqn($name); diff --git a/src/PriorityQueue.php b/src/PriorityQueue.php index 2c3f448..68856d4 100644 --- a/src/PriorityQueue.php +++ b/src/PriorityQueue.php @@ -15,7 +15,7 @@ class PriorityQueue extends SplPriorityQueue { /** @var int */ - protected $serial = PHP_INT_MAX; + protected int $serial = PHP_INT_MAX; /** * Inserts an element in the queue by sifting it up. @@ -37,7 +37,7 @@ public function insert($value, $priority): true * * @return Generator */ - public function yieldAll() + public function yieldAll(): Generator { // Clone queue because the SplPriorityQueue acts as a heap and thus items are removed upon iteration $queue = clone $this; diff --git a/src/Seq.php b/src/Seq.php index dbae277..7d7d407 100644 --- a/src/Seq.php +++ b/src/Seq.php @@ -18,7 +18,7 @@ class Seq * * @return bool */ - public static function contains($traversable, $needle, $caseSensitive = true) + public static function contains($traversable, mixed $needle, bool $caseSensitive = true): bool { return self::find($traversable, $needle, $caseSensitive)[0] !== null; } @@ -33,7 +33,7 @@ public static function contains($traversable, $needle, $caseSensitive = true) * @return array An array with two entries, the first is the key, then the value. * Both are null if nothing is found. */ - public static function find($traversable, $needle, $caseSensitive = true) + public static function find($traversable, mixed $needle, bool $caseSensitive = true): array { $usesCallback = $needle instanceof Closure; if (! $usesCallback && $caseSensitive && is_array($traversable)) { @@ -72,7 +72,7 @@ public static function find($traversable, $needle, $caseSensitive = true) * * @return mixed|null Null if nothing is found */ - public static function findKey($traversable, $needle, $caseSensitive = true) + public static function findKey($traversable, mixed $needle, bool $caseSensitive = true): mixed { return self::find($traversable, $needle, $caseSensitive)[0]; } @@ -86,7 +86,7 @@ public static function findKey($traversable, $needle, $caseSensitive = true) * * @return mixed|null Null if nothing is found */ - public static function findValue($traversable, $needle, $caseSensitive = true) + public static function findValue($traversable, mixed $needle, bool $caseSensitive = true): mixed { $usesCallback = $needle instanceof Closure; if (! $usesCallback && $caseSensitive && is_array($traversable)) { diff --git a/src/Str.php b/src/Str.php index b48663a..338ca4a 100644 --- a/src/Str.php +++ b/src/Str.php @@ -16,7 +16,7 @@ class Str * * @return string */ - public static function camel(?string $subject) + public static function camel(?string $subject): string { if ($subject === null) { return ''; @@ -36,7 +36,7 @@ public static function camel(?string $subject) * * @return bool */ - public static function startsWith(?string $subject, string $start, bool $caseSensitive = true) + public static function startsWith(?string $subject, string $start, bool $caseSensitive = true): bool { $subject = $subject ?? ''; if (! $caseSensitive) { @@ -58,7 +58,7 @@ public static function startsWith(?string $subject, string $start, bool $caseSen * * @return array */ - public static function symmetricSplit(?string $subject, string $delimiter, int $limit, ?string $default = null) + public static function symmetricSplit(?string $subject, string $delimiter, int $limit, ?string $default = null): array { if ($subject === null || empty($delimiter)) { return array_pad([], $limit, $default); @@ -76,7 +76,7 @@ public static function symmetricSplit(?string $subject, string $delimiter, int $ * * @return array */ - public static function trimSplit(?string $subject, string $delimiter = ',', ?int $limit = null) + public static function trimSplit(?string $subject, string $delimiter = ',', ?int $limit = null): array { if ($subject === null || empty($delimiter)) { return []; diff --git a/src/functions.php b/src/functions.php index e7f9be0..bcbfa7f 100644 --- a/src/functions.php +++ b/src/functions.php @@ -17,7 +17,7 @@ * * @return string */ -function get_php_type($subject) +function get_php_type(mixed $subject): string { if (is_object($subject)) { return get_class($subject); @@ -35,7 +35,7 @@ function get_php_type($subject) * * @throws InvalidArgumentException If subject type is invalid */ -function arrayval($subject) +function arrayval($subject): array { if (is_array($subject)) { return $subject; @@ -63,7 +63,7 @@ function arrayval($subject) * * @return mixed The first key of the iterable if it is not empty, null otherwise */ -function iterable_key_first($iterable) +function iterable_key_first(array $iterable): mixed { foreach ($iterable as $key => $_) { return $key; @@ -79,7 +79,7 @@ function iterable_key_first($iterable) * * @return ?mixed */ -function iterable_value_first($iterable) +function iterable_value_first(array $iterable): mixed { foreach ($iterable as $_ => $value) { return $value; From f8acc1caa720d4e1fe537eaba20edb488920038f Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Mon, 8 Dec 2025 15:09:41 +0100 Subject: [PATCH 06/27] Add types in Contract\Translator interface --- src/Contract/Translator.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Contract/Translator.php b/src/Contract/Translator.php index 85ab515..426be9b 100644 --- a/src/Contract/Translator.php +++ b/src/Contract/Translator.php @@ -10,25 +10,25 @@ interface Translator /** * Translate a message * - * @param string $message - * @param string $context Message context + * @param string $message + * @param string|null $context Message context * * @return string Translated message or original message if no translation is found */ - public function translate($message, $context = null); + public function translate(string $message, string $context = null): string; /** * Translate a message in the given domain * * If no translation is found in the specified domain, the translation is also searched for in the default domain. * - * @param string $domain - * @param string $message - * @param string $context Message context + * @param string $domain + * @param string $message + * @param string|null $context Message context * * @return string Translated message or original message if no translation is found */ - public function translateInDomain($domain, $message, $context = null); + public function translateInDomain(string $domain, string $message, ?string $context = null): string; /** * Translate a plural message @@ -36,14 +36,14 @@ public function translateInDomain($domain, $message, $context = null); * The returned message is based on the given number to decide between the singular and plural forms. * That is also the case if no translation is found. * - * @param string $singular Singular message - * @param string $plural Plural message - * @param int $number Number to decide between the returned singular and plural forms - * @param string $context Message context + * @param string $singular Singular message + * @param string $plural Plural message + * @param int $number Number to decide between the returned singular and plural forms + * @param string|null $context Message context * * @return string Translated message or original message if no translation is found */ - public function translatePlural($singular, $plural, $number, $context = null); + public function translatePlural(string $singular, string $plural, int $number, ?string $context = null): string; /** * Translate a plural message in the given domain @@ -53,13 +53,13 @@ public function translatePlural($singular, $plural, $number, $context = null); * The returned message is based on the given number to decide between the singular and plural forms. * That is also the case if no translation is found. * - * @param string $domain - * @param string $singular Singular message - * @param string $plural Plural message - * @param int $number Number to decide between the returned singular and plural forms - * @param string $context Message context + * @param string $domain + * @param string $singular Singular message + * @param string $plural Plural message + * @param int $number Number to decide between the returned singular and plural forms + * @param string|null $context Message context * * @return string Translated message or original message if no translation is found */ - public function translatePluralInDomain($domain, $singular, $plural, $number, $context = null); + public function translatePluralInDomain(string $domain, string $singular, string $plural, int $number, ?string $context = null): string; } From 25ec156ace11f4c947dee12f22eb6c746f7321b3 Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Mon, 8 Dec 2025 15:12:23 +0100 Subject: [PATCH 07/27] Add types in Filters trait --- src/Filters.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Filters.php b/src/Filters.php index defff43..8019bca 100644 --- a/src/Filters.php +++ b/src/Filters.php @@ -4,15 +4,15 @@ trait Filters { - /** @var Filter\Chain */ - protected $filter; + /** @var ?Filter\Chain */ + protected ?Filter\Chain $filter; - public function getFilter() + public function getFilter(): Filter\Chain { return $this->filter ?: Filter::all(); } - public function filter(Filter\Rule $filter) + public function filter(Filter\Rule $filter): static { $currentFilter = $this->getFilter(); if ($currentFilter instanceof Filter\All) { @@ -27,7 +27,7 @@ public function filter(Filter\Rule $filter) return $this; } - public function orFilter(Filter\Rule $filter) + public function orFilter(Filter\Rule $filter): static { $currentFilter = $this->getFilter(); if ($currentFilter instanceof Filter\Any) { @@ -42,14 +42,14 @@ public function orFilter(Filter\Rule $filter) return $this; } - public function notFilter(Filter\Rule $filter) + public function notFilter(Filter\Rule $filter): static { $this->filter(Filter::none($filter)); return $this; } - public function orNotFilter(Filter\Rule $filter) + public function orNotFilter(Filter\Rule $filter): static { $this->orFilter(Filter::none($filter)); From b7a19a0836000c63f7dca345ac25785180c6917b Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Mon, 8 Dec 2025 16:04:45 +0100 Subject: [PATCH 08/27] Add types in Filter/Chain --- src/Filter/Chain.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Filter/Chain.php b/src/Filter/Chain.php index c0060e6..de153f3 100644 --- a/src/Filter/Chain.php +++ b/src/Filter/Chain.php @@ -14,7 +14,7 @@ abstract class Chain implements Rule, MetaDataProvider, IteratorAggregate, Count use MetaData; /** @var array */ - protected $rules = []; + protected array $rules = []; /** * Create a new Chain @@ -59,7 +59,7 @@ public function getIterator(): Traversable * * @return $this */ - public function add(Rule $rule) + public function add(Rule $rule): static { $this->rules[] = $rule; @@ -75,7 +75,7 @@ public function add(Rule $rule) * @throws OutOfBoundsException In case no existing rule is found * @return $this */ - public function insertBefore(Rule $rule, Rule $before) + public function insertBefore(Rule $rule, Rule $before): static { $ruleAt = array_search($before, $this->rules, true); if ($ruleAt === false) { @@ -96,7 +96,7 @@ public function insertBefore(Rule $rule, Rule $before) * @throws OutOfBoundsException In case no existing rule is found * @return $this */ - public function insertAfter(Rule $rule, Rule $after) + public function insertAfter(Rule $rule, Rule $after): static { $ruleAt = array_search($after, $this->rules, true); if ($ruleAt === false) { @@ -115,7 +115,7 @@ public function insertAfter(Rule $rule, Rule $after) * * @return bool */ - public function has(Rule $rule) + public function has(Rule $rule): bool { return array_search($rule, $this->rules, true) !== false; } @@ -129,7 +129,7 @@ public function has(Rule $rule) * @throws OutOfBoundsException In case no existing rule is found * @return $this */ - public function replace(Rule $rule, Rule $replacement) + public function replace(Rule $rule, Rule $replacement): static { $ruleAt = array_search($rule, $this->rules, true); if ($ruleAt === false) { @@ -148,7 +148,7 @@ public function replace(Rule $rule, Rule $replacement) * * @return $this */ - public function remove(Rule $rule) + public function remove(Rule $rule): static { $ruleAt = array_search($rule, $this->rules, true); if ($ruleAt !== false) { @@ -163,7 +163,7 @@ public function remove(Rule $rule) * * @return bool */ - public function isEmpty() + public function isEmpty(): bool { return empty($this->rules); } From 10f73e844f8778608cd3098d889735d0ffd0935a Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Mon, 8 Dec 2025 16:10:39 +0100 Subject: [PATCH 09/27] Add types in Filter/Condition extended in ipl/Sql/Filter/... In, NotIn, Exists, NotExists --- src/Filter/Condition.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Filter/Condition.php b/src/Filter/Condition.php index cc35610..c8e6772 100644 --- a/src/Filter/Condition.php +++ b/src/Filter/Condition.php @@ -7,10 +7,10 @@ abstract class Condition implements Rule, MetaDataProvider use MetaData; /** @var string */ - protected $column; + protected string $column; /** @var mixed */ - protected $value; + protected mixed $value; /** * Create a new Condition @@ -18,7 +18,7 @@ abstract class Condition implements Rule, MetaDataProvider * @param string $column * @param mixed $value */ - public function __construct($column, $value) + public function __construct(string $column, mixed $value) { $this->setColumn($column) ->setValue($value); @@ -41,7 +41,7 @@ public function __clone() * * @return $this */ - public function setColumn($column) + public function setColumn(string $column): static { $this->column = $column; @@ -53,7 +53,7 @@ public function setColumn($column) * * @return string */ - public function getColumn() + public function getColumn(): string { return $this->column; } @@ -65,7 +65,7 @@ public function getColumn() * * @return $this */ - public function setValue($value) + public function setValue(mixed $value): static { $this->value = $value; @@ -77,7 +77,7 @@ public function setValue($value) * * @return mixed */ - public function getValue() + public function getValue(): mixed { return $this->value; } From e85a1da9593f338327f47f18eae38263ad5ae664 Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Mon, 8 Dec 2025 16:15:38 +0100 Subject: [PATCH 10/27] Add types in Filter/MetaData --- src/Filter/MetaData.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Filter/MetaData.php b/src/Filter/MetaData.php index 6fe2523..c56c7a3 100644 --- a/src/Filter/MetaData.php +++ b/src/Filter/MetaData.php @@ -7,9 +7,9 @@ trait MetaData { /** @var Data */ - protected $metaData; + protected Data $metaData; - public function metaData() + public function metaData(): Data { if ($this->metaData === null) { $this->metaData = new Data(); From ead06b6df83f9cc59c7763bf6d9f32611231309a Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Mon, 8 Dec 2025 16:16:20 +0100 Subject: [PATCH 11/27] Add types in Filter/MetaDataProvider interface implemented in ipl/Sql/Filter/... In, NotIn, Exists, NotExists --- src/Filter/MetaDataProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Filter/MetaDataProvider.php b/src/Filter/MetaDataProvider.php index ef9557e..c4f0ab9 100644 --- a/src/Filter/MetaDataProvider.php +++ b/src/Filter/MetaDataProvider.php @@ -11,5 +11,5 @@ interface MetaDataProvider * * @return Data */ - public function metaData(); + public function metaData(): Data; } From b0c7d2eb4b2e990a121b512a4d2815fa4d156189 Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Mon, 8 Dec 2025 16:27:21 +0100 Subject: [PATCH 12/27] Add types in Contract/Filterable interface --- src/Contract/Filterable.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Contract/Filterable.php b/src/Contract/Filterable.php index 2a6316a..a6fcdb3 100644 --- a/src/Contract/Filterable.php +++ b/src/Contract/Filterable.php @@ -11,7 +11,7 @@ interface Filterable * * @return Filter\Chain */ - public function getFilter(); + public function getFilter(): Filter\Chain; /** * Add a filter to the query @@ -23,7 +23,7 @@ public function getFilter(); * * @return $this */ - public function filter(Filter\Rule $filter); + public function filter(Filter\Rule $filter): static; /** * Add a filter to the query @@ -35,7 +35,7 @@ public function filter(Filter\Rule $filter); * * @return $this */ - public function orFilter(Filter\Rule $filter); + public function orFilter(Filter\Rule $filter): static; /** * Add a filter to the query @@ -47,7 +47,7 @@ public function orFilter(Filter\Rule $filter); * * @return $this */ - public function notFilter(Filter\Rule $filter); + public function notFilter(Filter\Rule $filter): static; /** * Add a filter to the query @@ -59,5 +59,5 @@ public function notFilter(Filter\Rule $filter); * * @return $this */ - public function orNotFilter(Filter\Rule $filter); + public function orNotFilter(Filter\Rule $filter): static; } From d8e4964462e9685ea1e3a1353b94e73ee5899b0f Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Mon, 8 Dec 2025 16:42:44 +0100 Subject: [PATCH 13/27] Add types in Contract/Pagination interface --- src/Contract/Paginatable.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Contract/Paginatable.php b/src/Contract/Paginatable.php index 3e2a4ee..07470af 100644 --- a/src/Contract/Paginatable.php +++ b/src/Contract/Paginatable.php @@ -11,14 +11,14 @@ interface Paginatable extends Countable * * @return bool */ - public function hasLimit(); + public function hasLimit(): bool; /** * Get the limit * * @return int|null */ - public function getLimit(); + public function getLimit(): ?int; /** * Set the limit @@ -28,21 +28,21 @@ public function getLimit(); * * @return $this */ - public function limit($limit); + public function limit(?int $limit): static; /** * Get whether an offset is set * * @return bool */ - public function hasOffset(); + public function hasOffset(): bool; /** * Get the offset * * @return int|null */ - public function getOffset(); + public function getOffset(): ?int; /** * Set the offset @@ -52,5 +52,5 @@ public function getOffset(); * * @return $this */ - public function offset($offset); + public function offset(?int $offset): static; } From f270417ce351abe0cbf736b3df9782b0d0e14ebd Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Mon, 8 Dec 2025 16:49:40 +0100 Subject: [PATCH 14/27] Add types in Contract/PluginLoader interface --- src/Contract/PluginLoader.php | 2 +- src/Loader/AutoloadingPluginLoader.php | 2 +- tests/Loader/TestPluginLoader.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Contract/PluginLoader.php b/src/Contract/PluginLoader.php index 1be779c..5c5bdd7 100644 --- a/src/Contract/PluginLoader.php +++ b/src/Contract/PluginLoader.php @@ -17,5 +17,5 @@ interface PluginLoader * * @return string|false FQN of the plugin's class if found, false otherwise */ - public function load($name); + public function load(string $name): false|string; } diff --git a/src/Loader/AutoloadingPluginLoader.php b/src/Loader/AutoloadingPluginLoader.php index 0f4a996..a9de176 100644 --- a/src/Loader/AutoloadingPluginLoader.php +++ b/src/Loader/AutoloadingPluginLoader.php @@ -39,7 +39,7 @@ protected function getFqn(string $name): string return $this->namespace . '\\' . ucfirst($name) . $this->postfix; } - public function load($name): false|string + public function load(string $name): false|string { $class = $this->getFqn($name); diff --git a/tests/Loader/TestPluginLoader.php b/tests/Loader/TestPluginLoader.php index 1ec8f61..ed6b4cd 100644 --- a/tests/Loader/TestPluginLoader.php +++ b/tests/Loader/TestPluginLoader.php @@ -16,7 +16,7 @@ public function __construct($canLoad = true) $this->canLoad = $canLoad; } - public function load($name) + public function load(string $name) { if (! $this->canLoad) { return false; From e751a986f6d91c29c9555f6d0a3a8d51f282a8f2 Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Tue, 9 Dec 2025 10:31:36 +0100 Subject: [PATCH 15/27] Apply review suggestions --- src/Contract/Translator.php | 2 +- src/Filter/Condition.php | 4 ++-- src/Filter/MetaData.php | 4 ++-- src/functions.php | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Contract/Translator.php b/src/Contract/Translator.php index 426be9b..15ae8f6 100644 --- a/src/Contract/Translator.php +++ b/src/Contract/Translator.php @@ -15,7 +15,7 @@ interface Translator * * @return string Translated message or original message if no translation is found */ - public function translate(string $message, string $context = null): string; + public function translate(string $message, ?string $context = null): string; /** * Translate a message in the given domain diff --git a/src/Filter/Condition.php b/src/Filter/Condition.php index c8e6772..b425a99 100644 --- a/src/Filter/Condition.php +++ b/src/Filter/Condition.php @@ -7,10 +7,10 @@ abstract class Condition implements Rule, MetaDataProvider use MetaData; /** @var string */ - protected string $column; + protected $column; /** @var mixed */ - protected mixed $value; + protected $value; /** * Create a new Condition diff --git a/src/Filter/MetaData.php b/src/Filter/MetaData.php index c56c7a3..700b2ff 100644 --- a/src/Filter/MetaData.php +++ b/src/Filter/MetaData.php @@ -6,8 +6,8 @@ trait MetaData { - /** @var Data */ - protected Data $metaData; + /** @var ?Data */ + protected ?Data $metaData = null; public function metaData(): Data { diff --git a/src/functions.php b/src/functions.php index bcbfa7f..b455580 100644 --- a/src/functions.php +++ b/src/functions.php @@ -63,7 +63,7 @@ function arrayval($subject): array * * @return mixed The first key of the iterable if it is not empty, null otherwise */ -function iterable_key_first(array $iterable): mixed +function iterable_key_first(iterable $iterable): mixed { foreach ($iterable as $key => $_) { return $key; @@ -79,7 +79,7 @@ function iterable_key_first(array $iterable): mixed * * @return ?mixed */ -function iterable_value_first(array $iterable): mixed +function iterable_value_first(iterable $iterable): mixed { foreach ($iterable as $_ => $value) { return $value; From fbead8c1d8715235d8c0ad4ebb217066bd86f9a2 Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Tue, 9 Dec 2025 10:51:37 +0100 Subject: [PATCH 16/27] Fix missing property initialization --- src/Filters.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Filters.php b/src/Filters.php index 8019bca..c4b03ad 100644 --- a/src/Filters.php +++ b/src/Filters.php @@ -5,7 +5,7 @@ trait Filters { /** @var ?Filter\Chain */ - protected ?Filter\Chain $filter; + protected ?Filter\Chain $filter = null; public function getFilter(): Filter\Chain { From 1148d952cb4fe80a11c40083097b5b67e695e991 Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Tue, 9 Dec 2025 10:59:13 +0100 Subject: [PATCH 17/27] Update BaseFilter with nullable property prevent the error: Typed property Icinga\Module\Icingadb\Widget\Detail\ObjectStatistics::$baseFilter must not be accessed before initialization --- src/BaseFilter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BaseFilter.php b/src/BaseFilter.php index 7ef4cfa..4e7862f 100644 --- a/src/BaseFilter.php +++ b/src/BaseFilter.php @@ -6,8 +6,8 @@ trait BaseFilter { - /** @var Rule Base filter */ - private Rule $baseFilter; + /** @var ?Rule Base filter */ + private ?Rule $baseFilter = null; /** * Get whether a base filter has been set From 152e88f18a94bcb55ba1f40caf0f3718ff32d0cb Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Tue, 9 Dec 2025 11:35:16 +0100 Subject: [PATCH 18/27] Adjust Condition setter & getter --- src/Filter/Condition.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Filter/Condition.php b/src/Filter/Condition.php index b425a99..8bdf654 100644 --- a/src/Filter/Condition.php +++ b/src/Filter/Condition.php @@ -41,7 +41,7 @@ public function __clone() * * @return $this */ - public function setColumn(string $column): static + public function setColumn($column): static { $this->column = $column; @@ -53,7 +53,7 @@ public function setColumn(string $column): static * * @return string */ - public function getColumn(): string + public function getColumn() { return $this->column; } @@ -65,7 +65,7 @@ public function getColumn(): string * * @return $this */ - public function setValue(mixed $value): static + public function setValue($value): static { $this->value = $value; @@ -77,7 +77,7 @@ public function setValue(mixed $value): static * * @return mixed */ - public function getValue(): mixed + public function getValue() { return $this->value; } From fa6c4efe50e9964db1fc1c1f2cfcd96c78c6d8ef Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Tue, 9 Dec 2025 11:37:17 +0100 Subject: [PATCH 19/27] Add Datetime to Filter parameter uniontype --- src/Filter.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Filter.php b/src/Filter.php index 40972b8..b2e28bf 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -2,6 +2,7 @@ namespace ipl\Stdlib; +use DateTime; use InvalidArgumentException; use ipl\Stdlib\Filter\All; use ipl\Stdlib\Filter\Any; @@ -373,11 +374,11 @@ protected function matchUnlike(Unlike $rule, object $row): bool * Create a rule that matches rows with a column that is **greater** than the given value * * @param string $column - * @param float|int|string $value + * @param float|int|string|DateTime $value * * @return Condition */ - public static function greaterThan(string $column, float|int|string $value): Condition + public static function greaterThan(string $column, float|int|string|DateTime $value): Condition { return new GreaterThan($column, $value); } @@ -431,11 +432,11 @@ protected function matchLessThan(LessThan $rule, object $row): bool * Create a rule that matches rows with a column that is **greater** than or **equal** to the given value * * @param string $column - * @param float|int|string $value + * @param float|int|string|DateTime $value * * @return Condition */ - public static function greaterThanOrEqual(string $column, float|int|string $value): Condition + public static function greaterThanOrEqual(string $column, float|int|string|DateTime $value): Condition { return new GreaterThanOrEqual($column, $value); } From 58b90f7988c40397ab9d765334de82ed08861ad7 Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Tue, 9 Dec 2025 11:39:03 +0100 Subject: [PATCH 20/27] Replace null with empty string in Plugins::wantPluginLoader() e.g. ipl\Html\FormElement::addElementLoader() allows to call the method with null --- src/Plugins.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins.php b/src/Plugins.php index a5dbb77..5e9c12b 100644 --- a/src/Plugins.php +++ b/src/Plugins.php @@ -23,7 +23,7 @@ public static function wantPluginLoader($loaderOrNamespace, $postfix = '') if ($loaderOrNamespace instanceof PluginLoader) { $loader = $loaderOrNamespace; } else { - $loader = new AutoloadingPluginLoader($loaderOrNamespace, $postfix); + $loader = new AutoloadingPluginLoader($loaderOrNamespace, $postfix ?? ''); } return $loader; From e34c39f3ddcdd4ce7692d96e3100f2ecd1319419 Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Tue, 9 Dec 2025 14:10:18 +0100 Subject: [PATCH 21/27] Adjust types in Filter/Condition Depends on removing the ipl\Sql\Filter\InAndNotInUtils trait --- src/Filter/Condition.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Filter/Condition.php b/src/Filter/Condition.php index 8bdf654..dfb160a 100644 --- a/src/Filter/Condition.php +++ b/src/Filter/Condition.php @@ -6,19 +6,19 @@ abstract class Condition implements Rule, MetaDataProvider { use MetaData; - /** @var string */ - protected $column; + /** @var string|string[] */ + protected string|array $column = []; /** @var mixed */ - protected $value; + protected mixed $value = null; /** * Create a new Condition * - * @param string $column + * @param string|string[] $column * @param mixed $value */ - public function __construct(string $column, mixed $value) + public function __construct(string|array $column, mixed $value) { $this->setColumn($column) ->setValue($value); @@ -37,11 +37,11 @@ public function __clone() /** * Set this condition's column * - * @param string $column + * @param string|string[] $column * * @return $this */ - public function setColumn($column): static + public function setColumn(string|array $column): static { $this->column = $column; @@ -51,9 +51,9 @@ public function setColumn($column): static /** * Get this condition's column * - * @return string + * @return string|string[] */ - public function getColumn() + public function getColumn(): string|array { return $this->column; } @@ -65,7 +65,7 @@ public function getColumn() * * @return $this */ - public function setValue($value): static + public function setValue(mixed $value): static { $this->value = $value; @@ -77,7 +77,7 @@ public function setValue($value): static * * @return mixed */ - public function getValue() + public function getValue(): mixed { return $this->value; } From b04e7f4d360f30c60683b2fb6f7e3f1a6cda579e Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Wed, 10 Dec 2025 13:07:35 +0100 Subject: [PATCH 22/27] Appply review suggestion: return type to static --- src/BaseFilter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BaseFilter.php b/src/BaseFilter.php index 4e7862f..0b0a946 100644 --- a/src/BaseFilter.php +++ b/src/BaseFilter.php @@ -36,7 +36,7 @@ public function getBaseFilter(): ?Rule * * @return $this */ - public function setBaseFilter(?Rule $baseFilter = null): self + public function setBaseFilter(?Rule $baseFilter = null): static { $this->baseFilter = $baseFilter; From 96e539bc2a99f11a792215ae1debc49c1f8864e2 Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Wed, 10 Dec 2025 13:09:43 +0100 Subject: [PATCH 23/27] Appply review suggestion: add DateTime to union types --- src/Filter.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Filter.php b/src/Filter.php index b2e28bf..98f0e09 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -150,11 +150,11 @@ protected function matchNone(None $rules, object $row): bool * Create a rule that matches rows with a column that **equals** the given value * * @param string $column - * @param array|bool|float|int|string $value + * @param array|bool|float|int|string|DateTime $value * * @return Condition */ - public static function equal(string $column, array|bool|float|int|string $value): Condition + public static function equal(string $column, array|bool|float|int|string|DateTime $value): Condition { return new Equal($column, $value); } @@ -320,11 +320,11 @@ protected function performSimilarityMatch(mixed $value, mixed $rowValue, bool $i * Create a rule that matches rows with a column that is **unequal** with the given value * * @param string $column - * @param array|bool|float|int|string $value + * @param array|bool|float|int|string|DateTime $value * * @return Condition */ - public static function unequal(string $column, array|bool|float|int|string $value): Condition + public static function unequal(string $column, array|bool|float|int|string|DateTime $value): Condition { return new Unequal($column, $value); } @@ -403,11 +403,11 @@ protected function matchGreaterThan(GreaterThan $rule, object $row): bool * Create a rule that matches rows with a column that is **less** than the given value * * @param string $column - * @param float|int|string $value + * @param float|int|string|DateTime $value * * @return Condition */ - public static function lessThan(string $column, float|int|string $value): Condition + public static function lessThan(string $column, float|int|string|DateTime $value): Condition { return new LessThan($column, $value); } @@ -461,11 +461,11 @@ protected function matchGreaterThanOrEqual(GreaterThanOrEqual $rule, object $row * Create a rule that matches rows with a column that is **less** than or **equal** to the given value * * @param string $column - * @param float|int|string $value + * @param float|int|string|DateTime $value * * @return Condition */ - public static function lessThanOrEqual(string $column, float|int|string $value): Condition + public static function lessThanOrEqual(string $column, float|int|string|DateTime $value): Condition { return new LessThanOrEqual($column, $value); } From 7615b5104dece069ea0470e03bc3c94f4ee40653 Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Wed, 10 Dec 2025 13:11:51 +0100 Subject: [PATCH 24/27] Appply review suggestion: TestPluginLoader add return type --- tests/Loader/TestPluginLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Loader/TestPluginLoader.php b/tests/Loader/TestPluginLoader.php index ed6b4cd..8ce4651 100644 --- a/tests/Loader/TestPluginLoader.php +++ b/tests/Loader/TestPluginLoader.php @@ -16,7 +16,7 @@ public function __construct($canLoad = true) $this->canLoad = $canLoad; } - public function load(string $name) + public function load(string $name): false|string { if (! $this->canLoad) { return false; From cf59452980842fed257e33d272a12769bdb791d2 Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Wed, 10 Dec 2025 13:13:03 +0100 Subject: [PATCH 25/27] Appply review suggestion: declare $traversable as iterable --- src/Seq.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Seq.php b/src/Seq.php index 7d7d407..14cb755 100644 --- a/src/Seq.php +++ b/src/Seq.php @@ -12,13 +12,13 @@ class Seq /** * Check if the traversable contains the given needle * - * @param array|iterable $traversable + * @param iterable $traversable * @param mixed $needle Might also be a closure * @param bool $caseSensitive Whether strings should be compared case-sensitive * * @return bool */ - public static function contains($traversable, mixed $needle, bool $caseSensitive = true): bool + public static function contains(iterable $traversable, mixed $needle, bool $caseSensitive = true): bool { return self::find($traversable, $needle, $caseSensitive)[0] !== null; } @@ -26,14 +26,14 @@ public static function contains($traversable, mixed $needle, bool $caseSensitive /** * Search in the traversable for the given needle and return its key and value * - * @param array|iterable $traversable + * @param iterable $traversable * @param mixed $needle Might also be a closure * @param bool $caseSensitive Whether strings should be compared case-sensitive * * @return array An array with two entries, the first is the key, then the value. * Both are null if nothing is found. */ - public static function find($traversable, mixed $needle, bool $caseSensitive = true): array + public static function find(iterable $traversable, mixed $needle, bool $caseSensitive = true): array { $usesCallback = $needle instanceof Closure; if (! $usesCallback && $caseSensitive && is_array($traversable)) { @@ -66,13 +66,13 @@ public static function find($traversable, mixed $needle, bool $caseSensitive = t /** * Search in the traversable for the given needle and return its key * - * @param array|iterable $traversable + * @param iterable $traversable * @param mixed $needle Might also be a closure * @param bool $caseSensitive Whether strings should be compared case-sensitive * * @return mixed|null Null if nothing is found */ - public static function findKey($traversable, mixed $needle, bool $caseSensitive = true): mixed + public static function findKey(iterable $traversable, mixed $needle, bool $caseSensitive = true): mixed { return self::find($traversable, $needle, $caseSensitive)[0]; } @@ -80,13 +80,13 @@ public static function findKey($traversable, mixed $needle, bool $caseSensitive /** * Search in the traversable for the given needle and return its value * - * @param array|iterable $traversable + * @param iterable $traversable * @param mixed $needle Might also be a closure * @param bool $caseSensitive Whether strings should be compared case-sensitive * * @return mixed|null Null if nothing is found */ - public static function findValue($traversable, mixed $needle, bool $caseSensitive = true): mixed + public static function findValue(iterable $traversable, mixed $needle, bool $caseSensitive = true): mixed { $usesCallback = $needle instanceof Closure; if (! $usesCallback && $caseSensitive && is_array($traversable)) { From eb5ac10b152684a2cd74923e0bd63ef7a922c1d6 Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Wed, 10 Dec 2025 13:50:04 +0100 Subject: [PATCH 26/27] Add null to parameter union types, to preserve expected behavior --- src/Filter.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Filter.php b/src/Filter.php index 98f0e09..dd10408 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -150,11 +150,11 @@ protected function matchNone(None $rules, object $row): bool * Create a rule that matches rows with a column that **equals** the given value * * @param string $column - * @param array|bool|float|int|string|DateTime $value + * @param array|bool|float|int|string|DateTime|null $value * * @return Condition */ - public static function equal(string $column, array|bool|float|int|string|DateTime $value): Condition + public static function equal(string $column, array|bool|float|int|string|DateTime|null $value): Condition { return new Equal($column, $value); } @@ -201,11 +201,11 @@ protected function matchEqual(Equal|Unequal $rule, object $row): bool * Performs a wildcard search if the value contains asterisks. * * @param string $column - * @param string|string[] $value + * @param string|string[]|null $value * * @return Condition */ - public static function like(string $column, string|array $value): Condition + public static function like(string $column, string|array|null $value): Condition { return new Like($column, $value); } @@ -320,11 +320,11 @@ protected function performSimilarityMatch(mixed $value, mixed $rowValue, bool $i * Create a rule that matches rows with a column that is **unequal** with the given value * * @param string $column - * @param array|bool|float|int|string|DateTime $value + * @param array|bool|float|int|string|DateTime|null $value * * @return Condition */ - public static function unequal(string $column, array|bool|float|int|string|DateTime $value): Condition + public static function unequal(string $column, array|bool|float|int|string|DateTime|null $value): Condition { return new Unequal($column, $value); } @@ -348,11 +348,11 @@ protected function matchUnequal(Unequal $rule, object $row): bool * Performs a wildcard search if the value contains asterisks. * * @param string $column - * @param string|string[] $value + * @param string|string[]|null $value * * @return Condition */ - public static function unlike(string $column, string|array $value): Condition + public static function unlike(string $column, string|array|null $value): Condition { return new Unlike($column, $value); } @@ -374,11 +374,11 @@ protected function matchUnlike(Unlike $rule, object $row): bool * Create a rule that matches rows with a column that is **greater** than the given value * * @param string $column - * @param float|int|string|DateTime $value + * @param float|int|string|DateTime|null $value * * @return Condition */ - public static function greaterThan(string $column, float|int|string|DateTime $value): Condition + public static function greaterThan(string $column, float|int|string|DateTime|null $value): Condition { return new GreaterThan($column, $value); } @@ -403,11 +403,11 @@ protected function matchGreaterThan(GreaterThan $rule, object $row): bool * Create a rule that matches rows with a column that is **less** than the given value * * @param string $column - * @param float|int|string|DateTime $value + * @param float|int|string|DateTime|null $value * * @return Condition */ - public static function lessThan(string $column, float|int|string|DateTime $value): Condition + public static function lessThan(string $column, float|int|string|DateTime|null $value): Condition { return new LessThan($column, $value); } @@ -432,11 +432,11 @@ protected function matchLessThan(LessThan $rule, object $row): bool * Create a rule that matches rows with a column that is **greater** than or **equal** to the given value * * @param string $column - * @param float|int|string|DateTime $value + * @param float|int|string|DateTime|null $value * * @return Condition */ - public static function greaterThanOrEqual(string $column, float|int|string|DateTime $value): Condition + public static function greaterThanOrEqual(string $column, float|int|string|DateTime|null $value): Condition { return new GreaterThanOrEqual($column, $value); } @@ -461,11 +461,11 @@ protected function matchGreaterThanOrEqual(GreaterThanOrEqual $rule, object $row * Create a rule that matches rows with a column that is **less** than or **equal** to the given value * * @param string $column - * @param float|int|string|DateTime $value + * @param float|int|string|DateTime|null $value * * @return Condition */ - public static function lessThanOrEqual(string $column, float|int|string|DateTime $value): Condition + public static function lessThanOrEqual(string $column, float|int|string|DateTime|null $value): Condition { return new LessThanOrEqual($column, $value); } From 0e8fbc5fd7b904cfaa9dee892f0da6830ec908b7 Mon Sep 17 00:00:00 2001 From: Jan Schuppik Date: Thu, 11 Dec 2025 09:24:06 +0100 Subject: [PATCH 27/27] Apply review suggestions removing parameter uniontypes & unnecessary typechecking, change switch to match --- src/Filter.php | 87 +++++++++++++++++--------------------------------- 1 file changed, 29 insertions(+), 58 deletions(-) diff --git a/src/Filter.php b/src/Filter.php index dd10408..c8b9afd 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -2,7 +2,6 @@ namespace ipl\Stdlib; -use DateTime; use InvalidArgumentException; use ipl\Stdlib\Filter\All; use ipl\Stdlib\Filter\Any; @@ -150,11 +149,11 @@ protected function matchNone(None $rules, object $row): bool * Create a rule that matches rows with a column that **equals** the given value * * @param string $column - * @param array|bool|float|int|string|DateTime|null $value + * @param array|bool|float|int|string $value * * @return Condition */ - public static function equal(string $column, array|bool|float|int|string|DateTime|null $value): Condition + public static function equal(string $column, $value): Condition { return new Equal($column, $value); } @@ -169,15 +168,6 @@ public static function equal(string $column, array|bool|float|int|string|DateTim */ protected function matchEqual(Equal|Unequal $rule, object $row): bool { - if (! $rule instanceof Equal && ! $rule instanceof Unequal) { - throw new InvalidArgumentException(sprintf( - 'Rule must be of type %s or %s, got %s instead', - Equal::class, - Unequal::class, - get_php_type($rule) - )); - } - $rowValue = $this->extractValue($rule->getColumn(), $row); $value = $rule->getValue(); $this->normalizeTypes($rowValue, $value); @@ -220,15 +210,6 @@ public static function like(string $column, string|array|null $value): Condition */ protected function matchSimilar(Like|Unlike $rule, object $row): bool { - if (! $rule instanceof Like && ! $rule instanceof Unlike) { - throw new InvalidArgumentException(sprintf( - 'Rule must be of type %s or %s, got %s instead', - Like::class, - Unlike::class, - get_php_type($rule) - )); - } - $rowValue = $this->extractValue($rule->getColumn(), $row); $value = $rule->getValue(); $this->normalizeTypes($rowValue, $value); @@ -320,11 +301,11 @@ protected function performSimilarityMatch(mixed $value, mixed $rowValue, bool $i * Create a rule that matches rows with a column that is **unequal** with the given value * * @param string $column - * @param array|bool|float|int|string|DateTime|null $value + * @param array|bool|float|int|string $value * * @return Condition */ - public static function unequal(string $column, array|bool|float|int|string|DateTime|null $value): Condition + public static function unequal(string $column, $value): Condition { return new Unequal($column, $value); } @@ -374,11 +355,11 @@ protected function matchUnlike(Unlike $rule, object $row): bool * Create a rule that matches rows with a column that is **greater** than the given value * * @param string $column - * @param float|int|string|DateTime|null $value + * @param float|int|string $value * * @return Condition */ - public static function greaterThan(string $column, float|int|string|DateTime|null $value): Condition + public static function greaterThan(string $column, $value): Condition { return new GreaterThan($column, $value); } @@ -403,11 +384,11 @@ protected function matchGreaterThan(GreaterThan $rule, object $row): bool * Create a rule that matches rows with a column that is **less** than the given value * * @param string $column - * @param float|int|string|DateTime|null $value + * @param float|int|string $value * * @return Condition */ - public static function lessThan(string $column, float|int|string|DateTime|null $value): Condition + public static function lessThan(string $column, $value): Condition { return new LessThan($column, $value); } @@ -432,11 +413,11 @@ protected function matchLessThan(LessThan $rule, object $row): bool * Create a rule that matches rows with a column that is **greater** than or **equal** to the given value * * @param string $column - * @param float|int|string|DateTime|null $value + * @param float|int|string $value * * @return Condition */ - public static function greaterThanOrEqual(string $column, float|int|string|DateTime|null $value): Condition + public static function greaterThanOrEqual(string $column, $value): Condition { return new GreaterThanOrEqual($column, $value); } @@ -461,11 +442,11 @@ protected function matchGreaterThanOrEqual(GreaterThanOrEqual $rule, object $row * Create a rule that matches rows with a column that is **less** than or **equal** to the given value * * @param string $column - * @param float|int|string|DateTime|null $value + * @param float|int|string $value * * @return Condition */ - public static function lessThanOrEqual(string $column, float|int|string|DateTime|null $value): Condition + public static function lessThanOrEqual(string $column, $value): Condition { return new LessThanOrEqual($column, $value); } @@ -496,35 +477,25 @@ protected function matchLessThanOrEqual(LessThanOrEqual $rule, object $row): boo */ protected function performMatch(Rule $rule, object $row): bool { - switch (true) { - case $rule instanceof All: - return $this->matchAll($rule, $row); - case $rule instanceof Any: - return $this->matchAny($rule, $row); - case $rule instanceof Like: - return $this->matchSimilar($rule, $row); - case $rule instanceof Equal: - return $this->matchEqual($rule, $row); - case $rule instanceof GreaterThan: - return $this->matchGreaterThan($rule, $row); - case $rule instanceof GreaterThanOrEqual: - return $this->matchGreaterThanOrEqual($rule, $row); - case $rule instanceof LessThan: - return $this->matchLessThan($rule, $row); - case $rule instanceof LessThanOrEqual: - return $this->matchLessThanOrEqual($rule, $row); - case $rule instanceof None: - return $this->matchNone($rule, $row); - case $rule instanceof Unequal: - return $this->matchUnequal($rule, $row); - case $rule instanceof Unlike: - return $this->matchUnlike($rule, $row); - default: - throw new InvalidArgumentException(sprintf( + return match (true) { + $rule instanceof All => $this->matchAll($rule, $row), + $rule instanceof Any => $this->matchAny($rule, $row), + $rule instanceof Like => $this->matchSimilar($rule, $row), + $rule instanceof Equal => $this->matchEqual($rule, $row), + $rule instanceof GreaterThan => $this->matchGreaterThan($rule, $row), + $rule instanceof GreaterThanOrEqual => $this->matchGreaterThanOrEqual($rule, $row), + $rule instanceof LessThan => $this->matchLessThan($rule, $row), + $rule instanceof LessThanOrEqual => $this->matchLessThanOrEqual($rule, $row), + $rule instanceof None => $this->matchNone($rule, $row), + $rule instanceof Unequal => $this->matchUnequal($rule, $row), + $rule instanceof Unlike => $this->matchUnlike($rule, $row), + default => throw new InvalidArgumentException( + sprintf( 'Unable to match filter. Rule type %s is unknown', get_class($rule) - )); - } + ) + ), + }; } /**