| Conditions | 10 |
| Paths | 25 |
| Total Lines | 37 |
| Code Lines | 22 |
| 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 |
||
| 90 | public function down(Schema $schema): void |
||
| 91 | { |
||
| 92 | // Re-introduce configuration.tool_enable from active as 'true'/'false' |
||
| 93 | $conn = $this->connection; |
||
| 94 | |||
| 95 | $rows = $conn->fetchAllAssociative('SELECT id, active, configuration FROM access_url_rel_plugin'); |
||
| 96 | |||
| 97 | foreach ($rows as $row) { |
||
| 98 | $id = (int) $row['id']; |
||
| 99 | $active = isset($row['active']) ? (int) $row['active'] : 0; |
||
| 100 | $cfgRaw = $row['configuration']; |
||
| 101 | $cfg = []; |
||
| 102 | |||
| 103 | if (is_string($cfgRaw) && $cfgRaw !== '') { |
||
| 104 | $decoded = json_decode($cfgRaw, true); |
||
| 105 | if (is_array($decoded)) { |
||
| 106 | $cfg = $decoded; |
||
| 107 | } |
||
| 108 | } elseif (is_array($cfgRaw)) { |
||
| 109 | $cfg = $cfgRaw; |
||
| 110 | } |
||
| 111 | |||
| 112 | // Do not overwrite if it already exists (unlikely after up()) |
||
| 113 | if (!array_key_exists('tool_enable', $cfg)) { |
||
| 114 | $cfg['tool_enable'] = $active ? 'true' : 'false'; |
||
| 115 | } |
||
| 116 | |||
| 117 | $payload = json_encode($cfg, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
||
| 118 | |||
| 119 | $conn->update( |
||
| 120 | 'access_url_rel_plugin', |
||
| 121 | ['configuration' => $payload], |
||
| 122 | ['id' => $id], |
||
| 123 | ['configuration' => \PDO::PARAM_STR] |
||
| 124 | ); |
||
| 125 | |||
| 126 | $this->write("Row {$id}: restored configuration.tool_enable='".($active ? 'true' : 'false')."' from active."); |
||
| 127 | } |
||
| 130 |