Total Complexity | 11 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class Validator extends BaseValidator |
||
10 | { |
||
11 | private array $extraCallbacks = []; |
||
12 | |||
13 | public function afterSuccess(callable $callback): Validator |
||
14 | { |
||
15 | return $this->registerExtraCallback('success', $callback); |
||
16 | } |
||
17 | |||
18 | public function afterFailure(callable $callback): Validator |
||
19 | { |
||
20 | return $this->registerExtraCallback('fail', $callback); |
||
21 | } |
||
22 | |||
23 | public function fails() |
||
24 | { |
||
25 | $fails = !$this->passes(); |
||
26 | |||
27 | if ($fails) { |
||
28 | $this->runExtraCallbacks('fail'); |
||
29 | } else { |
||
30 | $fails = $this->runExtraCallbacks('success') === false; |
||
31 | } |
||
32 | |||
33 | return $fails; |
||
34 | } |
||
35 | |||
36 | private function registerExtraCallback(string $type, callable $callback): Validator |
||
45 | } |
||
46 | |||
47 | private function runExtraCallbacks(string $type): bool |
||
62 | } |
||
63 | } |
||
64 |