We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
5 | trait Fields |
||
6 | { |
||
7 | // ------------ |
||
8 | // FIELDS |
||
9 | // ------------ |
||
10 | |||
11 | /** |
||
12 | * Add a field to the create/update form or both. |
||
13 | * |
||
14 | * @param string $form The form to add the field to (create/update/both) |
||
15 | */ |
||
16 | public function addField($field, $form = 'both') |
||
57 | |||
58 | public function addFields($fields, $form = 'both') |
||
66 | |||
67 | /** |
||
68 | * Remove a certain field from the create/update/both forms by its name. |
||
69 | * |
||
70 | * @param string $name Field name (as defined with the addField() procedure) |
||
71 | * @param string $form update/create/both |
||
72 | */ |
||
73 | public function removeField($name, $form = 'both') |
||
90 | |||
91 | /** |
||
92 | * Remove many fields from the create/update/both forms by their name. |
||
93 | * |
||
94 | * @param array $array_of_names A simple array of the names of the fields to be removed. |
||
95 | * @param string $form update/create/both |
||
96 | */ |
||
97 | public function removeFields($array_of_names, $form = 'both') |
||
105 | |||
106 | /** |
||
107 | * Check if field is the first of its type in the given fields array. |
||
108 | * It's used in each field_type.blade.php to determine wether to push the css and js content or not (we only need to push the js and css for a field the first time it's loaded in the form, not any subsequent times). |
||
109 | * |
||
110 | * @param array $field The current field being tested if it's the first of its type. |
||
111 | * @param array $fields_array All the fields in that particular form. |
||
112 | * |
||
113 | * @return bool true/false |
||
114 | */ |
||
115 | public function checkIfFieldIsFirstOfItsType($field, $fields_array) |
||
123 | |||
124 | /** |
||
125 | * Order the fields in a certain way. |
||
126 | * |
||
127 | * @param [string] Column name. |
||
128 | * @param [attributes and values array] |
||
129 | */ |
||
130 | public function setFieldOrder($fields) |
||
134 | |||
135 | // ALIAS of setFieldOrder($fields) |
||
136 | public function setFieldsOrder($fields) |
||
140 | |||
141 | // ------------ |
||
142 | // TONE FUNCTIONS - UNDOCUMENTED, UNTESTED, SOME MAY BE USED |
||
143 | // ------------ |
||
144 | // TODO: check them |
||
145 | |||
146 | public function orderFields($order) |
||
150 | } |
||
151 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.