1 | <?php |
||
29 | class Builder |
||
30 | { |
||
31 | /** |
||
32 | * @var \Caridea\Validate\Parser |
||
33 | */ |
||
34 | private $parser; |
||
35 | /** |
||
36 | * @var array<string,\Caridea\Validate\Rule\Set> |
||
37 | */ |
||
38 | private $validators = []; |
||
39 | |||
40 | /** |
||
41 | * Creates a new Validation Builder. |
||
42 | * |
||
43 | * @param \Caridea\Validate\Parser $parser The parser. |
||
44 | */ |
||
45 | 2 | public function __construct(Parser $parser) |
|
49 | |||
50 | /** |
||
51 | * Adds one or more rules to this builder. |
||
52 | * |
||
53 | * @param string $field The field to validate |
||
54 | * @param string|object|array $rules Either a string name, an associative |
||
55 | * array, or an object with name → arguments |
||
56 | * @return $this provides a fluent interface |
||
57 | */ |
||
58 | 1 | public function field(string $field, ...$rules): self |
|
63 | |||
64 | /** |
||
65 | * Builds a validator for the provided ruleset. |
||
66 | * |
||
67 | * ```javascript |
||
68 | * // rules.json |
||
69 | * { |
||
70 | * name: 'required', |
||
71 | * email: ['required', 'email'], |
||
72 | * drinks: { one_of: [['coffee', 'tea']] }, |
||
73 | * phone: {max_length: 10} |
||
74 | * } |
||
75 | * ``` |
||
76 | * ```php |
||
77 | * $ruleset = json_decode(file_get_contents('rules.json')); |
||
78 | * $builder = new \Caridea\Validate\Builder(); |
||
79 | * $validator = $builder->build($ruleset); |
||
80 | * ``` |
||
81 | * |
||
82 | * @param object|array $ruleset Object or associative array (as returned |
||
83 | * from `json_decode`) with ruleset, or `null` to use defined rules. |
||
84 | * @return \Caridea\Validate\Validator the built validator |
||
85 | */ |
||
86 | 2 | public function build($ruleset = null): Validator |
|
96 | } |
||
97 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.