1 | <?php |
||
25 | class FormBuilder extends \Collective\Html\FormBuilder |
||
26 | { |
||
27 | /** |
||
28 | * Render Form object into Html form with Former. |
||
29 | * |
||
30 | * @param FormInterface $form |
||
31 | * @param array $attrs |
||
32 | * |
||
33 | * @return string |
||
34 | */ |
||
35 | 48 | public function form(FormInterface $form, array $attrs = []) |
|
36 | { |
||
37 | // Populate form from edited model |
||
38 | 48 | $model = $form->getModel(); |
|
39 | 48 | if ($model instanceof Model) { |
|
40 | 11 | Former::populate($model); |
|
41 | } |
||
42 | |||
43 | // Start a form and add rules |
||
44 | 48 | $formType = $form->openType(); |
|
45 | 48 | $former = Former::$formType(); |
|
46 | array_walk($attrs, function ($value, $attr) use ($former) { |
||
47 | 48 | if ($value === null) { |
|
48 | 41 | $former->$attr(); |
|
49 | } else { |
||
50 | 48 | $former->$attr($value); |
|
51 | } |
||
52 | 48 | }); |
|
53 | 48 | $former->rules($form->rules()); |
|
54 | |||
55 | // Generate form fields |
||
56 | 48 | $output = $former; |
|
57 | 48 | $fields = $form->fields(); |
|
58 | 48 | foreach ($fields as $name => $field) { |
|
59 | 48 | $element = $this->element($name, $field); |
|
60 | |||
61 | 48 | if ($element instanceof Field) { |
|
62 | 48 | if (null === $model) { |
|
63 | 44 | $element->value = Request::input($name); |
|
1 ignored issue
–
show
|
|||
64 | } |
||
65 | } |
||
66 | |||
67 | 48 | $output .= $element; |
|
68 | } |
||
69 | |||
70 | // Generate form actions |
||
71 | 48 | $output .= $this->actions($form); |
|
72 | |||
73 | // Close the opened form |
||
74 | 48 | $output .= Former::close(); |
|
75 | |||
76 | 48 | return $output; |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * Generate Former field. |
||
81 | * |
||
82 | * @param string $name |
||
83 | * @param array $field |
||
84 | * |
||
85 | * @return Field |
||
86 | */ |
||
87 | 48 | public function element($name, array $field) |
|
106 | |||
107 | /** |
||
108 | * Render form actions. |
||
109 | * |
||
110 | * @param FormInterface $form |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | 48 | public function actions(FormInterface $form) |
|
132 | } |
||
133 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.