diff --git a/CHANGELOG.md b/CHANGELOG.md index 8339d2dd3..74908d9d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,16 +28,6 @@ - Chg #613: Change type of `$escape` argument in `Error::getValuePath()` from `bool|string|null` to `string|null` (@arogachev) -## 1.3.0 April 04, 2024 - -- New #665: Add methods `addErrorWithFormatOnly()` and `addErrorWithoutPostProcessing()` to `Result` object (@vjik) -- New #670, #677, #680: Add `Image` validation rule (@vjik, @arogachev) -- New #678: Add `Date`, `DateTime` and `Time` validation rules (@vjik) -- Enh #668: Clarify psalm types in `Result` (@vjik) -## 1.4.1 under development - -- no changes in this release. - ## 1.4.0 May 22, 2024 - New #649: Add `getFirstErrorMessagesIndexedByPath()` and `getFirstErrorMessagesIndexedByAttribute()` methods to diff --git a/composer.json b/composer.json index 7020afe30..5af160c36 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "maglnet/composer-require-checker": "^4.3", "phpbench/phpbench": "^1.2", "phpunit/phpunit": "^9.5", - "rector/rector": "^1.0", + "rector/rector": "1.0.*", "roave/infection-static-analysis-plugin": "^1.25", "spatie/phpunit-watcher": "^1.23", "vimeo/psalm": "^5.22", diff --git a/docs/guide/en/creating-custom-rules.md b/docs/guide/en/creating-custom-rules.md index 54611e156..a1f787224 100644 --- a/docs/guide/en/creating-custom-rules.md +++ b/docs/guide/en/creating-custom-rules.md @@ -379,7 +379,7 @@ final class YamlHandler implements RuleHandlerInterface > **Note:** Using [yaml_parse] additionally requires `yaml` PHP extension. > **Note:** Processing untrusted user input with `yaml_parse()` can be dangerous with certain settings. Please refer to -> [yaml_parse] docs for more details. +> [`yaml_parse()` docs](https://www.php.net/manual/en/function.yaml-parse.php) for more details. ### Wrapping validation diff --git a/messages/ru/yii-validator.php b/messages/ru/yii-validator.php index 9f3080850..4e9ba1623 100644 --- a/messages/ru/yii-validator.php +++ b/messages/ru/yii-validator.php @@ -63,7 +63,10 @@ '{Attribute} must be an IP address with specified subnet.' => '{Attribute} должен быть IP адресом с подсетью.', '{Attribute} must not be a subnet.' => '{Attribute} не должно быть подсетью.', '{Attribute} is not in the allowed range.' => '{Attribute} не входит в список разрешенных диапазонов адресов.', - /** @see Integer */ + /** + * @see IntegerType + * @see Integer + */ '{Attribute} must be an integer.' => '{Attribute} должно быть целым числом.', /** @see Json */ '{Attribute} is not JSON.' => '{Attribute} не является строкой JSON.', diff --git a/src/Rule/AnyRule.php b/src/Rule/AnyRule.php index 5678b2d99..a27a222ae 100644 --- a/src/Rule/AnyRule.php +++ b/src/Rule/AnyRule.php @@ -8,12 +8,12 @@ use Closure; use JetBrains\PhpStorm\ArrayShape; use Yiisoft\Validator\AfterInitAttributeEventInterface; +use Yiisoft\Validator\DumpedRuleInterface; use Yiisoft\Validator\Helper\RulesNormalizer; use Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait; use Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait; use Yiisoft\Validator\Rule\Trait\WhenTrait; use Yiisoft\Validator\Helper\RulesDumper; -use Yiisoft\Validator\RuleWithOptionsInterface; use Yiisoft\Validator\SkipOnEmptyInterface; use Yiisoft\Validator\SkipOnErrorInterface; use Yiisoft\Validator\ValidatorInterface; @@ -44,7 +44,7 @@ */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] final class AnyRule implements - RuleWithOptionsInterface, + DumpedRuleInterface, SkipOnEmptyInterface, SkipOnErrorInterface, WhenInterface, @@ -83,16 +83,17 @@ final class AnyRule implements public function __construct( iterable $rules, private string $message = 'At least one of the inner rules must pass the validation.', - private mixed $skipOnEmpty = null, + bool|callable|null $skipOnEmpty = null, private bool $skipOnError = false, private Closure|null $when = null, ) { $this->rules = RulesNormalizer::normalizeList($rules); + $this->skipOnEmpty = $skipOnEmpty; } public function getName(): string { - return 'any'; + return self::class; } /** diff --git a/src/Rule/AnyRuleHandler.php b/src/Rule/AnyRuleHandler.php index d505e12fe..287ced806 100644 --- a/src/Rule/AnyRuleHandler.php +++ b/src/Rule/AnyRuleHandler.php @@ -7,6 +7,7 @@ use Yiisoft\Validator\Exception\UnexpectedRuleException; use Yiisoft\Validator\Result; use Yiisoft\Validator\RuleHandlerInterface; +use Yiisoft\Validator\RuleInterface; use Yiisoft\Validator\ValidationContext; /** @@ -15,7 +16,7 @@ */ final class AnyRuleHandler implements RuleHandlerInterface { - public function validate(mixed $value, object $rule, ValidationContext $context): Result + public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result { if (!$rule instanceof AnyRule) { throw new UnexpectedRuleException(AnyRule::class, $rule); diff --git a/src/Rule/CompareHandler.php b/src/Rule/CompareHandler.php index 4a3c59b0f..1b7c239e7 100644 --- a/src/Rule/CompareHandler.php +++ b/src/Rule/CompareHandler.php @@ -84,8 +84,6 @@ public function validate(mixed $value, RuleInterface $rule, ValidationContext $c * * @psalm-param CompareType::ORIGINAL | CompareType::STRING | CompareType::NUMBER $type * - * @param mixed $value The validated value. - * * @return bool `true` if value is correct and `false` otherwise. */ private function isInputCorrect(string $type, mixed $value): bool @@ -97,8 +95,6 @@ private function isInputCorrect(string $type, mixed $value): bool * Checks whether the validated value is allowed for types that require type casting - {@see CompareType::NUMBER} * and {@see CompareType::STRING}. * - * @param mixed $value The Validated value. - * * @return bool `true` if value is allowed and `false` otherwise. */ private function isValueAllowedForTypeCasting(mixed $value): bool @@ -112,8 +108,6 @@ private function isValueAllowedForTypeCasting(mixed $value): bool /** * Gets representation of the value for using with error parameter. * - * @param mixed $value The validated value. - * * @return scalar|null Formatted value. */ private function getFormattedValue(mixed $value): int|float|string|bool|null @@ -141,9 +135,6 @@ private function getFormattedValue(mixed $value): int|float|string|bool|null * * @psalm-param CompareType::ORIGINAL | CompareType::STRING | CompareType::NUMBER $type * - * @param mixed $value The validated value. - * @param mixed $targetValue "Target" value set in rule options. - * * @return bool Whether the result of comparison using the specified operator is true. */ private function compareValues(string $type, string $operator, mixed $value, mixed $targetValue): bool @@ -179,8 +170,6 @@ private function compareValues(string $type, string $operator, mixed $value, mix * * @psalm-param CompareType::ORIGINAL | CompareType::STRING | CompareType::NUMBER $type * - * @param mixed $value The validated value. - * @param mixed $targetValue "Target" value set in rule options. * @param bool $strict Whether the values must be equal (when set to `false`, default) / strictly equal (when set to * `true`). * @@ -228,8 +217,6 @@ private function checkFloatsAreEqual(float $value, float $targetValue): bool * * @psalm-param CompareType::ORIGINAL | CompareType::STRING | CompareType::NUMBER $type * - * @param mixed $value One of the compared values. Both validated and target value can be used. - * * @return mixed Normalized value ready for comparison. */ private function normalizeValue(string $type, mixed $value): mixed @@ -244,9 +231,6 @@ private function normalizeValue(string $type, mixed $value): mixed /** * Normalizes number that might be stored in a different type to float number. * - * @param mixed $number Raw number. Can be within an object implementing {@see Stringable} / - * {@see DateTimeInterface} or other primitive type, such as `int`, `float`, `string`. - * * @return float Float number ready for comparison. */ private function normalizeNumber(mixed $number): float @@ -263,9 +247,6 @@ private function normalizeNumber(mixed $number): float /** * Normalizes string that might be stored in a different type to simple string. * - * @param mixed $string Raw string. Can be within an object implementing {@see DateTimeInterface} or other primitive - * type, such as `int`, `float`, `string`. - * * @return string String ready for comparison. */ private function normalizeString(mixed $string): string diff --git a/src/Rule/Type/BooleanType.php b/src/Rule/Type/BooleanType.php index 449a2a36f..a51a45a97 100644 --- a/src/Rule/Type/BooleanType.php +++ b/src/Rule/Type/BooleanType.php @@ -6,10 +6,10 @@ use Attribute; use Closure; +use Yiisoft\Validator\DumpedRuleInterface; use Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait; use Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait; use Yiisoft\Validator\Rule\Trait\WhenTrait; -use Yiisoft\Validator\RuleWithOptionsInterface; use Yiisoft\Validator\SkipOnEmptyInterface; use Yiisoft\Validator\SkipOnErrorInterface; use Yiisoft\Validator\WhenInterface; @@ -26,7 +26,7 @@ * @psalm-import-type WhenType from WhenInterface */ #[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] -final class BooleanType implements RuleWithOptionsInterface, SkipOnEmptyInterface, SkipOnErrorInterface, WhenInterface +final class BooleanType implements DumpedRuleInterface, SkipOnEmptyInterface, SkipOnErrorInterface, WhenInterface { use SkipOnEmptyTrait; use SkipOnErrorTrait; @@ -51,15 +51,16 @@ final class BooleanType implements RuleWithOptionsInterface, SkipOnEmptyInterfac */ public function __construct( private string $message = 'Value must be a boolean.', - private mixed $skipOnEmpty = null, + bool|callable|null $skipOnEmpty = null, private bool $skipOnError = false, private Closure|null $when = null, ) { + $this->skipOnEmpty = $skipOnEmpty; } public function getName(): string { - return 'booleanType'; + return self::class; } /** diff --git a/src/Rule/Type/BooleanTypeHandler.php b/src/Rule/Type/BooleanTypeHandler.php index e37d244ce..907cbf2d7 100644 --- a/src/Rule/Type/BooleanTypeHandler.php +++ b/src/Rule/Type/BooleanTypeHandler.php @@ -7,6 +7,7 @@ use Yiisoft\Validator\Exception\UnexpectedRuleException; use Yiisoft\Validator\Result; use Yiisoft\Validator\RuleHandlerInterface; +use Yiisoft\Validator\RuleInterface; use Yiisoft\Validator\ValidationContext; use function is_bool; @@ -17,7 +18,7 @@ */ final class BooleanTypeHandler implements RuleHandlerInterface { - public function validate(mixed $value, object $rule, ValidationContext $context): Result + public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result { if (!$rule instanceof BooleanType) { throw new UnexpectedRuleException(BooleanType::class, $rule); diff --git a/src/Rule/Type/FloatType.php b/src/Rule/Type/FloatType.php index f6cd65370..73cc5df4a 100644 --- a/src/Rule/Type/FloatType.php +++ b/src/Rule/Type/FloatType.php @@ -6,10 +6,10 @@ use Attribute; use Closure; +use Yiisoft\Validator\DumpedRuleInterface; use Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait; use Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait; use Yiisoft\Validator\Rule\Trait\WhenTrait; -use Yiisoft\Validator\RuleWithOptionsInterface; use Yiisoft\Validator\SkipOnEmptyInterface; use Yiisoft\Validator\SkipOnErrorInterface; use Yiisoft\Validator\WhenInterface; @@ -25,7 +25,7 @@ * @psalm-import-type WhenType from WhenInterface */ #[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] -final class FloatType implements RuleWithOptionsInterface, SkipOnEmptyInterface, SkipOnErrorInterface, WhenInterface +final class FloatType implements DumpedRuleInterface, SkipOnEmptyInterface, SkipOnErrorInterface, WhenInterface { use SkipOnEmptyTrait; use SkipOnErrorTrait; @@ -50,15 +50,16 @@ final class FloatType implements RuleWithOptionsInterface, SkipOnEmptyInterface, */ public function __construct( private string $message = 'Value must be a float.', - private mixed $skipOnEmpty = null, + bool|callable|null $skipOnEmpty = null, private bool $skipOnError = false, private Closure|null $when = null, ) { + $this->skipOnEmpty = $skipOnEmpty; } public function getName(): string { - return 'floatType'; + return self::class; } /** diff --git a/src/Rule/Type/FloatTypeHandler.php b/src/Rule/Type/FloatTypeHandler.php index 4cf768ab8..db0f5df62 100644 --- a/src/Rule/Type/FloatTypeHandler.php +++ b/src/Rule/Type/FloatTypeHandler.php @@ -7,6 +7,7 @@ use Yiisoft\Validator\Exception\UnexpectedRuleException; use Yiisoft\Validator\Result; use Yiisoft\Validator\RuleHandlerInterface; +use Yiisoft\Validator\RuleInterface; use Yiisoft\Validator\ValidationContext; use function is_float; @@ -17,7 +18,7 @@ */ final class FloatTypeHandler implements RuleHandlerInterface { - public function validate(mixed $value, object $rule, ValidationContext $context): Result + public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result { if (!$rule instanceof FloatType) { throw new UnexpectedRuleException(FloatType::class, $rule); diff --git a/src/Rule/Type/IntegerType.php b/src/Rule/Type/IntegerType.php index 751a44625..c90b98de4 100644 --- a/src/Rule/Type/IntegerType.php +++ b/src/Rule/Type/IntegerType.php @@ -6,10 +6,10 @@ use Attribute; use Closure; +use Yiisoft\Validator\DumpedRuleInterface; use Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait; use Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait; use Yiisoft\Validator\Rule\Trait\WhenTrait; -use Yiisoft\Validator\RuleWithOptionsInterface; use Yiisoft\Validator\SkipOnEmptyInterface; use Yiisoft\Validator\SkipOnErrorInterface; use Yiisoft\Validator\WhenInterface; @@ -25,7 +25,7 @@ * @psalm-import-type WhenType from WhenInterface */ #[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] -final class IntegerType implements RuleWithOptionsInterface, SkipOnEmptyInterface, SkipOnErrorInterface, WhenInterface +final class IntegerType implements DumpedRuleInterface, SkipOnEmptyInterface, SkipOnErrorInterface, WhenInterface { use SkipOnEmptyTrait; use SkipOnErrorTrait; @@ -50,15 +50,16 @@ final class IntegerType implements RuleWithOptionsInterface, SkipOnEmptyInterfac */ public function __construct( private string $message = 'Value must be an integer.', - private mixed $skipOnEmpty = null, + bool|callable|null $skipOnEmpty = null, private bool $skipOnError = false, private Closure|null $when = null, ) { + $this->skipOnEmpty = $skipOnEmpty; } public function getName(): string { - return 'integerType'; + return self::class; } /** diff --git a/src/Rule/Type/IntegerTypeHandler.php b/src/Rule/Type/IntegerTypeHandler.php index 025117eaa..db7412cb0 100644 --- a/src/Rule/Type/IntegerTypeHandler.php +++ b/src/Rule/Type/IntegerTypeHandler.php @@ -7,6 +7,7 @@ use Yiisoft\Validator\Exception\UnexpectedRuleException; use Yiisoft\Validator\Result; use Yiisoft\Validator\RuleHandlerInterface; +use Yiisoft\Validator\RuleInterface; use Yiisoft\Validator\ValidationContext; use function is_int; @@ -17,7 +18,7 @@ */ final class IntegerTypeHandler implements RuleHandlerInterface { - public function validate(mixed $value, object $rule, ValidationContext $context): Result + public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result { if (!$rule instanceof IntegerType) { throw new UnexpectedRuleException(IntegerType::class, $rule); diff --git a/src/Rule/Type/StringType.php b/src/Rule/Type/StringType.php index e615f1a36..65b7c48ae 100644 --- a/src/Rule/Type/StringType.php +++ b/src/Rule/Type/StringType.php @@ -6,10 +6,10 @@ use Attribute; use Closure; +use Yiisoft\Validator\DumpedRuleInterface; use Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait; use Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait; use Yiisoft\Validator\Rule\Trait\WhenTrait; -use Yiisoft\Validator\RuleWithOptionsInterface; use Yiisoft\Validator\SkipOnEmptyInterface; use Yiisoft\Validator\SkipOnErrorInterface; use Yiisoft\Validator\WhenInterface; @@ -24,7 +24,7 @@ * @psalm-import-type WhenType from WhenInterface */ #[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] -final class StringType implements RuleWithOptionsInterface, SkipOnEmptyInterface, SkipOnErrorInterface, WhenInterface +final class StringType implements DumpedRuleInterface, SkipOnEmptyInterface, SkipOnErrorInterface, WhenInterface { use SkipOnEmptyTrait; use SkipOnErrorTrait; @@ -49,15 +49,16 @@ final class StringType implements RuleWithOptionsInterface, SkipOnEmptyInterface */ public function __construct( private string $message = 'Value must be a string.', - private mixed $skipOnEmpty = null, + bool|callable|null $skipOnEmpty = null, private bool $skipOnError = false, private Closure|null $when = null, ) { + $this->skipOnEmpty = $skipOnEmpty; } public function getName(): string { - return 'stringType'; + return self::class; } /** diff --git a/src/Rule/Type/StringTypeHandler.php b/src/Rule/Type/StringTypeHandler.php index 3d398acbd..f0dd5891f 100644 --- a/src/Rule/Type/StringTypeHandler.php +++ b/src/Rule/Type/StringTypeHandler.php @@ -7,6 +7,7 @@ use Yiisoft\Validator\Exception\UnexpectedRuleException; use Yiisoft\Validator\Result; use Yiisoft\Validator\RuleHandlerInterface; +use Yiisoft\Validator\RuleInterface; use Yiisoft\Validator\ValidationContext; use function is_string; @@ -17,7 +18,7 @@ */ final class StringTypeHandler implements RuleHandlerInterface { - public function validate(mixed $value, object $rule, ValidationContext $context): Result + public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result { if (!$rule instanceof StringType) { throw new UnexpectedRuleException(StringType::class, $rule); diff --git a/src/Rule/UniqueIterable.php b/src/Rule/UniqueIterable.php index 926a92703..48c5488c6 100644 --- a/src/Rule/UniqueIterable.php +++ b/src/Rule/UniqueIterable.php @@ -7,10 +7,10 @@ use Attribute; use Closure; use JetBrains\PhpStorm\ArrayShape; +use Yiisoft\Validator\DumpedRuleInterface; use Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait; use Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait; use Yiisoft\Validator\Rule\Trait\WhenTrait; -use Yiisoft\Validator\RuleWithOptionsInterface; use Yiisoft\Validator\SkipOnEmptyInterface; use Yiisoft\Validator\SkipOnErrorInterface; use Yiisoft\Validator\WhenInterface; @@ -25,7 +25,7 @@ */ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] final class UniqueIterable implements - RuleWithOptionsInterface, + DumpedRuleInterface, SkipOnEmptyInterface, SkipOnErrorInterface, WhenInterface @@ -78,15 +78,16 @@ public function __construct( 'float, string, boolean and object implementing \Stringable or \DateTimeInterface.', private string $differentTypesMessage = 'All iterable items must have the same type.', private string $message = 'Every iterable\'s item must be unique.', - private mixed $skipOnEmpty = null, + bool|callable|null $skipOnEmpty = null, private bool $skipOnError = false, private Closure|null $when = null, ) { + $this->skipOnEmpty = $skipOnEmpty; } public function getName(): string { - return 'unique'; + return self::class; } /** diff --git a/src/Rule/UniqueIterableHandler.php b/src/Rule/UniqueIterableHandler.php index 4d96cdf48..55abf126f 100644 --- a/src/Rule/UniqueIterableHandler.php +++ b/src/Rule/UniqueIterableHandler.php @@ -9,6 +9,7 @@ use Yiisoft\Validator\Exception\UnexpectedRuleException; use Yiisoft\Validator\Result; use Yiisoft\Validator\RuleHandlerInterface; +use Yiisoft\Validator\RuleInterface; use Yiisoft\Validator\ValidationContext; use function count; @@ -19,7 +20,7 @@ */ final class UniqueIterableHandler implements RuleHandlerInterface { - public function validate(mixed $value, object $rule, ValidationContext $context): Result + public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result { if (!$rule instanceof UniqueIterable) { throw new UnexpectedRuleException(UniqueIterable::class, $rule); diff --git a/src/RuleHandlerInterface.php b/src/RuleHandlerInterface.php index c5f52ea4b..db338b71c 100644 --- a/src/RuleHandlerInterface.php +++ b/src/RuleHandlerInterface.php @@ -42,12 +42,10 @@ interface RuleHandlerInterface * } * ``` * - * @param mixed $value A validated value of any type. * @param RuleInterface $rule A rule instance containing configuration parameters. * @param ValidationContext $context A validation context instance. * * @return Result A validation result instance. - * * @internal Should never be called directly. Use {@see ValidatorInterface} instead. */ public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result; diff --git a/src/ValidationContext.php b/src/ValidationContext.php index 2159219da..430cf1d9d 100644 --- a/src/ValidationContext.php +++ b/src/ValidationContext.php @@ -89,11 +89,9 @@ public function __construct( * @param ValidatorInterface $validator A validator instance. * @param AttributeTranslatorInterface $attributeTranslator Attribute translator to use by default. If translator * is specified via {@see setAttributeTranslator()}, it will be used instead. - * @param mixed $rawData The raw validated data. * @param DataSetInterface $dataSet Global data set ({@see $globalDataSet}). * * @internal - * * @return $this The same instance of validation context. */ public function setContextDataOnce( @@ -137,15 +135,12 @@ public function setAttributeLabel(string|null $label): self /** * Validate data in current context. * - * @param mixed $data Data set to validate. If {@see RulesProviderInterface} instance provided and rules are - * not specified explicitly, they are read from the {@see RulesProviderInterface::getRules()}. * @param callable|iterable|object|string|null $rules Rules to apply. If specified, rules are not read from data set * even if it is an instance of {@see RulesProviderInterface}. * * @psalm-param RawRules|null $rules * * @throws RuntimeException If validator is not set in validation context. - * * @return Result Validation result. */ public function validate(mixed $data, callable|iterable|object|string|null $rules = null): Result @@ -285,10 +280,8 @@ public function setAttribute(?string $attribute): self * Get named parameter. * * @param string $name Parameter name. - * @param mixed $default Default value to return in case parameter with a given name does not exist. * * @return mixed Parameter value. - * * @see ArrayHelper::getValue() */ public function getParameter(string $name, mixed $default = null): mixed @@ -300,7 +293,6 @@ public function getParameter(string $name, mixed $default = null): mixed * Set parameter value. * * @param string $name Parameter name. - * @param mixed $value Parameter value. * * @return $this The same instance of validation context. */ diff --git a/src/Validator.php b/src/Validator.php index 7534d833d..612341400 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -183,13 +183,11 @@ public function validate( * Validates input of any type according to normalized rules and validation context. Aggregates errors from all the * rules to a one unified result. * - * @param mixed $value The validated value of any type. * @param iterable $rules Normalized rules ({@see RuleInterface} that can be iterated). * * @psalm-param iterable $rules * * @param ValidationContext $context Validation context. - * * @return Result The result of validation. */ private function validateInternal(mixed $value, iterable $rules, ValidationContext $context): Result @@ -245,9 +243,7 @@ private function validateInternal(mixed $value, iterable $rules, ValidationConte * - "when" callable returned `false` {@see WhenInterface}. * * @param RuleInterface $rule A rule instance. - * @param mixed $value The validated value of any type. * @param ValidationContext $context Validation context. - * * @return bool Whether to skip validation for this rule - `true` means skip and `false` to not skip. */ private function shouldSkipRule(RuleInterface $rule, mixed $value, ValidationContext $context): bool diff --git a/tests/Rule/AnyRuleTest.php b/tests/Rule/AnyRuleTest.php index 2f9bdc0fe..c36211144 100644 --- a/tests/Rule/AnyRuleTest.php +++ b/tests/Rule/AnyRuleTest.php @@ -26,7 +26,7 @@ final class AnyRuleTest extends RuleTestCase public function testGetName(): void { $rule = new AnyRule([new IntegerType(), new FloatType()]); - $this->assertSame('any', $rule->getName()); + $this->assertSame(AnyRule::class, $rule->getName()); } public function dataOptions(): array @@ -43,7 +43,7 @@ public function dataOptions(): array 'skipOnError' => false, 'rules' => [ [ - 'integerType', + IntegerType::class, 'message' => [ 'template' => 'Value must be an integer.', 'parameters' => [], @@ -70,7 +70,7 @@ public function dataOptions(): array 'skipOnError' => true, 'rules' => [ [ - 'integerType', + IntegerType::class, 'message' => [ 'template' => 'Value must be an integer.', 'parameters' => [], @@ -79,7 +79,7 @@ public function dataOptions(): array 'skipOnError' => false, ], [ - 'floatType', + FloatType::class, 'message' => [ 'template' => 'Value must be a float.', 'parameters' => [], diff --git a/tests/Rule/Type/BooleanTypeTest.php b/tests/Rule/Type/BooleanTypeTest.php index 6408f0b57..9dac9bfa3 100644 --- a/tests/Rule/Type/BooleanTypeTest.php +++ b/tests/Rule/Type/BooleanTypeTest.php @@ -26,7 +26,7 @@ final class BooleanTypeTest extends RuleTestCase public function testGetName(): void { $rule = new BooleanType(); - $this->assertSame('booleanType', $rule->getName()); + $this->assertSame(BooleanType::class, $rule->getName()); } public function dataOptions(): array diff --git a/tests/Rule/Type/FloatTypeTest.php b/tests/Rule/Type/FloatTypeTest.php index a34a396ba..407faf890 100644 --- a/tests/Rule/Type/FloatTypeTest.php +++ b/tests/Rule/Type/FloatTypeTest.php @@ -26,7 +26,7 @@ final class FloatTypeTest extends RuleTestCase public function testGetName(): void { $rule = new FloatType(); - $this->assertSame('floatType', $rule->getName()); + $this->assertSame(FloatType::class, $rule->getName()); } public function dataOptions(): array diff --git a/tests/Rule/Type/IntegerTypeTest.php b/tests/Rule/Type/IntegerTypeTest.php index 3f021bdfe..073ebba6b 100644 --- a/tests/Rule/Type/IntegerTypeTest.php +++ b/tests/Rule/Type/IntegerTypeTest.php @@ -26,7 +26,7 @@ final class IntegerTypeTest extends RuleTestCase public function testGetName(): void { $rule = new IntegerType(); - $this->assertSame('integerType', $rule->getName()); + $this->assertSame(IntegerType::class, $rule->getName()); } public function dataOptions(): array diff --git a/tests/Rule/Type/StringTypeTest.php b/tests/Rule/Type/StringTypeTest.php index 843717de2..cb7d85057 100644 --- a/tests/Rule/Type/StringTypeTest.php +++ b/tests/Rule/Type/StringTypeTest.php @@ -27,7 +27,7 @@ final class StringTypeTest extends RuleTestCase public function testGetName(): void { $rule = new StringType(); - $this->assertSame('stringType', $rule->getName()); + $this->assertSame(StringType::class, $rule->getName()); } public function dataOptions(): array diff --git a/tests/Rule/UniqueIterableTest.php b/tests/Rule/UniqueIterableTest.php index 638a48186..6980939cb 100644 --- a/tests/Rule/UniqueIterableTest.php +++ b/tests/Rule/UniqueIterableTest.php @@ -29,7 +29,7 @@ final class UniqueIterableTest extends RuleTestCase public function testGetName(): void { $rule = new UniqueIterable(); - $this->assertSame('unique', $rule->getName()); + $this->assertSame(UniqueIterable::class, $rule->getName()); } public function dataOptions(): array