Conditions | 9 |
Paths | 10 |
Total Lines | 56 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
95 | public function execute(): mixed |
||
96 | { |
||
97 | $type = $this->getArgumentValue('type'); |
||
98 | |||
99 | $io = $this->io(); |
||
100 | $writer = $io->writer(); |
||
101 | $writer->boldYellow('MIGRATION EXECUTION', true)->eol(); |
||
102 | |||
103 | $migrations = $this->getMigrations(); |
||
104 | $executed = $this->getExecuted('DESC'); |
||
105 | $version = $this->getOptionValue('id'); |
||
106 | |||
107 | if ($type === 'up') { |
||
108 | $diff = array_diff_key($migrations, $executed); |
||
109 | if (count($diff) === 0) { |
||
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 (count($executed) === 0) { |
||
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 | } |
||
147 | } |
||
148 | } |
||
149 | |||
150 | return true; |
||
151 | } |
||
207 |