| Conditions | 15 |
| Paths | 74 |
| Total Lines | 58 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 21 | public function up(Schema $schema): void |
||
| 22 | { |
||
| 23 | $extraFields = ExtraFieldFixtures::getExtraFields(); |
||
| 24 | |||
| 25 | $protectedFlagsVars = ['my_terms', 'terms_ville', 'terms_villedustage']; |
||
| 26 | |||
| 27 | foreach ($extraFields as $field) { |
||
| 28 | $existingField = $this->connection->executeQuery( |
||
| 29 | 'SELECT * FROM extra_field WHERE variable = :variable AND item_type = :item_type', |
||
| 30 | [ |
||
| 31 | 'variable' => $field['variable'], |
||
| 32 | 'item_type' => $field['item_type'], |
||
| 33 | ] |
||
| 34 | )->fetchAssociative(); |
||
| 35 | |||
| 36 | if (!$existingField) { |
||
| 37 | // Insert new field if it does not exist |
||
| 38 | $this->connection->insert('extra_field', [ |
||
| 39 | 'item_type' => $field['item_type'], |
||
| 40 | 'value_type' => $field['value_type'], |
||
| 41 | 'variable' => $field['variable'], |
||
| 42 | 'display_text' => $field['display_text'], |
||
| 43 | 'visible_to_self' => isset($field['visible_to_self']) ? (int) $field['visible_to_self'] : 0, |
||
| 44 | 'visible_to_others'=> isset($field['visible_to_others'])? (int) $field['visible_to_others']: 0, |
||
| 45 | 'changeable' => isset($field['changeable']) ? (int) $field['changeable'] : 0, |
||
| 46 | 'filter' => isset($field['filter']) ? (int) $field['filter'] : 0, |
||
| 47 | 'created_at' => (new \DateTime())->format('Y-m-d H:i:s'), |
||
| 48 | ]); |
||
| 49 | continue; |
||
| 50 | } |
||
| 51 | |||
| 52 | $updateData = [ |
||
| 53 | 'display_text' => $field['display_text'], |
||
| 54 | ]; |
||
| 55 | |||
| 56 | if (isset($field['filter'])) { |
||
| 57 | $updateData['filter'] = (int) $field['filter']; |
||
| 58 | } |
||
| 59 | |||
| 60 | if (isset($field['value_type']) && (int)$existingField['value_type'] !== (int)$field['value_type']) { |
||
| 61 | $updateData['value_type'] = (int)$field['value_type']; |
||
| 62 | } |
||
| 63 | |||
| 64 | if (!in_array($field['variable'], $protectedFlagsVars, true)) { |
||
| 65 | if (array_key_exists('visible_to_self', $field)) { |
||
| 66 | $updateData['visible_to_self'] = (int) $field['visible_to_self']; |
||
| 67 | } |
||
| 68 | if (array_key_exists('visible_to_others', $field)) { |
||
| 69 | $updateData['visible_to_others'] = (int) $field['visible_to_others']; |
||
| 70 | } |
||
| 71 | if (array_key_exists('changeable', $field)) { |
||
| 72 | $updateData['changeable'] = (int) $field['changeable']; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | if (!empty($updateData)) { |
||
| 77 | $this->connection->update('extra_field', $updateData, [ |
||
| 78 | 'id' => $existingField['id'], |
||
| 79 | ]); |
||
| 86 |