| Conditions | 9 |
| Paths | 12 |
| Total Lines | 67 |
| Code Lines | 44 |
| 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 |
||
| 12 | protected function parseMigrationDefinitionData($data, MigrationDefinition $definition, $format = 'Yaml') |
||
| 13 | { |
||
| 14 | $migrationDefinition = parent::parseMigrationDefinitionData($data, $definition, $format); |
||
| 15 | |||
| 16 | $status = $migrationDefinition->status; |
||
| 17 | $steps = $migrationDefinition->steps->getArrayCopy(); |
||
| 18 | $error = $migrationDefinition->parsingError; |
||
| 19 | |||
| 20 | $signalName = ''; |
||
| 21 | // false stands for 'use current user' |
||
| 22 | $user = false; |
||
| 23 | $useTransaction = false; |
||
| 24 | $avoidRecursion = false; |
||
| 25 | |||
| 26 | if ($status == MigrationDefinition::STATUS_PARSED) { |
||
| 27 | |||
| 28 | do { // goto is evil ;-) |
||
| 29 | if (count($steps) < 1) { |
||
| 30 | $status = MigrationDefinition::STATUS_INVALID; |
||
| 31 | $error = "$format file '{$definition->path}' is not a valid workflow definition as it has no workflow manifest"; |
||
| 32 | break; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** @var \Kaliop\eZMigrationBundle\API\Value\MigrationStep $manifestStep */ |
||
| 36 | $manifestStep = $steps[0]; |
||
| 37 | if ($manifestStep->type !== WorkflowDefinition::MANIFEST_STEP_TYPE) { |
||
| 38 | $status = MigrationDefinition::STATUS_INVALID; |
||
| 39 | $error = "$format file '{$definition->path}' is not a valid workflow definition as its 1st step is not the workflow manifest"; |
||
| 40 | break; |
||
| 41 | } |
||
| 42 | |||
| 43 | array_shift($steps); |
||
| 44 | |||
| 45 | $dsl = $manifestStep->dsl; |
||
| 46 | if (!isset($dsl[WorkflowDefinition::MANIFEST_SIGNAL_ELEMENT])) { |
||
| 47 | $status = MigrationDefinition::STATUS_INVALID; |
||
| 48 | $error = "$format file '{$definition->path}' is not a valid workflow definition as its 1st step does not define a signal"; |
||
| 49 | break; |
||
| 50 | } |
||
| 51 | $signalName = $dsl[WorkflowDefinition::MANIFEST_SIGNAL_ELEMENT]; |
||
| 52 | |||
| 53 | if (isset($dsl[WorkflowDefinition::MANIFEST_RUNAS_ELEMENT])) { |
||
| 54 | $user = $dsl[WorkflowDefinition::MANIFEST_RUNAS_ELEMENT]; |
||
| 55 | } |
||
| 56 | |||
| 57 | if (isset($dsl[WorkflowDefinition::MANIFEST_USETRANSACTION_ELEMENT])) { |
||
| 58 | $useTransaction = $dsl[WorkflowDefinition::MANIFEST_USETRANSACTION_ELEMENT]; |
||
| 59 | } |
||
| 60 | |||
| 61 | if (isset($dsl[WorkflowDefinition::MANIFEST_AVOIDRECURSION_ELEMENT])) { |
||
| 62 | $avoidRecursion = $dsl[WorkflowDefinition::MANIFEST_AVOIDRECURSION_ELEMENT]; |
||
| 63 | } |
||
| 64 | |||
| 65 | } while(false); |
||
| 66 | } |
||
| 67 | |||
| 68 | return new WorkflowDefinition( |
||
| 69 | $migrationDefinition->name, |
||
| 70 | $migrationDefinition->path, |
||
| 71 | $migrationDefinition->rawDefinition, |
||
| 72 | $status, |
||
| 73 | $steps, |
||
| 74 | $error, |
||
| 75 | $signalName, |
||
| 76 | $user, |
||
| 77 | $useTransaction, |
||
| 78 | $avoidRecursion |
||
| 79 | ); |
||
| 82 |