| Conditions | 9 |
| Paths | 14 |
| Total Lines | 52 |
| Code Lines | 37 |
| 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 |
||
| 94 | public function execute() |
||
| 95 | { |
||
| 96 | $type = $this->getArgumentValue('type'); |
||
| 97 | |||
| 98 | $io = $this->io(); |
||
| 99 | $writer = $io->writer(); |
||
| 100 | $writer->boldYellow('MIGRATION EXECUTION', true)->eol(); |
||
| 101 | |||
| 102 | $migrations = $this->getMigrations(); |
||
| 103 | $executed = $this->getExecuted('DESC'); |
||
| 104 | |||
| 105 | $version = $this->getOptionValue('id'); |
||
| 106 | |||
| 107 | if ($type === 'up') { |
||
| 108 | $diff = array_diff_key($migrations, $executed); |
||
| 109 | if (empty($diff)) { |
||
| 110 | $writer->boldGreen('Migration already up to date'); |
||
| 111 | } else { |
||
| 112 | if (empty($version)) { |
||
| 113 | $version = $io->choice('Choose which version to migrate up', $diff); |
||
| 114 | } |
||
| 115 | |||
| 116 | if (!isset($diff[$version])) { |
||
| 117 | $writer->boldRed(sprintf( |
||
| 118 | 'Invalid migration version [%s] or already executed', |
||
| 119 | $version |
||
| 120 | )); |
||
| 121 | } else { |
||
| 122 | $description = str_replace('_', ' ', $migrations[$version]); |
||
| 123 | $this->executeMigrationUp($version, $description); |
||
|
|
|||
| 124 | } |
||
| 125 | } |
||
| 126 | } else { |
||
| 127 | if (empty($executed)) { |
||
| 128 | $writer->boldGreen('No migration to rollback'); |
||
| 129 | } else { |
||
| 130 | $data = []; |
||
| 131 | foreach ($executed as $ver => $entity) { |
||
| 132 | $data[$ver] = $entity->description; |
||
| 133 | } |
||
| 134 | if (empty($version)) { |
||
| 135 | $version = $io->choice('Choose which version to rollback', $data); |
||
| 136 | } |
||
| 137 | |||
| 138 | if (!isset($data[$version])) { |
||
| 139 | $writer->boldRed(sprintf( |
||
| 140 | 'Invalid migration version [%s] or not yet executed', |
||
| 141 | $version |
||
| 142 | )); |
||
| 143 | } else { |
||
| 144 | $description = str_replace('_', ' ', $data[$version]); |
||
| 145 | $this->executeMigrationDown($version, $description); |
||
| 146 | } |
||
| 205 |