diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e95e132ab..de0dba541 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,7 @@ create a validator that validates if a string is equal to "Hello World". ### Creating the rule -The rule itself needs to implement the `Validatable` interface but, it is +The rule itself needs to implement the `Rule` interface but, it is convenient to just extend the `Simple` or `Standard` class. Doing that, you'll only need to declare one method: `validate($input)`. This method must return `true` or `false`. diff --git a/bin/create-mixin b/bin/create-mixin index 2433e5a5d..d3f8363ac 100755 --- a/bin/create-mixin +++ b/bin/create-mixin @@ -28,7 +28,7 @@ use Respect\Validation\Mixins\StaticUndefOr; use Respect\Validation\Rules\NotUndef; use Respect\Validation\Rules\NullOr; use Respect\Validation\Rules\UndefOr; -use Respect\Validation\Validatable; +use Respect\Validation\Rule; function addMethodToInterface( string $originalName, @@ -209,15 +209,15 @@ function overwriteFile(string $content, string $basename): void foreach ($mixins as [$name, $prefix, $allowList, $denyList]) { $chainedNamespace = new PhpNamespace('Respect\\Validation\\Mixins'); - $chainedNamespace->addUse(Validatable::class); + $chainedNamespace->addUse(Rule::class); $chainedInterface = $chainedNamespace->addInterface('Chained' . $name); $staticNamespace = new PhpNamespace('Respect\\Validation\\Mixins'); - $staticNamespace->addUse(Validatable::class); + $staticNamespace->addUse(Rule::class); $staticInterface = $staticNamespace->addInterface('Static' . $name); if ($name === 'Validator') { - $chainedInterface->addExtend(Validatable::class); + $chainedInterface->addExtend(Rule::class); $chainedInterface->addExtend(ChainedKey::class); $chainedInterface->addExtend(ChainedLength::class); $chainedInterface->addExtend(ChainedMax::class); @@ -240,7 +240,7 @@ function overwriteFile(string $content, string $basename): void $setTemplates->addComment('@param array $templates'); $getRules = $chainedInterface->addMethod('getRules')->setPublic()->setReturnType('array'); - $getRules->addComment('@return array'); + $getRules->addComment('@return array'); $staticInterface->addExtend(StaticKey::class); $staticInterface->addExtend(StaticLength::class); diff --git a/docs/07-custom-rules.md b/docs/07-custom-rules.md index fbefad900..3aa6f3da9 100644 --- a/docs/07-custom-rules.md +++ b/docs/07-custom-rules.md @@ -3,7 +3,7 @@ You can also create and use your own rules. To do this, you will need to create a rule and an exception to go with the rule. -To create a rule, you need to create a class that implements the `Validatable` interface +To create a rule, you need to create a class that implements the `Rule` interface and is within the Rules `namespace`. It is convenient to just extend the `Simple` or `Standard` class. When the rule is called the logic inside the validate method will be executed. Here's how the class should look: diff --git a/docs/rules/AllOf.md b/docs/rules/AllOf.md index 8d7de2a7b..9a01e8239 100644 --- a/docs/rules/AllOf.md +++ b/docs/rules/AllOf.md @@ -1,6 +1,6 @@ # AllOf -- `AllOf(Validatable $rule1, Validatable $rule2, Validatable ...$rule)` +- `AllOf(Rule $rule1, Rule $rule2, Rule ...$rule)` Will validate if all inner validators validates. diff --git a/docs/rules/AnyOf.md b/docs/rules/AnyOf.md index 213b49b1f..34c9d94ed 100644 --- a/docs/rules/AnyOf.md +++ b/docs/rules/AnyOf.md @@ -1,6 +1,6 @@ # AnyOf -- `AnyOf(Validatable $rule1, Validatable $rule2, Validatable ...$rule)` +- `AnyOf(Rule $rule1, Rule $rule2, Rule ...$rule)` This is a group validator that acts as an OR operator. diff --git a/docs/rules/Consecutive.md b/docs/rules/Consecutive.md index 36fc085d5..e980cc9b7 100644 --- a/docs/rules/Consecutive.md +++ b/docs/rules/Consecutive.md @@ -1,6 +1,6 @@ # Consecutive -- `Consecutive(Validatable $rule1, Validatable $rule2, Validatable ...$rule)` +- `Consecutive(Rule $rule1, Rule $rule2, Rule ...$rule)` Validates the input against a series of rules until one fails. diff --git a/docs/rules/DateTimeDiff.md b/docs/rules/DateTimeDiff.md index 59aaf6703..0f73b89cd 100644 --- a/docs/rules/DateTimeDiff.md +++ b/docs/rules/DateTimeDiff.md @@ -1,7 +1,7 @@ # DateTimeDiff -- `DateTimeDiff(string $type, Validatable $rule)` -- `DateTimeDiff(string $type, Validatable $rule, string $format)` +- `DateTimeDiff(string $type, Rule $rule)` +- `DateTimeDiff(string $type, Rule $rule, string $format)` Validates the difference of date/time against a specific rule. diff --git a/docs/rules/Each.md b/docs/rules/Each.md index cb57ffd03..d15e0f163 100644 --- a/docs/rules/Each.md +++ b/docs/rules/Each.md @@ -1,6 +1,6 @@ # Each -- `Each(Validatable $rule)` +- `Each(Rule $rule)` Validates whether each value in the input is valid according to another rule. diff --git a/docs/rules/Key.md b/docs/rules/Key.md index 7c933090c..cc64114cc 100644 --- a/docs/rules/Key.md +++ b/docs/rules/Key.md @@ -1,6 +1,6 @@ # Key -- `Key(int|string $key, Validatable $rule)` +- `Key(int|string $key, Rule $rule)` Validates the value of an array against a given rule. diff --git a/docs/rules/KeyOptional.md b/docs/rules/KeyOptional.md index 35a350b0a..436a73a2d 100644 --- a/docs/rules/KeyOptional.md +++ b/docs/rules/KeyOptional.md @@ -1,6 +1,6 @@ # KeyOptional -- `KeyOptional(int|string $key, Validatable $rule)` +- `KeyOptional(int|string $key, Rule $rule)` Validates the value of an array against a given rule when the key exists. diff --git a/docs/rules/Lazy.md b/docs/rules/Lazy.md index 614594ac0..f4202c5a6 100644 --- a/docs/rules/Lazy.md +++ b/docs/rules/Lazy.md @@ -1,6 +1,6 @@ # Lazy -- `Lazy(callable(mixed $input): Validatable $ruleCreator)` +- `Lazy(callable(mixed $input): Rule $ruleCreator)` Validates the input using a rule that is created from a callback. diff --git a/docs/rules/Length.md b/docs/rules/Length.md index 96e8cbcd9..d5689b847 100644 --- a/docs/rules/Length.md +++ b/docs/rules/Length.md @@ -1,6 +1,6 @@ # Length -- `Length(Validatable $rule)` +- `Length(Rule $rule)` Validates the length of the given input against a given rule. diff --git a/docs/rules/Max.md b/docs/rules/Max.md index 8aee002e4..29b7adc0e 100644 --- a/docs/rules/Max.md +++ b/docs/rules/Max.md @@ -1,6 +1,6 @@ # Max -- `Max(Validatable $rule)` +- `Max(Rule $rule)` Validates the maximum value of the input against a given rule. diff --git a/docs/rules/Min.md b/docs/rules/Min.md index 3d5359247..be7f0ae9e 100644 --- a/docs/rules/Min.md +++ b/docs/rules/Min.md @@ -1,6 +1,6 @@ # Min -- `Min(Validatable $rule)` +- `Min(Rule $rule)` Validates the minimum value of the input against a given rule. diff --git a/docs/rules/NoneOf.md b/docs/rules/NoneOf.md index 6708c5c61..8a2f54c04 100644 --- a/docs/rules/NoneOf.md +++ b/docs/rules/NoneOf.md @@ -1,6 +1,6 @@ # NoneOf -- `NoneOf(Validatable $rule1, Validatable $rule2, Validatable ...$rule)` +- `NoneOf(Rule $rule1, Rule $rule2, Rule ...$rule)` Validates if NONE of the given validators validate: diff --git a/docs/rules/Not.md b/docs/rules/Not.md index b46dd501b..c2801c8de 100644 --- a/docs/rules/Not.md +++ b/docs/rules/Not.md @@ -1,6 +1,6 @@ # Not -- `Not(Validatable $rule)` +- `Not(Rule $rule)` Negates any rule. diff --git a/docs/rules/NullOr.md b/docs/rules/NullOr.md index 13315ac57..d2bf814b9 100644 --- a/docs/rules/NullOr.md +++ b/docs/rules/NullOr.md @@ -1,6 +1,6 @@ # NullOr -- `NullOr(Validatable $rule)` +- `NullOr(Rule $rule)` Validates the input using a defined rule when the input is not `null`. diff --git a/docs/rules/OneOf.md b/docs/rules/OneOf.md index f606a4d62..ed65d6268 100644 --- a/docs/rules/OneOf.md +++ b/docs/rules/OneOf.md @@ -1,6 +1,6 @@ # OneOf -- `OneOf(Validatable $rule1, Validatable $rule2, Validatable ...$rule)` +- `OneOf(Rule $rule1, Rule $rule2, Rule ...$rule)` Will validate if exactly one inner validator passes. diff --git a/docs/rules/Property.md b/docs/rules/Property.md index ea9b648cd..5ae2d0dbe 100644 --- a/docs/rules/Property.md +++ b/docs/rules/Property.md @@ -1,6 +1,6 @@ # Property -- `Property(string $propertyName, Validatable $rule)` +- `Property(string $propertyName, Rule $rule)` Validates an object property against a given rule. diff --git a/docs/rules/PropertyOptional.md b/docs/rules/PropertyOptional.md index 52d1ec051..5de11d20a 100644 --- a/docs/rules/PropertyOptional.md +++ b/docs/rules/PropertyOptional.md @@ -1,6 +1,6 @@ # PropertyOptional -- `PropertyOptional(string $propertyName, Validatable $rule)` +- `PropertyOptional(string $propertyName, Rule $rule)` Validates an object property against a given rule only if the property exists. diff --git a/docs/rules/UndefOr.md b/docs/rules/UndefOr.md index 4229aaefe..e74752e18 100644 --- a/docs/rules/UndefOr.md +++ b/docs/rules/UndefOr.md @@ -1,6 +1,6 @@ # UndefOr -- `UndefOr(Validatable $rule)` +- `UndefOr(Rule $rule)` Validates the input using a defined rule when the input is not `null` or an empty string (`''`). diff --git a/docs/rules/When.md b/docs/rules/When.md index 4cda058cc..e285deffb 100644 --- a/docs/rules/When.md +++ b/docs/rules/When.md @@ -1,7 +1,7 @@ # When -- `When(Validatable $if, Validatable $then)` -- `When(Validatable $if, Validatable $then, Validatable $else)` +- `When(Rule $if, Rule $then)` +- `When(Rule $if, Rule $then, Rule $else)` A ternary validator that accepts three parameters. diff --git a/library/Factory.php b/library/Factory.php index 22c01de1c..67e8d3b81 100644 --- a/library/Factory.php +++ b/library/Factory.php @@ -64,12 +64,12 @@ public function withRuleNamespace(string $rulesNamespace): self /** * @param mixed[] $arguments */ - public function rule(string $ruleName, array $arguments = []): Validatable + public function rule(string $ruleName, array $arguments = []): Rule { return $this->createRuleSpec($this->transformer->transform(new RuleSpec($ruleName, $arguments))); } - private function createRuleSpec(RuleSpec $ruleSpec): Validatable + private function createRuleSpec(RuleSpec $ruleSpec): Rule { $rule = $this->createRule($ruleSpec->name, $ruleSpec->arguments); if ($ruleSpec->wrapper !== null) { @@ -82,16 +82,16 @@ private function createRuleSpec(RuleSpec $ruleSpec): Validatable /** * @param mixed[] $arguments */ - private function createRule(string $ruleName, array $arguments = []): Validatable + private function createRule(string $ruleName, array $arguments = []): Rule { foreach ($this->rulesNamespaces as $namespace) { try { - /** @var class-string $name */ + /** @var class-string $name */ $name = $namespace . '\\' . ucfirst($ruleName); $reflection = new ReflectionClass($name); - if (!$reflection->isSubclassOf(Validatable::class)) { + if (!$reflection->isSubclassOf(Rule::class)) { throw new InvalidClassException( - sprintf('"%s" must be an instance of "%s"', $name, Validatable::class) + sprintf('"%s" must be an instance of "%s"', $name, Rule::class) ); } diff --git a/library/Helpers/CanBindEvaluateRule.php b/library/Helpers/CanBindEvaluateRule.php index d3e8b6f84..c55d2ef71 100644 --- a/library/Helpers/CanBindEvaluateRule.php +++ b/library/Helpers/CanBindEvaluateRule.php @@ -10,11 +10,11 @@ namespace Respect\Validation\Helpers; use Respect\Validation\Result; -use Respect\Validation\Validatable; +use Respect\Validation\Rule; trait CanBindEvaluateRule { - private function bindEvaluate(Validatable $binded, Validatable $binder, mixed $input): Result + private function bindEvaluate(Rule $binded, Rule $binder, mixed $input): Result { if ($binder->getName() !== null && $binded->getName() === null) { $binded->setName($binder->getName()); diff --git a/library/Helpers/CanExtractRules.php b/library/Helpers/CanExtractRules.php index 67e843023..592ad810a 100644 --- a/library/Helpers/CanExtractRules.php +++ b/library/Helpers/CanExtractRules.php @@ -9,9 +9,9 @@ namespace Respect\Validation\Helpers; +use Respect\Validation\Rule; use Respect\Validation\Rules\Core\Composite; use Respect\Validation\Rules\Not; -use Respect\Validation\Validatable; use Respect\Validation\Validator; use Throwable; @@ -19,7 +19,7 @@ trait CanExtractRules { - private function extractSiblingSuitableRule(Validatable $rule, Throwable $throwable): Validatable + private function extractSiblingSuitableRule(Rule $rule, Throwable $throwable): Rule { $this->assertSingleRule($rule, $throwable); @@ -30,7 +30,7 @@ private function extractSiblingSuitableRule(Validatable $rule, Throwable $throwa return $rule; } - private function assertSingleRule(Validatable $rule, Throwable $throwable): void + private function assertSingleRule(Rule $rule, Throwable $throwable): void { if ($rule instanceof Not) { $this->assertSingleRule($rule->getRule(), $throwable); diff --git a/library/Message/StandardRenderer.php b/library/Message/StandardRenderer.php index dbe9285ea..ffaa6ea9a 100644 --- a/library/Message/StandardRenderer.php +++ b/library/Message/StandardRenderer.php @@ -14,7 +14,7 @@ use Respect\Stringifier\Stringifiers\CompositeStringifier; use Respect\Validation\Mode; use Respect\Validation\Result; -use Respect\Validation\Validatable; +use Respect\Validation\Rule; use function is_bool; use function is_scalar; @@ -60,7 +60,7 @@ function (array $matches) use ($parameters, $translator) { } /** @return array