Conditions | 14 |
Paths | 123 |
Total Lines | 66 |
Code Lines | 35 |
Lines | 6 |
Ratio | 9.09 % |
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 |
||
54 | public function migrate() |
||
55 | { |
||
56 | $factory = DocBlockFactory::createInstance(); |
||
57 | |||
58 | $schema = $this->mapper->getSchema(); |
||
59 | |||
60 | foreach($this->entities as $entity) { |
||
61 | |||
62 | $class = new ReflectionClass($entity); |
||
63 | $spaceName = $this->toUnderscore($class->getShortName()); |
||
64 | |||
65 | $space = $schema->hasSpace($spaceName) ? $schema->getSpace($spaceName) : $schema->createSpace($spaceName); |
||
66 | $this->mapEntity($spaceName, $entity); |
||
67 | |||
68 | foreach($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { |
||
69 | |||
70 | $description = $factory->create($property->getDocComment()); |
||
71 | $tags = $description->getTags('var'); |
||
72 | |||
73 | View Code Duplication | if(!count($tags)) { |
|
74 | throw new Exception("No var tag for ".$entity.'::'.$property->getName()); |
||
75 | } |
||
76 | |||
77 | View Code Duplication | if(count($tags) > 1) { |
|
78 | throw new Exception("Invalid var tag for ".$entity.'::'.$property->getName()); |
||
79 | } |
||
80 | |||
81 | $property = $this->toUnderscore($property->getName()); |
||
82 | $type = $this->getTarantoolType($tags[0]->getType()); |
||
83 | |||
84 | if(!$space->hasProperty($property)) { |
||
85 | $space->addProperty($property, $type); |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | |||
90 | foreach($this->repositories as $repository) { |
||
91 | |||
92 | $class = new ReflectionClass($repository); |
||
93 | $spaceName = $this->toUnderscore($class->getShortName()); |
||
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 | $space->addIndex($index); |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 | |||
110 | foreach($schema->getSpaces() as $space) { |
||
111 | |||
112 | if(!count($space->getIndexes())) { |
||
113 | if(!$space->hasProperty('id')) { |
||
114 | throw new Exception("No primary index on ". $space->getName()); |
||
115 | } |
||
116 | $space->addIndex(['id']); |
||
117 | } |
||
118 | } |
||
119 | } |
||
120 | |||
153 |