| Total Complexity | 6 |
| Total Lines | 66 |
| Duplicated Lines | 0 % |
| Coverage | 66.67% |
| Changes | 0 | ||
| 1 | <?php |
||
| 41 | trait Validator |
||
| 42 | { |
||
| 43 | /** |
||
| 44 | * @var ValidatorForm instance |
||
| 45 | */ |
||
| 46 | private $validatorForm; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Get ValidatorBuilder |
||
| 50 | * |
||
| 51 | * @return ValidatorForm |
||
| 52 | */ |
||
| 53 | 2 | private function getValidatorForm(): ValidatorForm |
|
| 54 | { |
||
| 55 | 2 | if (!$this->validatorForm) { |
|
| 56 | 2 | $this->validatorForm = new ValidatorForm(); |
|
| 57 | } |
||
| 58 | 2 | return $this->validatorForm; |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Add ValidatorChain |
||
| 63 | * |
||
| 64 | * @param string $name |
||
| 65 | * |
||
| 66 | * @return ValidatorChain |
||
| 67 | */ |
||
| 68 | 2 | public function addValidator(string $name): ValidatorChain |
|
| 69 | { |
||
| 70 | 2 | return $this->getValidatorForm()->add($name); |
|
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Get ValidatorChain |
||
| 75 | * |
||
| 76 | * @param string $name |
||
| 77 | * |
||
| 78 | * @return ValidatorChain |
||
| 79 | */ |
||
| 80 | public function getValidator(string $name): ValidatorChain |
||
| 81 | { |
||
| 82 | return $this->getValidatorForm()->get($name); |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Validate input data |
||
| 87 | * |
||
| 88 | * @param array $input |
||
| 89 | * |
||
| 90 | * @return bool |
||
| 91 | */ |
||
| 92 | public function validate($input): bool |
||
| 93 | { |
||
| 94 | return $this->getValidatorForm()->validate($input); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Assert input data |
||
| 99 | * |
||
| 100 | * @param array $input |
||
| 101 | * |
||
| 102 | * @throws ValidatorException |
||
| 103 | */ |
||
| 104 | 2 | public function assert($input): void |
|
| 107 | 2 | } |
|
| 108 | } |
||
| 109 |