Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Not | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
validate | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Verja\Validator; |
4 | |
5 | use Verja\Validator; |
6 | use Verja\ValidatorInterface; |
7 | |
8 | class Not extends Validator |
9 | { |
10 | /** @var ValidatorInterface */ |
11 | protected $validator; |
12 | |
13 | /** |
14 | * Not constructor. |
15 | * |
16 | * @param ValidatorInterface|string $validator |
17 | */ |
18 | public function __construct($validator) |
19 | { |
20 | if (!$validator instanceof ValidatorInterface) { |
21 | $validator = Validator::fromString($validator); |
22 | } |
23 | |
24 | $this->validator = $validator; |
25 | } |
26 | |
27 | /** |
28 | * Validate $value |
29 | * |
30 | * @param mixed $value |
31 | * @param array $context |
32 | * @return bool |
33 | */ |
34 | public function validate($value, array $context = []): bool |
35 | { |
36 | if ($this->validator->validate($value, $context)) { |
37 | $this->error = $this->validator->getInverseError($value); |
38 | return false; |
39 | } |
40 | |
41 | return true; |
42 | } |
43 | } |