Conditions | 4 |
Paths | 3 |
Total Lines | 52 |
Code Lines | 40 |
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 |
||
19 | public function up(Schema $schema): void |
||
20 | { |
||
21 | $settings = [ |
||
22 | [ |
||
23 | 'name' => 'disclose_ai_assistance', |
||
24 | 'title' => 'Disclose AI assistance', |
||
25 | 'comment' => 'Show a tag on any content or feedback that has been generated or co-generated by any AI system, evidencing to the user that the content was built with the help of some AI system. Details about which AI system was used in which case are kept inside the database for audit, but are not directly accessible by the final user.', |
||
26 | ], |
||
27 | ]; |
||
28 | |||
29 | foreach ($settings as $setting) { |
||
30 | $variable = addslashes($setting['name']); |
||
31 | $title = addslashes($setting['title']); |
||
32 | $comment = addslashes($setting['comment']); |
||
33 | |||
34 | $sqlCheck = \sprintf( |
||
35 | "SELECT COUNT(*) AS count |
||
36 | FROM settings |
||
37 | WHERE variable = '%s' |
||
38 | AND subkey IS NULL |
||
39 | AND access_url = 1", |
||
40 | $variable |
||
41 | ); |
||
42 | |||
43 | $stmt = $this->connection->executeQuery($sqlCheck); |
||
44 | $result = $stmt->fetchAssociative(); |
||
45 | |||
46 | if ($result && (int) $result['count'] > 0) { |
||
47 | $this->addSql(\sprintf( |
||
48 | "UPDATE settings |
||
49 | SET title = '%s', |
||
50 | comment = '%s', |
||
51 | category = 'ai_helpers' |
||
52 | WHERE variable = '%s' |
||
53 | AND subkey IS NULL |
||
54 | AND access_url = 1", |
||
55 | $title, |
||
56 | $comment, |
||
57 | $variable |
||
58 | )); |
||
59 | $this->write(\sprintf('Updated setting: %s', $setting['name'])); |
||
60 | } else { |
||
61 | $this->addSql(\sprintf( |
||
62 | "INSERT INTO settings |
||
63 | (variable, subkey, type, category, selected_value, title, comment, access_url_changeable, access_url_locked, access_url) |
||
64 | VALUES |
||
65 | ('%s', NULL, NULL, 'ai_helpers', 'true', '%s', '%s', 1, 0, 1)", |
||
66 | $variable, |
||
67 | $title, |
||
68 | $comment |
||
69 | )); |
||
70 | $this->write(\sprintf('Inserted setting: %s', $setting['name'])); |
||
71 | } |
||
94 |