1 | <?php |
||
24 | class RangeValidator extends Validator |
||
25 | { |
||
26 | /** |
||
27 | * @var array|\Traversable|\Closure a list of valid values that the attribute value should be among or an anonymous function that returns |
||
28 | * such a list. The signature of the anonymous function should be as follows, |
||
29 | * |
||
30 | * ```php |
||
31 | * function($model, $attribute) { |
||
32 | * // compute range |
||
33 | * return $range; |
||
34 | * } |
||
35 | * ``` |
||
36 | */ |
||
37 | public $range; |
||
38 | /** |
||
39 | * @var bool whether the comparison is strict (both type and value must be the same) |
||
40 | */ |
||
41 | public $strict = false; |
||
42 | /** |
||
43 | * @var bool whether to invert the validation logic. Defaults to false. If set to true, |
||
44 | * the attribute value should NOT be among the list of values defined via [[range]]. |
||
45 | */ |
||
46 | public $not = false; |
||
47 | /** |
||
48 | * @var bool whether to allow array type attribute. |
||
49 | */ |
||
50 | public $allowArray = false; |
||
51 | |||
52 | |||
53 | /** |
||
54 | * @inheritdoc |
||
55 | */ |
||
56 | 10 | public function init() |
|
69 | |||
70 | /** |
||
71 | * @inheritdoc |
||
72 | */ |
||
73 | 8 | protected function validateValue($value) |
|
90 | |||
91 | /** |
||
92 | * @inheritdoc |
||
93 | */ |
||
94 | 1 | public function validateAttribute($model, $attribute) |
|
101 | |||
102 | /** |
||
103 | * @inheritdoc |
||
104 | */ |
||
105 | public function clientValidateAttribute($model, $attribute, $view) |
||
116 | |||
117 | /** |
||
118 | * @inheritdoc |
||
119 | */ |
||
120 | public function getClientOptions($model, $attribute) |
||
142 | } |
||
143 |
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.