1 | <?php |
||
29 | class Validator |
||
30 | { |
||
31 | /** |
||
32 | * @var array<string,\Caridea\Validate\Rule\Set> Associative array of field name to rule set |
||
33 | */ |
||
34 | protected $ruleset; |
||
35 | |||
36 | /** |
||
37 | * Creates a new validator. |
||
38 | * |
||
39 | * @param array<string,\Caridea\Validate\Rule\Set> $ruleset Associative array of field name to rule set |
||
40 | */ |
||
41 | 1 | public function __construct(array $ruleset) |
|
45 | |||
46 | /** |
||
47 | * Gets a field from the values. |
||
48 | * |
||
49 | * This can be overridden to access by other means (e.g. object properties, |
||
50 | * getter methods). |
||
51 | * |
||
52 | * @param mixed $values The values |
||
53 | * @param string $field The field to access |
||
54 | * @return mixed The accessed value |
||
55 | */ |
||
56 | 1 | protected function access($values, string $field) |
|
60 | |||
61 | /** |
||
62 | * Iterates over the ruleset and collects any error codes. |
||
63 | * |
||
64 | * @param object|array $values An object or associative array to validate |
||
65 | * @return array Associative array of field name to error |
||
66 | * @throws \InvalidArgumentException if `$values` is null |
||
67 | */ |
||
68 | 2 | protected function iterate($values) |
|
84 | |||
85 | /** |
||
86 | * Validates the provided value, returning a result object. |
||
87 | * |
||
88 | * @param object|array $values An object or associative array to validate |
||
89 | * @return \Caridea\Validate\Result The validation results |
||
90 | * @throws \InvalidArgumentException if `$values` is null |
||
91 | */ |
||
92 | 1 | public function validate($values): Result |
|
96 | |||
97 | /** |
||
98 | * Validates the provided value, throwing an exception upon failure. |
||
99 | * |
||
100 | * @param object|array $values An object or associative array to validate |
||
101 | * @throws \Caridea\Validate\Exception\Invalid if validation fails |
||
102 | * @throws \InvalidArgumentException if `$values` is null |
||
103 | */ |
||
104 | 2 | public function assert($values) |
|
111 | } |
||
112 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.