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') |
||
52 | |||
53 | public function addFields($fields, $form = 'both') |
||
61 | |||
62 | /** |
||
63 | * Remove a certain field from the create/update/both forms by its name. |
||
64 | * |
||
65 | * @param string $name Field name (as defined with the addField() procedure) |
||
66 | * @param string $form update/create/both |
||
67 | */ |
||
68 | public function removeField($name, $form = 'both') |
||
85 | |||
86 | /** |
||
87 | * Remove many fields from the create/update/both forms by their name. |
||
88 | * |
||
89 | * @param array $array_of_names A simple array of the names of the fields to be removed. |
||
90 | * @param string $form update/create/both |
||
91 | */ |
||
92 | public function removeFields($array_of_names, $form = 'both') |
||
100 | |||
101 | /** |
||
102 | * Check if field is the first of its type in the given fields array. |
||
103 | * 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). |
||
104 | * |
||
105 | * @param array $field The current field being tested if it's the first of its type. |
||
106 | * @param array $fields_array All the fields in that particular form. |
||
107 | * |
||
108 | * @return bool true/false |
||
109 | */ |
||
110 | public function checkIfFieldIsFirstOfItsType($field, $fields_array) |
||
118 | |||
119 | /** |
||
120 | * Order the fields in a certain way. |
||
121 | * |
||
122 | * @param [string] Column name. |
||
123 | * @param [attributes and values array] |
||
124 | */ |
||
125 | public function setFieldOrder($fields) |
||
129 | |||
130 | // ALIAS of setFieldOrder($fields) |
||
131 | public function setFieldsOrder($fields) |
||
135 | |||
136 | // ------------ |
||
137 | // TONE FUNCTIONS - UNDOCUMENTED, UNTESTED, SOME MAY BE USED |
||
138 | // ------------ |
||
139 | // TODO: check them |
||
140 | |||
141 | public function orderFields($order) |
||
145 | |||
146 | public function mutateFieldData($data, $fields) |
||
164 | } |
||
165 |
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.