1 | <?php |
||
7 | class NotValidator extends ValidatorAbstract |
||
8 | { |
||
9 | const ERROR_TYPE = 'not'; |
||
10 | |||
11 | /** @var \Wandu\Validator\Contracts\ValidatorInterface */ |
||
12 | protected $next; |
||
13 | |||
14 | /** |
||
15 | * @param \Wandu\Validator\Contracts\ValidatorInterface $next |
||
16 | */ |
||
17 | 4 | public function __construct(ValidatorInterface $next) |
|
21 | |||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | function test($item) |
||
|
|||
26 | { |
||
27 | // nothing |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * {@inheritdoc} |
||
32 | */ |
||
33 | 2 | public function assert($item) |
|
34 | { |
||
35 | 2 | if (!isset($item)) return; |
|
36 | try { |
||
37 | 2 | $this->next->assert($item); |
|
38 | 2 | } catch (InvalidValueException $exception) { |
|
39 | 2 | return; |
|
40 | } |
||
41 | 2 | $errorType = ValidatorAbstract::ERROR_TYPE; |
|
42 | 2 | if ($this->next instanceof ValidatorAbstract) { |
|
43 | 2 | $errorType = $this->next->getErrorType(); |
|
44 | } |
||
45 | 2 | $suffix = isset($this->name) ? '@' . $this->name : ''; |
|
46 | 2 | throw new InvalidValueException('not.' . $errorType . $suffix); |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | 1 | public function validate($item) |
|
57 | } |
||
58 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.