| Conditions | 16 |
| Paths | 207 |
| Total Lines | 72 |
| Code Lines | 40 |
| Lines | 6 |
| Ratio | 8.33 % |
| 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 |
||
| 57 | public function migrate() |
||
| 58 | { |
||
| 59 | $factory = DocBlockFactory::createInstance(); |
||
| 60 | |||
| 61 | $schema = $this->mapper->getSchema(); |
||
| 62 | |||
| 63 | foreach ($this->entities as $entity) { |
||
| 64 | $spaceName = $this->getSpaceName($entity); |
||
| 65 | $space = $schema->hasSpace($spaceName) ? $schema->getSpace($spaceName) : $schema->createSpace($spaceName); |
||
| 66 | |||
| 67 | $this->mapEntity($spaceName, $entity); |
||
| 68 | |||
| 69 | $class = new ReflectionClass($entity); |
||
| 70 | |||
| 71 | foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { |
||
| 72 | $description = $factory->create($property->getDocComment()); |
||
| 73 | $tags = $description->getTags('var'); |
||
| 74 | |||
| 75 | View Code Duplication | if (!count($tags)) { |
|
| 76 | throw new Exception("No var tag for ".$entity.'::'.$property->getName()); |
||
| 77 | } |
||
| 78 | |||
| 79 | View Code Duplication | if (count($tags) > 1) { |
|
| 80 | throw new Exception("Invalid var tag for ".$entity.'::'.$property->getName()); |
||
| 81 | } |
||
| 82 | |||
| 83 | $property = $this->toUnderscore($property->getName()); |
||
| 84 | $type = $this->getTarantoolType($tags[0]->getType()); |
||
| 85 | |||
| 86 | if (!$space->hasProperty($property)) { |
||
| 87 | $space->addProperty($property, $type); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | foreach ($this->repositories as $repository) { |
||
| 93 | $spaceName = $this->getSpaceName($repository); |
||
| 94 | |||
| 95 | if (!$schema->hasSpace($spaceName)) { |
||
| 96 | throw new Exception("Repository with no entity definition"); |
||
| 97 | } |
||
| 98 | |||
| 99 | $this->mapRepository($spaceName, $repository); |
||
| 100 | |||
| 101 | $space = $schema->getSpace($spaceName); |
||
| 102 | $properties = $class->getDefaultProperties(); |
||
| 103 | if (array_key_exists('indexes', $properties)) { |
||
| 104 | foreach ($properties['indexes'] as $index) { |
||
| 105 | if (!is_array($index)) { |
||
| 106 | $index = (array) $index; |
||
| 107 | } |
||
| 108 | if (!array_key_exists('fields', $index)) { |
||
| 109 | $index = ['fields' => $index]; |
||
| 110 | } |
||
| 111 | |||
| 112 | $index['if_not_exists'] = true; |
||
| 113 | $space->addIndex($index); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | foreach ($schema->getSpaces() as $space) { |
||
| 119 | if (!count($space->getIndexes())) { |
||
| 120 | if (!$space->hasProperty('id')) { |
||
| 121 | throw new Exception("No primary index on ". $space->getName()); |
||
| 122 | } |
||
| 123 | $space->addIndex(['id']); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | return $this; |
||
| 128 | } |
||
| 129 | |||
| 222 |