From aa13553d5f0a9a7de5928074001a1cf96cd80aff Mon Sep 17 00:00:00 2001 From: Valentin Courdy Date: Fri, 19 Dec 2025 21:39:09 +0100 Subject: [PATCH 1/2] Remove implicitly nullable types See : https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated --- src/Rule/AbstractRule.php | 2 +- src/Rule/Alpha.php | 2 +- src/Rule/AlphaNumHyphen.php | 2 +- src/Rule/AlphaNumeric.php | 2 +- src/Rule/ArrayLength.php | 2 +- src/Rule/ArrayMaxLength.php | 2 +- src/Rule/ArrayMinLength.php | 2 +- src/Rule/Between.php | 2 +- src/Rule/Callback.php | 2 +- src/Rule/Date.php | 2 +- src/Rule/Email.php | 2 +- src/Rule/EmailDomain.php | 2 +- src/Rule/Equal.php | 2 +- src/Rule/File/Extension.php | 2 +- src/Rule/File/Image.php | 2 +- src/Rule/File/ImageHeight.php | 2 +- src/Rule/File/ImageRatio.php | 2 +- src/Rule/File/ImageWidth.php | 2 +- src/Rule/File/Size.php | 2 +- src/Rule/FullName.php | 2 +- src/Rule/GreaterThan.php | 2 +- src/Rule/InList.php | 2 +- src/Rule/Integer.php | 2 +- src/Rule/IpAddress.php | 2 +- src/Rule/Length.php | 2 +- src/Rule/LessThan.php | 2 +- src/Rule/Matching.php | 2 +- src/Rule/MaxLength.php | 2 +- src/Rule/MinLength.php | 2 +- src/Rule/NotEqual.php | 2 +- src/Rule/NotInList.php | 2 +- src/Rule/NotMatch.php | 2 +- src/Rule/NotRegex.php | 2 +- src/Rule/Number.php | 2 +- src/Rule/Regex.php | 2 +- src/Rule/Required.php | 2 +- src/Rule/RequiredWhen.php | 2 +- src/Rule/RequiredWith.php | 2 +- src/Rule/RequiredWithout.php | 2 +- src/Rule/Upload/Extension.php | 2 +- src/Rule/Upload/Image.php | 2 +- src/Rule/Upload/ImageHeight.php | 2 +- src/Rule/Upload/ImageRatio.php | 2 +- src/Rule/Upload/ImageWidth.php | 2 +- src/Rule/Upload/Required.php | 2 +- src/Rule/Upload/Size.php | 2 +- src/Rule/Url.php | 2 +- src/Rule/Website.php | 2 +- src/RuleFactory.php | 4 ++-- src/Validator.php | 8 ++++---- src/ValueValidator.php | 10 +++++----- tests/src/Rule/AbstractValidatorTest.php | 2 +- tests/src/RuleFactoryTest.php | 2 +- 53 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/Rule/AbstractRule.php b/src/Rule/AbstractRule.php index a61fd4d..8d8c9ba 100644 --- a/src/Rule/AbstractRule.php +++ b/src/Rule/AbstractRule.php @@ -172,7 +172,7 @@ public function getMessageTemplate(): string /** * Validates a value */ - abstract public function validate(mixed $value, string $valueIdentifier = null): bool; + abstract public function validate(mixed $value, ?string $valueIdentifier = null): bool; /** * Sets the error message prototype that will be used when diff --git a/src/Rule/Alpha.php b/src/Rule/Alpha.php index 76f216c..4113154 100755 --- a/src/Rule/Alpha.php +++ b/src/Rule/Alpha.php @@ -8,7 +8,7 @@ class Alpha extends AbstractRule const MESSAGE = 'This input can contain only letters'; const LABELED_MESSAGE = '{label} can contain only letters'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $this->success = (bool)ctype_alpha((string)str_replace(' ', '', (string)$value)); diff --git a/src/Rule/AlphaNumHyphen.php b/src/Rule/AlphaNumHyphen.php index a9a8423..b69b644 100755 --- a/src/Rule/AlphaNumHyphen.php +++ b/src/Rule/AlphaNumHyphen.php @@ -8,7 +8,7 @@ class AlphaNumHyphen extends AbstractRule const MESSAGE = 'This input must contain only letters, digits, spaces, hyphens and underscores'; const LABELED_MESSAGE = '{label} must contain only letters, digits, spaces, hyphens and underscores'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $this->success = (bool)ctype_alnum( diff --git a/src/Rule/AlphaNumeric.php b/src/Rule/AlphaNumeric.php index a8ef000..33aa4c0 100755 --- a/src/Rule/AlphaNumeric.php +++ b/src/Rule/AlphaNumeric.php @@ -9,7 +9,7 @@ class AlphaNumeric extends AbstractRule const LABELED_MESSAGE = '{label} must contain only letters and digits'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $this->success = (bool)ctype_alnum((string)str_replace(' ', '', $value)); diff --git a/src/Rule/ArrayLength.php b/src/Rule/ArrayLength.php index 5934a8f..5181bfa 100755 --- a/src/Rule/ArrayLength.php +++ b/src/Rule/ArrayLength.php @@ -16,7 +16,7 @@ class ArrayLength extends AbstractRule 1 => self::OPTION_MAX ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $maxValidator = new ArrayMaxLength(); diff --git a/src/Rule/ArrayMaxLength.php b/src/Rule/ArrayMaxLength.php index d4f7df9..a4f0d06 100755 --- a/src/Rule/ArrayMaxLength.php +++ b/src/Rule/ArrayMaxLength.php @@ -15,7 +15,7 @@ class ArrayMaxLength extends AbstractRule self::OPTION_MAX ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!isset($this->options['max'])) { diff --git a/src/Rule/ArrayMinLength.php b/src/Rule/ArrayMinLength.php index efb8495..7fa436e 100755 --- a/src/Rule/ArrayMinLength.php +++ b/src/Rule/ArrayMinLength.php @@ -14,7 +14,7 @@ class ArrayMinLength extends AbstractRule 0 => self::OPTION_MIN ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!isset($this->options['min'])) { diff --git a/src/Rule/Between.php b/src/Rule/Between.php index fd1b1cc..7301a5d 100755 --- a/src/Rule/Between.php +++ b/src/Rule/Between.php @@ -16,7 +16,7 @@ class Between extends AbstractRule 1 => self::OPTION_MAX ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $minValidator = new LessThan(); diff --git a/src/Rule/Callback.php b/src/Rule/Callback.php index 7b873f8..e1a798e 100755 --- a/src/Rule/Callback.php +++ b/src/Rule/Callback.php @@ -40,7 +40,7 @@ public function getUniqueId(): string return $uniqueId; } - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!isset($this->options['callback']) || !is_callable($this->options['callback'])) { diff --git a/src/Rule/Date.php b/src/Rule/Date.php index 303ff48..e1b8a0b 100644 --- a/src/Rule/Date.php +++ b/src/Rule/Date.php @@ -19,7 +19,7 @@ class Date extends AbstractRule 0 => self::OPTION_FORMAT ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $this->success = $value == date( diff --git a/src/Rule/Email.php b/src/Rule/Email.php index 77d7b43..a84d1b3 100755 --- a/src/Rule/Email.php +++ b/src/Rule/Email.php @@ -9,7 +9,7 @@ class Email extends AbstractRule const LABELED_MESSAGE = '{label} must be a valid email address'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $this->success = (filter_var((string)$value, FILTER_VALIDATE_EMAIL) !== false); diff --git a/src/Rule/EmailDomain.php b/src/Rule/EmailDomain.php index a7cf903..6b70b72 100755 --- a/src/Rule/EmailDomain.php +++ b/src/Rule/EmailDomain.php @@ -8,7 +8,7 @@ class EmailDomain extends AbstractRule const MESSAGE = 'This the email address does not belong to a valid domain'; const LABELED_MESSAGE = '{label} does not belong to a valid domain'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $value = (string)$value; $this->value = $value; diff --git a/src/Rule/Equal.php b/src/Rule/Equal.php index f6adc57..cd3a1da 100644 --- a/src/Rule/Equal.php +++ b/src/Rule/Equal.php @@ -14,7 +14,7 @@ class Equal extends AbstractRule 0 => self::OPTION_VALUE ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (isset($this->options[self::OPTION_VALUE])) { diff --git a/src/Rule/File/Extension.php b/src/Rule/File/Extension.php index 69c1c80..aefb3a6 100644 --- a/src/Rule/File/Extension.php +++ b/src/Rule/File/Extension.php @@ -31,7 +31,7 @@ public function setOption(string $name, mixed $value): static return parent::setOption($name, $value); } - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!file_exists($value)) { diff --git a/src/Rule/File/Image.php b/src/Rule/File/Image.php index 0454609..308abf8 100644 --- a/src/Rule/File/Image.php +++ b/src/Rule/File/Image.php @@ -45,7 +45,7 @@ public function setOption(string $name, mixed $value): static return parent::setOption($name, $value); } - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!file_exists($value)) { diff --git a/src/Rule/File/ImageHeight.php b/src/Rule/File/ImageHeight.php index 1675bfc..22351b6 100644 --- a/src/Rule/File/ImageHeight.php +++ b/src/Rule/File/ImageHeight.php @@ -19,7 +19,7 @@ class ImageHeight extends AbstractRule self::OPTION_MIN => 0, ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!file_exists($value)) { diff --git a/src/Rule/File/ImageRatio.php b/src/Rule/File/ImageRatio.php index 706b865..e7da915 100644 --- a/src/Rule/File/ImageRatio.php +++ b/src/Rule/File/ImageRatio.php @@ -37,7 +37,7 @@ protected function normalizeRatio(mixed $ratio): float return 0; } - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $ratio = RuleHelper::normalizeImageRatio($this->options[self::OPTION_RATIO]); diff --git a/src/Rule/File/ImageWidth.php b/src/Rule/File/ImageWidth.php index b44b592..f0d1b70 100644 --- a/src/Rule/File/ImageWidth.php +++ b/src/Rule/File/ImageWidth.php @@ -19,7 +19,7 @@ class ImageWidth extends AbstractRule self::OPTION_MIN => 0, ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!file_exists($value)) { diff --git a/src/Rule/File/Size.php b/src/Rule/File/Size.php index f53bd83..e322df2 100644 --- a/src/Rule/File/Size.php +++ b/src/Rule/File/Size.php @@ -18,7 +18,7 @@ class Size extends AbstractRule self::OPTION_SIZE => '2M' ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!file_exists($value)) { diff --git a/src/Rule/FullName.php b/src/Rule/FullName.php index b93905d..b947729 100755 --- a/src/Rule/FullName.php +++ b/src/Rule/FullName.php @@ -11,7 +11,7 @@ class FullName extends AbstractRule /** * This is not going to work with Asian names, http://en.wikipedia.org/wiki/Chinese_name. */ - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; diff --git a/src/Rule/GreaterThan.php b/src/Rule/GreaterThan.php index 62b77ab..f43e740 100755 --- a/src/Rule/GreaterThan.php +++ b/src/Rule/GreaterThan.php @@ -20,7 +20,7 @@ class GreaterThan extends AbstractRule 1 => self::OPTION_INCLUSIVE ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!isset($this->options['min'])) { diff --git a/src/Rule/InList.php b/src/Rule/InList.php index 6fe8772..9faee0d 100755 --- a/src/Rule/InList.php +++ b/src/Rule/InList.php @@ -14,7 +14,7 @@ class InList extends AbstractRule 0 => self::OPTION_LIST ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!isset($this->options['list'])) { diff --git a/src/Rule/Integer.php b/src/Rule/Integer.php index 58dc2b5..fe0699c 100644 --- a/src/Rule/Integer.php +++ b/src/Rule/Integer.php @@ -8,7 +8,7 @@ class Integer extends AbstractRule const MESSAGE = 'This input must be an integer number'; const LABELED_MESSAGE = '{label} must be an integer number'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $this->success = (bool)filter_var($value, FILTER_VALIDATE_INT) || $value === '0'; diff --git a/src/Rule/IpAddress.php b/src/Rule/IpAddress.php index 648dea6..48e6de5 100755 --- a/src/Rule/IpAddress.php +++ b/src/Rule/IpAddress.php @@ -8,7 +8,7 @@ class IpAddress extends AbstractRule const MESSAGE = 'This input is not a valid IP address'; const LABELED_MESSAGE = '{label} is not a valid IP address'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; // Do not allow private and reserved range IPs diff --git a/src/Rule/Length.php b/src/Rule/Length.php index b963f9c..e84a5ea 100755 --- a/src/Rule/Length.php +++ b/src/Rule/Length.php @@ -18,7 +18,7 @@ class Length extends AbstractRule 2 => self::OPTION_ENCODING ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $maxValidator = new MaxLength(); diff --git a/src/Rule/LessThan.php b/src/Rule/LessThan.php index 08d14aa..90be4c9 100755 --- a/src/Rule/LessThan.php +++ b/src/Rule/LessThan.php @@ -20,7 +20,7 @@ class LessThan extends AbstractRule 1 => self::OPTION_INCLUSIVE ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!isset($this->options['max'])) { diff --git a/src/Rule/Matching.php b/src/Rule/Matching.php index 4df3900..26f7015 100644 --- a/src/Rule/Matching.php +++ b/src/Rule/Matching.php @@ -14,7 +14,7 @@ class Matching extends AbstractRule 0 => self::OPTION_ITEM ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (isset($this->options[self::OPTION_ITEM])) { diff --git a/src/Rule/MaxLength.php b/src/Rule/MaxLength.php index 90ecbc6..f3452ed 100755 --- a/src/Rule/MaxLength.php +++ b/src/Rule/MaxLength.php @@ -16,7 +16,7 @@ class MaxLength extends AbstractStringRule 1 => self::OPTION_ENCODING ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!isset($this->options['max'])) { diff --git a/src/Rule/MinLength.php b/src/Rule/MinLength.php index 9c58134..03293de 100755 --- a/src/Rule/MinLength.php +++ b/src/Rule/MinLength.php @@ -16,7 +16,7 @@ class MinLength extends AbstractStringRule 1 => self::OPTION_ENCODING ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!isset($this->options['min'])) { diff --git a/src/Rule/NotEqual.php b/src/Rule/NotEqual.php index 436898e..f3f80e5 100644 --- a/src/Rule/NotEqual.php +++ b/src/Rule/NotEqual.php @@ -8,7 +8,7 @@ class NotEqual extends Equal const MESSAGE = 'This input is equal to {value}'; const LABELED_MESSAGE = '{label} is equal to {value}'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { parent::validate($value, $valueIdentifier); $this->success = !$this->success; diff --git a/src/Rule/NotInList.php b/src/Rule/NotInList.php index 165b5c1..876cc5f 100755 --- a/src/Rule/NotInList.php +++ b/src/Rule/NotInList.php @@ -14,7 +14,7 @@ class NotInList extends InList 0 => self::OPTION_LIST ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!isset($this->options['list'])) { diff --git a/src/Rule/NotMatch.php b/src/Rule/NotMatch.php index 207ef71..ad2f6ae 100644 --- a/src/Rule/NotMatch.php +++ b/src/Rule/NotMatch.php @@ -8,7 +8,7 @@ class NotMatch extends Matching const MESSAGE = 'This input does match {item}'; const LABELED_MESSAGE = '{label} does match {item}'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { parent::validate($value, $valueIdentifier); $this->success = !$this->success; diff --git a/src/Rule/NotRegex.php b/src/Rule/NotRegex.php index 6197e65..019a726 100755 --- a/src/Rule/NotRegex.php +++ b/src/Rule/NotRegex.php @@ -8,7 +8,7 @@ class NotRegex extends Regex const MESSAGE = 'This input should not match the regular expression {pattern}'; const LABELED_MESSAGE = '{label} Tshould not match the regular expression {pattern}'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { parent::validate($value, $valueIdentifier); $this->success = !$this->success; diff --git a/src/Rule/Number.php b/src/Rule/Number.php index 04b7dcf..7505302 100644 --- a/src/Rule/Number.php +++ b/src/Rule/Number.php @@ -8,7 +8,7 @@ class Number extends AbstractRule const MESSAGE = 'This input must be a number'; const LABELED_MESSAGE = '{label} must be a number'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $this->success = (bool)filter_var($value, FILTER_VALIDATE_FLOAT) || (string)$value === '0'; diff --git a/src/Rule/Regex.php b/src/Rule/Regex.php index eb4d9c9..b061edd 100755 --- a/src/Rule/Regex.php +++ b/src/Rule/Regex.php @@ -14,7 +14,7 @@ class Regex extends AbstractRule 0 => self::OPTION_PATTERN ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (isset($this->options['pattern'])) { diff --git a/src/Rule/Required.php b/src/Rule/Required.php index e84f07e..6c4f386 100755 --- a/src/Rule/Required.php +++ b/src/Rule/Required.php @@ -8,7 +8,7 @@ class Required extends AbstractRule const MESSAGE = 'This field is required'; const LABELED_MESSAGE = '{label} is required'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $this->success = ($value !== null && $value !== ''); diff --git a/src/Rule/RequiredWhen.php b/src/Rule/RequiredWhen.php index 58a8c93..b4783ba 100644 --- a/src/Rule/RequiredWhen.php +++ b/src/Rule/RequiredWhen.php @@ -43,7 +43,7 @@ public function getItemRule(): ?AbstractRule return $rule; // @phpstan-ignore-line } - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; diff --git a/src/Rule/RequiredWith.php b/src/Rule/RequiredWith.php index bb5cd27..67685c2 100644 --- a/src/Rule/RequiredWith.php +++ b/src/Rule/RequiredWith.php @@ -14,7 +14,7 @@ class RequiredWith extends Required 0 => self::OPTION_ITEM ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; diff --git a/src/Rule/RequiredWithout.php b/src/Rule/RequiredWithout.php index 384e0b6..03a3cf2 100644 --- a/src/Rule/RequiredWithout.php +++ b/src/Rule/RequiredWithout.php @@ -14,7 +14,7 @@ class RequiredWithout extends Required 0 => self::OPTION_ITEM ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; diff --git a/src/Rule/Upload/Extension.php b/src/Rule/Upload/Extension.php index 34b99ce..2195c1c 100644 --- a/src/Rule/Upload/Extension.php +++ b/src/Rule/Upload/Extension.php @@ -31,7 +31,7 @@ public function setOption(string $name, mixed $value): static return parent::setOption($name, $value); } - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!is_array($value) || !isset($value['tmp_name'])) { diff --git a/src/Rule/Upload/Image.php b/src/Rule/Upload/Image.php index 99ae24c..65753d7 100644 --- a/src/Rule/Upload/Image.php +++ b/src/Rule/Upload/Image.php @@ -45,7 +45,7 @@ public function setOption(string $name, mixed $value): static return parent::setOption($name, $value); } - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!is_array($value) || !isset($value['tmp_name'])) { diff --git a/src/Rule/Upload/ImageHeight.php b/src/Rule/Upload/ImageHeight.php index ba28835..9368e80 100644 --- a/src/Rule/Upload/ImageHeight.php +++ b/src/Rule/Upload/ImageHeight.php @@ -19,7 +19,7 @@ class ImageHeight extends AbstractRule self::OPTION_MIN => 0, ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!is_array($value) || !isset($value['tmp_name'])) { diff --git a/src/Rule/Upload/ImageRatio.php b/src/Rule/Upload/ImageRatio.php index 865c260..9e271b8 100644 --- a/src/Rule/Upload/ImageRatio.php +++ b/src/Rule/Upload/ImageRatio.php @@ -23,7 +23,7 @@ class ImageRatio extends AbstractRule self::OPTION_ERROR_MARGIN => 0, ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $ratio = RuleHelper::normalizeImageRatio($this->options[self::OPTION_RATIO]); diff --git a/src/Rule/Upload/ImageWidth.php b/src/Rule/Upload/ImageWidth.php index 753d495..8987520 100644 --- a/src/Rule/Upload/ImageWidth.php +++ b/src/Rule/Upload/ImageWidth.php @@ -19,7 +19,7 @@ class ImageWidth extends AbstractRule self::OPTION_MIN => 0, ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!is_array($value) || !isset($value['tmp_name'])) { diff --git a/src/Rule/Upload/Required.php b/src/Rule/Upload/Required.php index 253b820..f01ab90 100644 --- a/src/Rule/Upload/Required.php +++ b/src/Rule/Upload/Required.php @@ -17,7 +17,7 @@ class Required extends AbstractRule const LABELED_MESSAGE = '{label} is required'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!is_array($value) || !isset($value['tmp_name']) || diff --git a/src/Rule/Upload/Size.php b/src/Rule/Upload/Size.php index b9fc0a6..041066c 100644 --- a/src/Rule/Upload/Size.php +++ b/src/Rule/Upload/Size.php @@ -18,7 +18,7 @@ class Size extends AbstractRule self::OPTION_SIZE => '2M' ]; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; if (!is_array($value) || !isset($value['tmp_name'])) { diff --git a/src/Rule/Url.php b/src/Rule/Url.php index ce9bd8f..2907b60 100755 --- a/src/Rule/Url.php +++ b/src/Rule/Url.php @@ -8,7 +8,7 @@ class Url extends AbstractRule const MESSAGE = 'This input is not a valid URL'; const LABELED_MESSAGE = '{label} is not a valid URL'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $this->success = (bool)filter_var($value, FILTER_VALIDATE_URL); diff --git a/src/Rule/Website.php b/src/Rule/Website.php index 591ac86..8245c25 100755 --- a/src/Rule/Website.php +++ b/src/Rule/Website.php @@ -10,7 +10,7 @@ class Website extends AbstractRule const MESSAGE = 'This input must be a valid website address'; const LABELED_MESSAGE = '{label} must be a valid website address'; - public function validate(mixed $value, string $valueIdentifier = null): bool + public function validate(mixed $value, ?string $valueIdentifier = null): bool { $this->value = $value; $this->success = (substr($value, 0, 2) == '//') diff --git a/src/RuleFactory.php b/src/RuleFactory.php index 2cb5360..19bb260 100644 --- a/src/RuleFactory.php +++ b/src/RuleFactory.php @@ -136,7 +136,7 @@ public function register(string $name, string $class, string $errorMessage = '', * @return AbstractRule * @throws \InvalidArgumentException */ - public function createRule(mixed $name, mixed $options = null, string $messageTemplate = null, string $label = null): AbstractRule + public function createRule(mixed $name, mixed $options = null, ?string $messageTemplate = null, ?string $label = null): AbstractRule { $validator = $this->construcRuleByNameAndOptions($name, $options); @@ -160,7 +160,7 @@ public function createRule(mixed $name, mixed $options = null, string $messageTe * * @return $this */ - public function setMessages(string $rule, string $messageWithoutLabel = null, string $messageWithLabel = null) + public function setMessages(string $rule, ?string $messageWithoutLabel = null, ?string $messageWithLabel = null) { if ($messageWithoutLabel) { $this->errorMessages[$rule] = $messageWithoutLabel; diff --git a/src/Validator.php b/src/Validator.php index 6441a01..fdbc30f 100755 --- a/src/Validator.php +++ b/src/Validator.php @@ -123,7 +123,7 @@ class Validator implements ValidatorInterface */ protected ?WrapperInterface $dataWrapper = null; - public function __construct(RuleFactory $ruleFactory = null, ErrorMessage $errorMessagePrototype = null) + public function __construct(?RuleFactory $ruleFactory = null, ?ErrorMessage $errorMessagePrototype = null) { if (!$ruleFactory) { $ruleFactory = new RuleFactory(); @@ -296,7 +296,7 @@ public function validate(mixed $data = null): bool return count($this->messages) === 0; } - public function addMessage(string $item, string|ErrorMessage $message = null): static + public function addMessage(string $item, string|ErrorMessage|null $message = null): static { if ($message === null || $message === '') { return $this; @@ -312,7 +312,7 @@ public function addMessage(string $item, string|ErrorMessage $message = null): s /** * Clears the messages of an item */ - public function clearMessages(string $item = null): static + public function clearMessages(?string $item = null): static { if (is_string($item)) { if (array_key_exists($item, $this->messages)) { @@ -332,7 +332,7 @@ public function clearMessages(string $item = null): static * @return array */ public - function getMessages(string $item = null): array + function getMessages(?string $item = null): array { if (is_string($item)) { return array_key_exists($item, $this->messages) ? $this->messages[$item] : []; diff --git a/src/ValueValidator.php b/src/ValueValidator.php index dde50e1..360afdf 100644 --- a/src/ValueValidator.php +++ b/src/ValueValidator.php @@ -25,8 +25,8 @@ class ValueValidator protected string $label; public function __construct( - RuleFactory $ruleFactory = null, - ErrorMessage $errorMessagePrototype = null, + ?RuleFactory $ruleFactory = null, + ?ErrorMessage $errorMessagePrototype = null, string $label = '' ) { @@ -80,7 +80,7 @@ public function setLabel(string $label = ''): self * $validator->add('minlength(min=2)({label} should have at least {min} characters)(Field label)'); * */ - public function add(mixed $name, $options = null, string $messageTemplate = null, string $label = null): self + public function add(mixed $name, $options = null, ?string $messageTemplate = null, ?string $label = null): self { if (is_array($name)) { return $this->addMultiple($name); @@ -148,7 +148,7 @@ public function remove($name = true, $options = null): self return $this; } $validator = $this->ruleFactory->createRule($name, $options); - $this->rules->detach($validator); + $this->rules->offsetUnset($validator); return $this; } @@ -210,7 +210,7 @@ protected function parseRule($ruleAsString): array /** * @param DataWrapper\WrapperInterface|null $context */ - public function validate(mixed $value, string $valueIdentifier = '', DataWrapper\WrapperInterface $context = null): bool + public function validate(mixed $value, string $valueIdentifier = '', ?DataWrapper\WrapperInterface $context = null): bool { $this->messages = []; $isRequired = false; diff --git a/tests/src/Rule/AbstractValidatorTest.php b/tests/src/Rule/AbstractValidatorTest.php index 4d84398..3f1908f 100755 --- a/tests/src/Rule/AbstractValidatorTest.php +++ b/tests/src/Rule/AbstractValidatorTest.php @@ -4,7 +4,7 @@ use \Sirius\Validation\Rule\AbstractRule; class FakeRule extends AbstractRule { - function validate($value, string $valueIdentifier = null): bool + function validate($value, ?string $valueIdentifier = null): bool { $this->value = $value; $this->success = (bool)$value && isset($this->context) && $this->context->getItemValue('key'); diff --git a/tests/src/RuleFactoryTest.php b/tests/src/RuleFactoryTest.php index 2f4b03c..1822b86 100644 --- a/tests/src/RuleFactoryTest.php +++ b/tests/src/RuleFactoryTest.php @@ -6,7 +6,7 @@ class TestingCustomRule extends AbstractRule { - function validate($value, string $valueIdentifier = null): bool + function validate($value, ?string $valueIdentifier = null): bool { return (bool)($value % 2); } From cbfa83a098a5955ba34cdbb6284533d9edd7edc8 Mon Sep 17 00:00:00 2001 From: Valentin Courdy Date: Fri, 19 Dec 2025 21:40:42 +0100 Subject: [PATCH 2/2] Update deprecated usage of SplObjectStorage methods --- src/RuleCollection.php | 8 ++++---- tests/src/RuleCollectionTest.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/RuleCollection.php b/src/RuleCollection.php index a7109ec..f2d523a 100644 --- a/src/RuleCollection.php +++ b/src/RuleCollection.php @@ -13,24 +13,24 @@ class RuleCollection extends SplObjectStorage #[ReturnTypeWillChange] public function attach(mixed $rule, mixed $data = null): void { - if ($this->contains($rule)) { + if ($this->offsetExists($rule)) { return; } if ($rule instanceof Rule\Required) { $rules = []; foreach ($this as $r) { $rules[] = $r; - $this->detach($r); + $this->offsetUnset($r); } array_unshift($rules, $rule); foreach ($rules as $r) { - parent::attach($r); + $this->offsetSet($r); } return; } - parent::attach($rule); + $this->offsetSet($rule); } #[ReturnTypeWillChange] diff --git a/tests/src/RuleCollectionTest.php b/tests/src/RuleCollectionTest.php index 8019c44..87f240a 100644 --- a/tests/src/RuleCollectionTest.php +++ b/tests/src/RuleCollectionTest.php @@ -12,7 +12,7 @@ $this->collection->attach(new Required()); expect(count($this->collection))->toEqual(1); - $this->collection->detach(new Required()); + $this->collection->offsetUnset(new Required()); expect(count($this->collection))->toEqual(0); });