| Conditions | 16 |
| Paths | 207 |
| Total Lines | 75 |
| Code Lines | 41 |
| Lines | 6 |
| Ratio | 8 % |
| 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 |
||
| 72 | public function migrate() |
||
| 73 | { |
||
| 74 | $factory = DocBlockFactory::createInstance(); |
||
| 75 | |||
| 76 | $schema = $this->mapper->getSchema(); |
||
| 77 | |||
| 78 | foreach ($this->entityClasses as $entity) { |
||
| 79 | $spaceName = $this->getSpaceName($entity); |
||
| 80 | $space = $schema->hasSpace($spaceName) ? $schema->getSpace($spaceName) : $schema->createSpace($spaceName); |
||
| 81 | |||
| 82 | $this->mapEntity($spaceName, $entity); |
||
| 83 | |||
| 84 | $class = new ReflectionClass($entity); |
||
| 85 | |||
| 86 | foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { |
||
| 87 | $description = $factory->create($property->getDocComment()); |
||
| 88 | $tags = $description->getTags('var'); |
||
| 89 | |||
| 90 | View Code Duplication | if (!count($tags)) { |
|
| 91 | throw new Exception("No var tag for ".$entity.'::'.$property->getName()); |
||
| 92 | } |
||
| 93 | |||
| 94 | View Code Duplication | if (count($tags) > 1) { |
|
| 95 | throw new Exception("Invalid var tag for ".$entity.'::'.$property->getName()); |
||
| 96 | } |
||
| 97 | |||
| 98 | $property = $this->toUnderscore($property->getName()); |
||
| 99 | $type = $this->getTarantoolType($tags[0]->getType()); |
||
| 100 | |||
| 101 | if (!$space->hasProperty($property)) { |
||
| 102 | $space->addProperty($property, $type); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | foreach ($this->repositoryClasses as $repository) { |
||
| 108 | $spaceName = $this->getSpaceName($repository); |
||
| 109 | |||
| 110 | if (!$schema->hasSpace($spaceName)) { |
||
| 111 | throw new Exception("Repository with no entity definition"); |
||
| 112 | } |
||
| 113 | |||
| 114 | $this->mapRepository($spaceName, $repository); |
||
| 115 | |||
| 116 | $space = $schema->getSpace($spaceName); |
||
| 117 | |||
| 118 | $class = new ReflectionClass($repository); |
||
| 119 | $properties = $class->getDefaultProperties(); |
||
| 120 | |||
| 121 | if (array_key_exists('indexes', $properties)) { |
||
| 122 | foreach ($properties['indexes'] as $index) { |
||
| 123 | if (!is_array($index)) { |
||
| 124 | $index = (array) $index; |
||
| 125 | } |
||
| 126 | if (!array_key_exists('fields', $index)) { |
||
| 127 | $index = ['fields' => $index]; |
||
| 128 | } |
||
| 129 | |||
| 130 | $index['if_not_exists'] = true; |
||
| 131 | $space->addIndex($index); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | foreach ($schema->getSpaces() as $space) { |
||
| 137 | if (!count($space->getIndexes())) { |
||
| 138 | if (!$space->hasProperty('id')) { |
||
| 139 | throw new Exception("No primary index on ". $space->getName()); |
||
| 140 | } |
||
| 141 | $space->addIndex(['id']); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | return $this; |
||
| 146 | } |
||
| 147 | |||
| 227 |