Conditions | 17 |
Paths | 41 |
Total Lines | 55 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
170 | public function cleanFields(&$fieldData, $leadField) |
||
171 | { |
||
172 | // This will catch null values or non-existent values to prevent null from converting to false/0 |
||
173 | if (!isset($fieldData[$leadField['alias']])) { |
||
174 | return; |
||
175 | } |
||
176 | |||
177 | switch ($leadField['type']) { |
||
178 | // Adjust the boolean values from text to boolean. Do not convert null to false. |
||
179 | case 'boolean': |
||
180 | $fieldData[$leadField['alias']] = (int) filter_var($fieldData[$leadField['alias']], FILTER_VALIDATE_BOOLEAN); |
||
181 | break; |
||
182 | // Ensure date/time entries match what symfony expects |
||
183 | case 'datetime': |
||
184 | case 'date': |
||
185 | case 'time': |
||
186 | // Prevent zero based date placeholders |
||
187 | $dateTest = (int) str_replace(['/', '-', ' '], '', $fieldData[$leadField['alias']]); |
||
188 | if (!$dateTest) { |
||
189 | // Date placeholder was used so just ignore it to allow import of the field |
||
190 | unset($fieldData[$leadField['alias']]); |
||
191 | } else { |
||
192 | if (false === ($timestamp = strtotime($fieldData[$leadField['alias']]))) { |
||
193 | $timestamp = null; |
||
194 | } |
||
195 | if ($timestamp) { |
||
196 | switch ($leadField['type']) { |
||
197 | case 'datetime': |
||
198 | $fieldData[$leadField['alias']] = (new \DateTime(date('Y-m-d H:i:s', $timestamp)))->format('Y-m-d H:i:s'); |
||
199 | break; |
||
200 | case 'date': |
||
201 | $fieldData[$leadField['alias']] = (new \DateTime(date('Y-m-d', $timestamp)))->format('Y-m-d'); |
||
202 | break; |
||
203 | case 'time': |
||
204 | $fieldData[$leadField['alias']] = (new \DateTime(date('H:i:s', $timestamp)))->format('H:i:s'); |
||
205 | break; |
||
206 | } |
||
207 | } |
||
208 | } |
||
209 | break; |
||
210 | case 'multiselect': |
||
211 | if (!is_array($fieldData[$leadField['alias']])) { |
||
212 | if (false !== strpos($fieldData[$leadField['alias']], '|')) { |
||
213 | $fieldData[$leadField['alias']] = explode('|', $fieldData[$leadField['alias']]); |
||
214 | } else { |
||
215 | $fieldData[$leadField['alias']] = [$fieldData[$leadField['alias']]]; |
||
216 | } |
||
217 | } |
||
218 | break; |
||
219 | case 'number': |
||
220 | $fieldData[$leadField['alias']] = (float) $fieldData[$leadField['alias']]; |
||
221 | break; |
||
222 | case 'email': |
||
223 | $fieldData[$leadField['alias']] = InputHelper::email($fieldData[$leadField['alias']]); |
||
224 | break; |
||
225 | } |
||
228 |