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