Conditions | 9 |
Paths | 11 |
Total Lines | 32 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php namespace Anomaly\Streams\Platform\Ui\Form\Component\Field\Guesser; |
||
14 | public function guess(FormBuilder $builder) |
||
15 | { |
||
16 | $fields = $builder->getFields(); |
||
17 | |||
18 | foreach ($fields as &$field) { |
||
|
|||
19 | |||
20 | // Skip if nullable |
||
21 | if (isset($field['rules']) && in_array('nullable', $field['rules'])) { |
||
22 | continue; |
||
23 | } |
||
24 | |||
25 | // If the field depends on other fields, we not add nullable here |
||
26 | // because validation will not be performed at all on this field |
||
27 | if (! empty($field['rules'])) { |
||
28 | if (preg_grep("/required_.*/", $field['rules'])) { |
||
29 | continue; |
||
30 | } |
||
31 | } |
||
32 | |||
33 | // If not required then nullable. |
||
34 | if (isset($field['required']) && $field['required'] == false) { |
||
35 | $field['rules'][] = 'nullable'; |
||
36 | } |
||
37 | |||
38 | // If not specified then it's nullable |
||
39 | if (!isset($field['required'])) { |
||
40 | $field['rules'][] = 'nullable'; |
||
41 | } |
||
42 | } |
||
43 | |||
44 | $builder->setFields($fields); |
||
45 | } |
||
46 | } |
||
47 |
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.