Skip to content

Commit 5677329

Browse files
authored
Fix #242: Document that rule handler should not be called directly (#256)
1 parent 4a4f19e commit 5677329

22 files changed

Lines changed: 26 additions & 22 deletions

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ final class CompanyNameHandler implements Rule\RuleHandlerInterface
644644
}
645645
```
646646

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

649651
Basically, you can use `SimpleRuleHandlerResolver` to resolve rule handler.

src/Rule/RuleHandlerInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ interface RuleHandlerInterface
1919
* @param object $rule Rule containing validation parameters.
2020
* @param ValidationContext|null $context Optional validation context.
2121
*
22+
* @internal Should be never called directly. Use {@see ValidatorInterface}.
23+
*
2224
* @return Result
2325
*/
2426
public function validate(mixed $value, object $rule, ?ValidationContext $context = null): Result;

tests/Rule/AbstractRuleValidatorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public function testDifferentRule(): void
5959

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

65-
return $ruleValidator->validate($value, $config, $context);
65+
return $ruleHandler->validate($value, $config, $context);
6666
}
6767

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

7777
abstract public function failedValidationProvider(): array;
7878

79-
abstract protected function getValidator(): RuleHandlerInterface;
79+
abstract protected function getRuleHandler(): RuleHandlerInterface;
8080

8181
protected function getValidationContext(): ValidationContext
8282
{

tests/Rule/AtLeastHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function customErrorMessagesProvider(): array
5353
];
5454
}
5555

56-
protected function getValidator(): RuleHandlerInterface
56+
protected function getRuleHandler(): RuleHandlerInterface
5757
{
5858
return new AtLeastHandler();
5959
}

tests/Rule/BooleanHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function customErrorMessagesProvider(): array
6969
];
7070
}
7171

72-
protected function getValidator(): RuleHandlerInterface
72+
protected function getRuleHandler(): RuleHandlerInterface
7373
{
7474
return new BooleanHandler();
7575
}

tests/Rule/CallbackHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testThrowExceptionWithInvalidReturn(): void
7575
$this->validate(null, $rule);
7676
}
7777

78-
protected function getValidator(): RuleHandlerInterface
78+
protected function getRuleHandler(): RuleHandlerInterface
7979
{
8080
return new CallbackHandler();
8181
}

tests/Rule/CompareToHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function customErrorMessagesProvider(): array
9292
];
9393
}
9494

95-
protected function getValidator(): RuleHandlerInterface
95+
protected function getRuleHandler(): RuleHandlerInterface
9696
{
9797
return new CompareToHandler();
9898
}

tests/Rule/CompositeHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function customErrorMessagesProvider(): array
7272
];
7373
}
7474

75-
protected function getValidator(): RuleHandlerInterface
75+
protected function getRuleHandler(): RuleHandlerInterface
7676
{
7777
return new CompositeHandler();
7878
}

tests/Rule/CountHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function customErrorMessagesProvider(): array
122122
];
123123
}
124124

125-
protected function getValidator(): RuleHandlerInterface
125+
protected function getRuleHandler(): RuleHandlerInterface
126126
{
127127
return new CountHandler();
128128
}

tests/Rule/EachHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function indexedByPathErrorMessagesProvider(): array
7575
];
7676
}
7777

78-
protected function getValidator(): RuleHandlerInterface
78+
protected function getRuleHandler(): RuleHandlerInterface
7979
{
8080
return new EachHandler();
8181
}

0 commit comments

Comments
 (0)