Skip to content

Commit

Permalink
Fix #242: Document that rule handler should not be called directly (#256
Browse files Browse the repository at this point in the history
)
  • Loading branch information
samdark committed Jul 17, 2022
1 parent 4a4f19e commit 5677329
Show file tree
Hide file tree
Showing 22 changed files with 26 additions and 22 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -644,6 +644,8 @@ final class CompanyNameHandler implements Rule\RuleHandlerInterface
}
```

> Note: Do not call handler's `validate()` method directly. It must be used via Validator only.
##### Resolving rule handler dependencies

Basically, you can use `SimpleRuleHandlerResolver` to resolve rule handler.
Expand Down
2 changes: 2 additions & 0 deletions src/Rule/RuleHandlerInterface.php
Expand Up @@ -19,6 +19,8 @@ interface RuleHandlerInterface
* @param object $rule Rule containing validation parameters.
* @param ValidationContext|null $context Optional validation context.
*
* @internal Should be never called directly. Use {@see ValidatorInterface}.
*
* @return Result
*/
public function validate(mixed $value, object $rule, ?ValidationContext $context = null): Result;
Expand Down
6 changes: 3 additions & 3 deletions tests/Rule/AbstractRuleValidatorTest.php
Expand Up @@ -59,10 +59,10 @@ public function testDifferentRule(): void

protected function validate(mixed $value, object $config): Result
{
$ruleValidator = $this->getValidator();
$ruleHandler = $this->getRuleHandler();
$context = $this->getValidationContext();

return $ruleValidator->validate($value, $config, $context);
return $ruleHandler->validate($value, $config, $context);
}

protected function formatMessage(string $message, array $params): string
Expand All @@ -76,7 +76,7 @@ abstract public function passedValidationProvider(): array;

abstract public function failedValidationProvider(): array;

abstract protected function getValidator(): RuleHandlerInterface;
abstract protected function getRuleHandler(): RuleHandlerInterface;

protected function getValidationContext(): ValidationContext
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/AtLeastHandlerTest.php
Expand Up @@ -53,7 +53,7 @@ public function customErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new AtLeastHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/BooleanHandlerTest.php
Expand Up @@ -69,7 +69,7 @@ public function customErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new BooleanHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/CallbackHandlerTest.php
Expand Up @@ -75,7 +75,7 @@ public function testThrowExceptionWithInvalidReturn(): void
$this->validate(null, $rule);
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new CallbackHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/CompareToHandlerTest.php
Expand Up @@ -92,7 +92,7 @@ public function customErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new CompareToHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/CompositeHandlerTest.php
Expand Up @@ -72,7 +72,7 @@ public function customErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new CompositeHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/CountHandlerTest.php
Expand Up @@ -122,7 +122,7 @@ public function customErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new CountHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/EachHandlerTest.php
Expand Up @@ -75,7 +75,7 @@ public function indexedByPathErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new EachHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/EmailHandlerTest.php
Expand Up @@ -152,7 +152,7 @@ public function customErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new EmailHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/GroupRuleHandlerTest.php
Expand Up @@ -49,7 +49,7 @@ public function customErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new GroupRuleHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/HasLengthHandlerTest.php
Expand Up @@ -85,7 +85,7 @@ public function customErrorMessagesProvider(): array
];
}

protected function getValidator(): HasLengthHandler
protected function getRuleHandler(): HasLengthHandler
{
return new HasLengthHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/InRangeHandlerTest.php
Expand Up @@ -80,7 +80,7 @@ public function customErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new InRangeHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/IpHandlerTest.php
Expand Up @@ -238,7 +238,7 @@ public function testInitException(): void
$this->validate('', $rule);
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new IpHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/JsonHandlerTest.php
Expand Up @@ -124,7 +124,7 @@ public function customErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new JsonHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/NestedHandlerTest.php
Expand Up @@ -214,7 +214,7 @@ public function indexedByPathErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new NestedHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/NumberHandlerTest.php
Expand Up @@ -123,7 +123,7 @@ public function customErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new NumberHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/RegexHandlerTest.php
Expand Up @@ -59,7 +59,7 @@ public function customErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new RegexHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/RequiredHandlerTest.php
Expand Up @@ -38,7 +38,7 @@ public function customErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new RequiredHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/SubsetHandlerTest.php
Expand Up @@ -50,7 +50,7 @@ public function customErrorMessagesProvider(): array
];
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new SubsetHandler();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/UrlHandlerTest.php
Expand Up @@ -95,7 +95,7 @@ public function testEnableIdnException(): void
new Url(enableIDN: true);
}

protected function getValidator(): RuleHandlerInterface
protected function getRuleHandler(): RuleHandlerInterface
{
return new UrlHandler();
}
Expand Down

0 comments on commit 5677329

Please sign in to comment.