Conditions | 11 |
Paths | 3 |
Total Lines | 36 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 | foreach ($extraFields as $field) { |
||
26 | $existingField = $this->connection->executeQuery( |
||
27 | 'SELECT * FROM extra_field WHERE variable = :variable AND item_type = :item_type', |
||
28 | [ |
||
29 | 'variable' => $field['variable'], |
||
30 | 'item_type' => $field['item_type'], |
||
31 | ] |
||
32 | )->fetchAssociative(); |
||
33 | |||
34 | if (!$existingField) { |
||
35 | // Insert new field if it does not exist |
||
36 | $this->connection->insert('extra_field', [ |
||
37 | 'item_type' => $field['item_type'], |
||
38 | 'value_type' => $field['value_type'], |
||
39 | 'variable' => $field['variable'], |
||
40 | 'display_text' => $field['display_text'], |
||
41 | 'visible_to_self' => isset($field['visible_to_self']) ? (int) $field['visible_to_self'] : 0, |
||
42 | 'visible_to_others' => isset($field['visible_to_others']) ? (int) $field['visible_to_others'] : 0, |
||
43 | 'changeable' => isset($field['changeable']) ? (int) $field['changeable'] : 0, |
||
44 | 'filter' => isset($field['filter']) ? (int) $field['filter'] : 0, |
||
45 | 'created_at' => (new DateTime())->format('Y-m-d H:i:s'), |
||
46 | ]); |
||
47 | } else { |
||
48 | // Update existing field |
||
49 | $this->connection->update('extra_field', [ |
||
50 | 'display_text' => $field['display_text'], |
||
51 | 'visible_to_self' => isset($field['visible_to_self']) ? (int) $field['visible_to_self'] : 0, |
||
52 | 'visible_to_others' => isset($field['visible_to_others']) ? (int) $field['visible_to_others'] : 0, |
||
53 | 'changeable' => isset($field['changeable']) ? (int) $field['changeable'] : 0, |
||
54 | 'filter' => isset($field['filter']) ? (int) $field['filter'] : 0, |
||
55 | ], [ |
||
56 | 'id' => $existingField['id'], |
||
57 | ]); |
||
64 |