Completed
Push — master ( b58579...24ecb0 )
by Dmitry
02:12
created
src/Plugins/Annotation.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -25,27 +25,27 @@  discard block
 block discarded – undo
25 25
         $isEntity = is_subclass_of($class, Entity::class);
26 26
         $isRepository = is_subclass_of($class, Repository::class);
27 27
 
28
-        if(!$isEntity && !$isRepository) {
28
+        if (!$isEntity && !$isRepository) {
29 29
             throw new Exception("Invalid registration");
30 30
         }
31 31
 
32
-        if($isEntity) {
33
-            if($class == Entity::class) {
32
+        if ($isEntity) {
33
+            if ($class == Entity::class) {
34 34
                 throw new Exception("Invalid entity registration");
35 35
             }
36 36
             $this->entities[] = $class;
37 37
         }
38 38
 
39
-        if($isRepository) {
40
-            if($class == Repository::class) {
39
+        if ($isRepository) {
40
+            if ($class == Repository::class) {
41 41
                 throw new Exception("Invalid repository registration");
42 42
             }
43 43
             $this->repositories[] = $class;
44 44
         }
45 45
 
46 46
         $space = $this->getSpaceName($class);
47
-        if($this->mapper->getSchema()->hasSpace($space)) {
48
-            if($isEntity) {
47
+        if ($this->mapper->getSchema()->hasSpace($space)) {
48
+            if ($isEntity) {
49 49
                 $this->mapEntity($space, $class);
50 50
             } else {
51 51
                 $this->mapRepository($space, $class);
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 
61 61
         $schema = $this->mapper->getSchema();
62 62
 
63
-        foreach($this->entities as $entity) {
63
+        foreach ($this->entities as $entity) {
64 64
 
65 65
             $spaceName = $this->getSpaceName($entity);
66 66
             $space = $schema->hasSpace($spaceName) ? $schema->getSpace($spaceName) : $schema->createSpace($spaceName);
@@ -69,33 +69,33 @@  discard block
 block discarded – undo
69 69
 
70 70
             $class = new ReflectionClass($entity);
71 71
 
72
-            foreach($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
72
+            foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
73 73
 
74 74
                 $description = $factory->create($property->getDocComment());
75 75
                 $tags = $description->getTags('var');
76 76
 
77
-                if(!count($tags)) {
77
+                if (!count($tags)) {
78 78
                     throw new Exception("No var tag for ".$entity.'::'.$property->getName());
79 79
                 }
80 80
 
81
-                if(count($tags) > 1) {
81
+                if (count($tags) > 1) {
82 82
                     throw new Exception("Invalid var tag for ".$entity.'::'.$property->getName());
83 83
                 }
84 84
 
85 85
                 $property = $this->toUnderscore($property->getName());
86 86
                 $type = $this->getTarantoolType($tags[0]->getType());
87 87
 
88
-                if(!$space->hasProperty($property)) {
88
+                if (!$space->hasProperty($property)) {
89 89
                     $space->addProperty($property, $type);
90 90
                 }
91 91
             }
92 92
         }
93 93
 
94
-        foreach($this->repositories as $repository) {
94
+        foreach ($this->repositories as $repository) {
95 95
 
96 96
             $spaceName = $this->getSpaceName($repository);
97 97
 
98
-            if(!$schema->hasSpace($spaceName)) {
98
+            if (!$schema->hasSpace($spaceName)) {
99 99
                 throw new Exception("Repository with no entity definition");
100 100
             }
101 101
 
@@ -103,12 +103,12 @@  discard block
 block discarded – undo
103 103
 
104 104
             $space = $schema->getSpace($spaceName);
105 105
             $properties = $class->getDefaultProperties();
106
-            if(array_key_exists('indexes', $properties)) {
107
-                foreach($properties['indexes'] as $index) {
108
-                    if(!is_array($index)) {
106
+            if (array_key_exists('indexes', $properties)) {
107
+                foreach ($properties['indexes'] as $index) {
108
+                    if (!is_array($index)) {
109 109
                         $index = (array) $index;
110 110
                     }
111
-                    if(!array_key_exists('fields', $index)) {
111
+                    if (!array_key_exists('fields', $index)) {
112 112
                         $index = ['fields' => $index];
113 113
                     }
114 114
 
@@ -118,11 +118,11 @@  discard block
 block discarded – undo
118 118
             }
119 119
         }
120 120
 
121
-        foreach($schema->getSpaces() as $space) {
121
+        foreach ($schema->getSpaces() as $space) {
122 122
 
123
-            if(!count($space->getIndexes())) {
124
-                if(!$space->hasProperty('id')) {
125
-                    throw new Exception("No primary index on ". $space->getName());
123
+            if (!count($space->getIndexes())) {
124
+                if (!$space->hasProperty('id')) {
125
+                    throw new Exception("No primary index on ".$space->getName());
126 126
                 }
127 127
                 $space->addIndex(['id']);
128 128
             }
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     public function getRepositoryMapping()
147 147
     {
148 148
         $mapping = [];
149
-        foreach($this->repositories as $class) {
149
+        foreach ($this->repositories as $class) {
150 150
             $mapping[$this->getSpaceName($class)] = $class;
151 151
         }
152 152
         return $mapping;
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
     public function getEntityMapping()
156 156
     {
157 157
         $mapping = [];
158
-        foreach($this->entities as $class) {
158
+        foreach ($this->entities as $class) {
159 159
             $mapping[$this->getSpaceName($class)] = $class;
160 160
         }
161 161
         return $mapping;
@@ -165,19 +165,19 @@  discard block
 block discarded – undo
165 165
 
166 166
     private function getSpaceName($class)
167 167
     {
168
-        if(!array_key_exists($class, $this->spaceNames)) {
168
+        if (!array_key_exists($class, $this->spaceNames)) {
169 169
 
170 170
             $reflection = new ReflectionClass($class);
171 171
             $className = $reflection->getShortName();
172 172
 
173
-            if($reflection->isSubclassOf(Repository::class)) {
174
-                if($this->repositoryPostifx) {
173
+            if ($reflection->isSubclassOf(Repository::class)) {
174
+                if ($this->repositoryPostifx) {
175 175
                     $className = substr($className, 0, strlen($className) - strlen($this->repositoryPostifx));
176 176
                 }
177 177
             }
178 178
 
179
-            if($reflection->isSubclassOf(Entity::class)) {
180
-                if($this->entityPostfix) {
179
+            if ($reflection->isSubclassOf(Entity::class)) {
180
+                if ($this->entityPostfix) {
181 181
                     $className = substr($className, 0, strlen($className) - strlen($this->entityPostfix));
182 182
                 }
183 183
             }
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
     private function toUnderscore($input)
194 194
     {
195
-        if(!array_key_exists($input, $this->underscores)) {
195
+        if (!array_key_exists($input, $this->underscores)) {
196 196
             preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
197 197
             $ret = $matches[0];
198 198
             foreach ($ret as &$match) {
@@ -207,15 +207,15 @@  discard block
 block discarded – undo
207 207
 
208 208
     private function getTarantoolType(string $type)
209 209
     {
210
-        if(array_key_exists($type, $this->tarantoolTypes)) {
210
+        if (array_key_exists($type, $this->tarantoolTypes)) {
211 211
             return $this->tarantoolTypes[$type];
212 212
         }
213 213
 
214
-        if($type[0] == '\\') {
214
+        if ($type[0] == '\\') {
215 215
             return $this->tarantoolTypes[$type] = 'unsigned';
216 216
         }
217 217
 
218
-        switch($type) {
218
+        switch ($type) {
219 219
             case 'int':
220 220
                 return $this->tarantoolTypes[$type] = 'unsigned';
221 221
 
Please login to merge, or discard this patch.