| Conditions | 10 |
| Paths | 164 |
| Total Lines | 42 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| 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 |
||
| 66 | private function execute($version = null, $message = null) |
||
| 67 | { |
||
| 68 | $migrateUp = null === $version || $version > $this->schemaTable->getCurrentVersion(); |
||
| 69 | $files = $this->migrationFiles->get($version); |
||
| 70 | if (null === $files) { |
||
| 71 | return 0; |
||
| 72 | } |
||
| 73 | $this->schemaManipulation->execute('BEGIN'); |
||
| 74 | try { |
||
| 75 | foreach ($files as $file) { |
||
| 76 | |||
| 77 | require_once $file->getPath(); |
||
| 78 | |||
| 79 | $definition = $this->createMigrationApiInstance($file->getClassName()); |
||
| 80 | |||
| 81 | if ($message) { |
||
| 82 | $message($file->getName(), $file->getVersion()); |
||
| 83 | } |
||
| 84 | if ($migrateUp) { |
||
| 85 | $definition->up(); |
||
| 86 | } else { |
||
| 87 | $definition->down(); |
||
| 88 | } |
||
| 89 | foreach ($definition->getActions() as $action) { |
||
| 90 | if (!is_callable($action)) { |
||
| 91 | throw new \InvalidArgumentException('Migration must be callable'); |
||
| 92 | } |
||
| 93 | $action = call_user_func_array($action, array()); |
||
| 94 | if ($action instanceof MigrationApi) { |
||
| 95 | $action->execute(); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | $this->schemaTable->migrateToVersion($file->getVersion()); |
||
| 99 | } |
||
| 100 | $this->schemaManipulation->execute('COMMIT'); |
||
| 101 | } catch (\Exception $e) { |
||
| 102 | $this->schemaManipulation->execute('ROLLBACK'); |
||
| 103 | throw $e; |
||
| 104 | } |
||
| 105 | |||
| 106 | return count($files); |
||
| 107 | } |
||
| 108 | } |
||
| 109 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: