| Conditions | 9 |
| Paths | 9 |
| Total Lines | 51 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 32 | public function execute(MigrationStep $step) |
||
| 33 | { |
||
| 34 | parent::execute($step); |
||
| 35 | |||
| 36 | if (!isset($step->dsl['repeat']) || $step->dsl['repeat'] < 0) { |
||
| 37 | throw new \Exception("Invalid step definition: missing 'repeat' or not a positive integer"); |
||
| 38 | } |
||
| 39 | |||
| 40 | if (!isset($step->dsl['steps']) || !is_array($step->dsl['steps'])) { |
||
| 41 | throw new \Exception("Invalid step definition: missing 'steps' or not an array"); |
||
| 42 | } |
||
| 43 | |||
| 44 | // no need for a 'mode' for now |
||
| 45 | /*$action = $step->dsl['mode']; |
||
|
|
|||
| 46 | |||
| 47 | if (!in_array($action, $this->supportedActions)) { |
||
| 48 | throw new \Exception("Invalid step definition: value '$action' is not allowed for 'mode'"); |
||
| 49 | }*/ |
||
| 50 | |||
| 51 | $this->skipStepIfNeeded($step); |
||
| 52 | |||
| 53 | // before engaging in the loop, check that all steps are valid |
||
| 54 | $stepExecutors = array(); |
||
| 55 | foreach ($step->dsl['steps'] as $i => $stepDef) { |
||
| 56 | $type = $stepDef['type']; |
||
| 57 | try { |
||
| 58 | $stepExecutors[$i] = $this->migrationService->getExecutor($type); |
||
| 59 | } catch (\InvalidArgumentException $e) { |
||
| 60 | throw new \InvalidArgumentException($e->getMessage() . " in sub-step of a loop step"); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | $this->loopResolver->beginLoop(); |
||
| 65 | $result = null; |
||
| 66 | |||
| 67 | // NB: we are *not* firing events for each pass of the loop... it might be worth making that optionally happen ? |
||
| 68 | for ($i = 0; $i < $step->dsl['repeat']; $i++) { |
||
| 69 | |||
| 70 | $this->loopResolver->loopStep(); |
||
| 71 | |||
| 72 | foreach ($step->dsl['steps'] as $j => $stepDef) { |
||
| 73 | $type = $stepDef['type']; |
||
| 74 | unset($stepDef['type']); |
||
| 75 | $subStep = new MigrationStep($type, $stepDef, array_merge($step->context, array())); |
||
| 76 | $result = $stepExecutors[$j]->execute($subStep); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | $this->loopResolver->endLoop(); |
||
| 81 | return $result; |
||
| 82 | } |
||
| 83 | |||
| 85 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.