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