Completed
Push — master ( edbb5b...b58579 )
by Dmitry
02:08
created
src/Client.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -31,6 +31,9 @@
 block discarded – undo
31 31
         return $response;
32 32
     }
33 33
 
34
+    /**
35
+     * @param double $start
36
+     */
34 37
     private function log($start, $class, $request = [], $response = [])
35 38
     {
36 39
         if ($this->logging) {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
     public function getTimeSummary()
38 38
     {
39 39
         $summary = 0;
40
-        foreach($this->log as $request) {
40
+        foreach ($this->log as $request) {
41 41
             $summary += $request[0];
42 42
         }
43 43
         return $summary;
Please login to merge, or discard this patch.
src/Mapper.php 2 patches
Doc Comments   +9 added lines patch added patch discarded remove patch
@@ -28,6 +28,9 @@  discard block
 block discarded – undo
28 28
         return $plugin;
29 29
     }
30 30
 
31
+    /**
32
+     * @param string $space
33
+     */
31 34
     public function create($space, $data)
32 35
     {
33 36
         $instance = $this->getRepository($space)->create($data);
@@ -35,11 +38,17 @@  discard block
 block discarded – undo
35 38
         return $instance;
36 39
     }
37 40
 
41
+    /**
42
+     * @param string $space
43
+     */
38 44
     public function findOne($space, $params = [])
39 45
     {
40 46
         return $this->getRepository($space)->findOne($params);
41 47
     }
42 48
 
49
+    /**
50
+     * @param string $space
51
+     */
43 52
     public function find($space, $params = [])
44 53
     {
45 54
         return $this->getRepository($space)->find($params);
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -19,8 +19,8 @@  discard block
 block discarded – undo
19 19
 
20 20
     public function addPlugin($class)
21 21
     {
22
-        if(!is_subclass_of($class, Plugin::class)) {
23
-            throw new Exception("Plugin should extend " . Plugin::class . " class");
22
+        if (!is_subclass_of($class, Plugin::class)) {
23
+            throw new Exception("Plugin should extend ".Plugin::class." class");
24 24
         }
25 25
 
26 26
         $plugin = is_object($class) ? $class : new $class($this);
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
 
49 49
     public function findRepository(Entity $instance)
50 50
     {
51
-        foreach($this->getSchema()->getSpaces() as $space) {
52
-            if($space->getRepository()->knows($instance)) {
51
+        foreach ($this->getSchema()->getSpaces() as $space) {
52
+            if ($space->getRepository()->knows($instance)) {
53 53
                 return $space->getRepository();
54 54
             }
55 55
         }
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 
70 70
     public function getPlugin($class)
71 71
     {
72
-        if(!array_key_exists($class, $this->plugins)) {
72
+        if (!array_key_exists($class, $this->plugins)) {
73 73
             throw new Exception("No plugin $class");
74 74
         }
75 75
         return $this->plugins[$class];
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
     public function getRepositories()
89 89
     {
90 90
         $repositories = [];
91
-        foreach($this->getSchema()->getSpaces() as $space) {
92
-            if($space->repositoryExists()) {
91
+        foreach ($this->getSchema()->getSpaces() as $space) {
92
+            if ($space->repositoryExists()) {
93 93
                 $repositories[] = $space->getRepository();
94 94
             }
95 95
         }
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 
104 104
     public function remove($space, $params = [])
105 105
     {
106
-        if($space instanceof Entity) {
106
+        if ($space instanceof Entity) {
107 107
             $this->findRepository($space)->removeEntity($space);
108 108
 
109 109
         } else {
Please login to merge, or discard this patch.
src/Plugins/Sequence.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -19,6 +19,9 @@
 block discarded – undo
19 19
         }
20 20
     }
21 21
 
22
+    /**
23
+     * @param Space $space
24
+     */
22 25
     private function generateValue($space)
23 26
     {
24 27
         $spaceId = $space->getId();
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@  discard block
 block discarded – undo
11 11
     public function generateKey(Entity $instance, Space $space)
12 12
     {
13 13
         $primary = $space->getPrimaryIndex();
14
-        if(count($primary->parts) == 1) {
14
+        if (count($primary->parts) == 1) {
15 15
             $key = $space->getFormat()[$primary->parts[0][0]]['name'];
16
-            if(!property_exists($instance, $key)) {
16
+            if (!property_exists($instance, $key)) {
17 17
                 $instance->$key = $this->generateValue($space);
18 18
             }
19 19
         }
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
     {
24 24
         $spaceId = $space->getId();
25 25
 
26
-        if(!$this->mapper->getSchema()->hasSpace('sequence')) {
26
+        if (!$this->mapper->getSchema()->hasSpace('sequence')) {
27 27
 
28 28
             $sequence = $this->mapper->getSchema()->createSpace('sequence');
29 29
             $sequence->addProperty('space', 'unsigned');
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
         }
33 33
 
34 34
         $entity = $this->mapper->findOne('sequence', $space->getId());
35
-        if(!$entity) {
35
+        if (!$entity) {
36 36
 
37 37
             $query = "return box.space.".$space->getName().".index[0]:max()";
38 38
             $data = $this->mapper->getClient()->evaluate($query)->getData();
Please login to merge, or discard this patch.
src/Plugins/UserClasses.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -15,14 +15,14 @@  discard block
 block discarded – undo
15 15
 
16 16
     public function getRepositoryClass(Space $space)
17 17
     {
18
-        if(array_key_exists($space->getName(), $this->repositories)) {
18
+        if (array_key_exists($space->getName(), $this->repositories)) {
19 19
             return $this->repositories[$space->getName()];
20 20
         }
21 21
     }
22 22
 
23 23
     public function getEntityClass(Space $space)
24 24
     {
25
-        if(array_key_exists($space->getName(), $this->entities)) {
25
+        if (array_key_exists($space->getName(), $this->entities)) {
26 26
             return $this->entities[$space->getName()];
27 27
         }
28 28
     }
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
     {
32 32
         $this->validateSpace($space);
33 33
 
34
-        if(!class_exists($class)) {
34
+        if (!class_exists($class)) {
35 35
             throw new Exception("No class $class");
36 36
         }
37 37
 
38
-        if(!is_subclass_of($class, Entity::class)) {
39
-            throw new Exception("Entity should extend " . Entity::class . " class");
38
+        if (!is_subclass_of($class, Entity::class)) {
39
+            throw new Exception("Entity should extend ".Entity::class." class");
40 40
         }
41 41
 
42 42
         $this->entities[$space] = $class;
@@ -46,12 +46,12 @@  discard block
 block discarded – undo
46 46
     {
47 47
         $this->validateSpace($space);
48 48
 
49
-        if(!class_exists($class)) {
49
+        if (!class_exists($class)) {
50 50
             throw new Exception("No class $class");
51 51
         }
52 52
 
53
-        if(!is_subclass_of($class, Repository::class)) {
54
-            throw new Exception("Repository should extend " . Repository::class . " class");
53
+        if (!is_subclass_of($class, Repository::class)) {
54
+            throw new Exception("Repository should extend ".Repository::class." class");
55 55
         }
56 56
 
57 57
         $this->repositories[$space] = $class;
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 
60 60
     public function validateSpace($space)
61 61
     {
62
-        if(!$this->mapper->getSchema()->hasSpace($space)) {
62
+        if (!$this->mapper->getSchema()->hasSpace($space)) {
63 63
             throw new Exception("No space $space");
64 64
         }
65 65
     }
Please login to merge, or discard this patch.
src/Bootstrap.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@
 block discarded – undo
20 20
     public function migrate()
21 21
     {
22 22
         $schema = $this->mapper->getSchema();
23
-        foreach($this->migrations as $migration) {
24
-            if(!is_object($migration)) {
23
+        foreach ($this->migrations as $migration) {
24
+            if (!is_object($migration)) {
25 25
                 $migration = new $migration;
26 26
             }
27 27
             $schema->once(get_class($migration), function() use ($migration) {
Please login to merge, or discard this patch.
src/Space.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
     public function addProperties($config)
29 29
     {
30
-        foreach($config as $name => $type) {
30
+        foreach ($config as $name => $type) {
31 31
             $this->addProperty($name, $type);
32 32
         }
33 33
         return $this;
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
     public function addProperty($name, $type)
37 37
     {
38 38
         $format = $this->getFormat();
39
-        foreach($format as $field) {
40
-            if($field['name'] == $name) {
39
+        foreach ($format as $field) {
40
+            if ($field['name'] == $name) {
41 41
                 throw new Exception("Property $name exists");
42 42
             }
43 43
         }
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
     {
55 55
         $format = $this->getFormat();
56 56
         $last = array_pop($format);
57
-        if($last['name'] != $name) {
57
+        if ($last['name'] != $name) {
58 58
             throw new Exception("Remove only last property");
59 59
         }
60 60
         $this->mapper->getClient()->evaluate("box.space[$this->id]:format(...)", [$format]);
@@ -82,13 +82,13 @@  discard block
 block discarded – undo
82 82
     public function createIndex($config)
83 83
     {
84 84
 
85
-        if(!is_array($config)) {
85
+        if (!is_array($config)) {
86 86
             $config = ['fields' => $config];
87 87
         }
88 88
 
89 89
 
90
-        if(!array_key_exists('fields', $config)) {
91
-            if(array_values($config) != $config) {
90
+        if (!array_key_exists('fields', $config)) {
91
+            if (array_values($config) != $config) {
92 92
                 throw new Exception("Invalid index configuration");
93 93
             }
94 94
             $config = [
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
             ];
97 97
         }
98 98
 
99
-        if(!is_array($config['fields'])) {
99
+        if (!is_array($config['fields'])) {
100 100
             $config['fields'] = [$config['fields']];
101 101
         }
102 102
 
@@ -104,17 +104,17 @@  discard block
 block discarded – undo
104 104
             'parts' => []
105 105
         ];
106 106
 
107
-        foreach($config as $k => $v) {
108
-            if($k != 'name' && $k != 'fields') {
107
+        foreach ($config as $k => $v) {
108
+            if ($k != 'name' && $k != 'fields') {
109 109
                 $options[$k] = $v;
110 110
             }
111 111
         }
112 112
 
113
-        foreach($config['fields'] as $property) {
114
-            if(!$this->getPropertyType($property)) {
113
+        foreach ($config['fields'] as $property) {
114
+            if (!$this->getPropertyType($property)) {
115 115
                 throw new Exception("Unknown property $property", 1);
116 116
             }
117
-            $options['parts'][] = $this->getPropertyIndex($property)+1;
117
+            $options['parts'][] = $this->getPropertyIndex($property) + 1;
118 118
             $options['parts'][] = $this->getPropertyType($property);
119 119
         }
120 120
 
@@ -140,15 +140,15 @@  discard block
 block discarded – undo
140 140
 
141 141
     public function getFormat()
142 142
     {
143
-        if(!$this->format) {
144
-            if($this->isSpecial()) {
143
+        if (!$this->format) {
144
+            if ($this->isSpecial()) {
145 145
                 $this->format = $this->mapper->getClient()
146 146
                     ->getSpace(280)->select([$this->id])->getData()[0][6];
147 147
 
148 148
             } else {
149 149
                 $this->format = $this->mapper->findOne('_space', ['id' => $this->id])->format;
150 150
             }
151
-            if(!$this->format) {
151
+            if (!$this->format) {
152 152
                 $this->format = [];
153 153
             }
154 154
             $this->parseFormat();
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
     {
172 172
         $this->formatTypesHash = [];
173 173
         $this->formatNamesHash = [];
174
-        foreach($this->format as $key => $row) {
174
+        foreach ($this->format as $key => $row) {
175 175
             $this->formatTypesHash[$row['name']] = $row['type'];
176 176
             $this->formatNamesHash[$row['name']] = $key;
177 177
         }
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
     public function getPropertyType($name)
188 188
     {
189
-        if(!$this->hasProperty($name)) {
189
+        if (!$this->hasProperty($name)) {
190 190
             throw new Exception("No property $name");
191 191
         }
192 192
         return $this->formatTypesHash[$name];
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 
195 195
     public function getPropertyIndex($name)
196 196
     {
197
-        if(!$this->hasProperty($name)) {
197
+        if (!$this->hasProperty($name)) {
198 198
             throw new Exception("No property $name");
199 199
         }
200 200
         return $this->formatNamesHash[$name];
@@ -202,14 +202,14 @@  discard block
 block discarded – undo
202 202
 
203 203
     public function getIndexes()
204 204
     {
205
-        if(!$this->indexes) {
206
-            if($this->isSpecial()) {
205
+        if (!$this->indexes) {
206
+            if ($this->isSpecial()) {
207 207
                 $this->indexes = [];
208 208
                 $indexTuples = $this->mapper->getClient()->getSpace(288)->select([$this->id])->getData();
209 209
                 $indexFormat = $this->mapper->getSchema()->getSpace(288)->getFormat();
210
-                foreach($indexTuples as $tuple) {
210
+                foreach ($indexTuples as $tuple) {
211 211
                     $instance = (object) [];
212
-                    foreach($indexFormat as $index => $format) {
212
+                    foreach ($indexFormat as $index => $format) {
213 213
                         $instance->{$format['name']} = $tuple[$index];
214 214
                     }
215 215
                     $this->indexes[] = $instance;
@@ -227,44 +227,44 @@  discard block
 block discarded – undo
227 227
         $keys = array_keys($params);
228 228
 
229 229
         $keys = [];
230
-        foreach($params as $name => $value) {
230
+        foreach ($params as $name => $value) {
231 231
             $keys[] = $this->getPropertyIndex($name);
232 232
         }
233
-        if($keys == [0]) {
233
+        if ($keys == [0]) {
234 234
             // primary index
235 235
             return 0;
236 236
         }
237 237
 
238 238
         // equals
239
-        foreach($this->getIndexes() as $index) {
239
+        foreach ($this->getIndexes() as $index) {
240 240
             $equals = false;
241
-            if(count($keys) == count($index->parts)) {
241
+            if (count($keys) == count($index->parts)) {
242 242
                 // same length
243 243
                 $equals = true;
244
-                foreach($index->parts as $part) {
244
+                foreach ($index->parts as $part) {
245 245
                     $equals = $equals && in_array($part[0], $keys);
246 246
                 }
247 247
             }
248 248
 
249
-            if($equals) {
249
+            if ($equals) {
250 250
                 return $index->iid;
251 251
             }
252 252
         }
253 253
 
254 254
         // index part
255
-        foreach($this->getIndexes() as $index) {
255
+        foreach ($this->getIndexes() as $index) {
256 256
             $partial = [];
257
-            foreach($index->parts as $n => $part) {
258
-                if(!array_key_exists($n, $keys)) {
257
+            foreach ($index->parts as $n => $part) {
258
+                if (!array_key_exists($n, $keys)) {
259 259
                     break;
260 260
                 }
261
-                if($keys[$n] != $part[0]) {
261
+                if ($keys[$n] != $part[0]) {
262 262
                     break;
263 263
                 }
264 264
                 $partial[] = $keys[$n];
265 265
             }
266 266
 
267
-            if(count($partial) == count($keys)) {
267
+            if (count($partial) == count($keys)) {
268 268
                 return $index->iid;
269 269
             }
270 270
         }
@@ -275,21 +275,21 @@  discard block
 block discarded – undo
275 275
     public function getIndexValues($indexId, $params)
276 276
     {
277 277
         $index = null;
278
-        foreach($this->getIndexes() as $candidate) {
279
-            if($candidate->iid == $indexId) {
278
+        foreach ($this->getIndexes() as $candidate) {
279
+            if ($candidate->iid == $indexId) {
280 280
                 $index = $candidate;
281 281
                 break;
282 282
             }
283 283
         }
284
-        if(!$index) {
284
+        if (!$index) {
285 285
             throw new Exception("Undefined index: $indexId");
286 286
         }
287 287
 
288 288
         $format = $this->getFormat();
289 289
         $values = [];
290
-        foreach($index->parts as $part) {
290
+        foreach ($index->parts as $part) {
291 291
             $name = $format[$part[0]]['name'];
292
-            if(!array_key_exists($name, $params)) {
292
+            if (!array_key_exists($name, $params)) {
293 293
                 break;
294 294
             }
295 295
             $values[] = $this->mapper->getSchema()->formatValue($part[1], $params[$name]);
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
     public function getPrimaryIndex()
301 301
     {
302 302
         $indexes = $this->getIndexes();
303
-        if(!count($indexes)) {
303
+        if (!count($indexes)) {
304 304
             throw new Exception("No primary index");
305 305
         }
306 306
         return $indexes[0];
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
     public function getTupleKey($tuple)
310 310
     {
311 311
         $key = [];
312
-        foreach($this->getPrimaryIndex()->parts as $part) {
312
+        foreach ($this->getPrimaryIndex()->parts as $part) {
313 313
             $key[] = $tuple[$part[0]];
314 314
         }
315 315
         return count($key) == 1 ? $key[0] : implode(':', $key);
@@ -320,9 +320,9 @@  discard block
 block discarded – undo
320 320
 
321 321
         $key = [];
322 322
 
323
-        foreach($this->getPrimaryIndex()->parts as $part) {
323
+        foreach ($this->getPrimaryIndex()->parts as $part) {
324 324
             $name = $this->getFormat()[$part[0]]['name'];
325
-            if(!property_exists($instance, $name)) {
325
+            if (!property_exists($instance, $name)) {
326 326
                 throw new Exception("Field $name is undefined", 1);
327 327
             }
328 328
             $key[] = $instance->$name;
@@ -334,10 +334,10 @@  discard block
 block discarded – undo
334 334
     public function getRepository()
335 335
     {
336 336
         $class = Repository::class;
337
-        foreach($this->mapper->getPlugins() as $plugin) {
337
+        foreach ($this->mapper->getPlugins() as $plugin) {
338 338
             $repositoryClass = $plugin->getRepositoryClass($this);
339
-            if($repositoryClass) {
340
-                if($class != Repository::class) {
339
+            if ($repositoryClass) {
340
+                if ($class != Repository::class) {
341 341
                     throw new Exception('Repository class override');
342 342
                 }
343 343
                 $class = $repositoryClass;
Please login to merge, or discard this patch.
src/Schema.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 
29 29
         $this->spaces[$id] = new Space($this->mapper, $id, $space);
30 30
 
31
-        if($properties) {
31
+        if ($properties) {
32 32
             $this->spaces[$id]->addProperties($properties);
33 33
         }
34 34
 
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
     public function formatValue($type, $value)
39 39
     {
40
-        switch($type) {
40
+        switch ($type) {
41 41
             case 'STR':
42 42
             case 'str':
43 43
                 return (string) $value;
@@ -53,15 +53,15 @@  discard block
 block discarded – undo
53 53
 
54 54
     public function getSpace($id)
55 55
     {
56
-        if(is_string($id)) {
56
+        if (is_string($id)) {
57 57
             return $this->getSpace($this->getSpaceId($id));
58 58
         }
59 59
 
60
-        if(!$id) {
60
+        if (!$id) {
61 61
             throw new Exception("Space id or name not defined");
62 62
         }
63 63
 
64
-        if(!array_key_exists($id, $this->spaces)) {
64
+        if (!array_key_exists($id, $this->spaces)) {
65 65
             $this->spaces[$id] = new Space($this->mapper, $id, array_search($id, $this->names));
66 66
         }
67 67
         return $this->spaces[$id];
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 
70 70
     public function getSpaceId($name)
71 71
     {
72
-        if(!$this->hasSpace($name)) {
72
+        if (!$this->hasSpace($name)) {
73 73
             throw new Exception("No space $name");
74 74
         }
75 75
         return $this->names[$name];
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 
78 78
     public function getSpaces()
79 79
     {
80
-        foreach($this->names as $id) {
80
+        foreach ($this->names as $id) {
81 81
             $this->getSpace($id);
82 82
         }
83 83
         return $this->spaces;
@@ -90,10 +90,10 @@  discard block
 block discarded – undo
90 90
 
91 91
     public function once($name, $callback)
92 92
     {
93
-        $key = 'once' . $name;
93
+        $key = 'once'.$name;
94 94
 
95 95
         $rows = $this->mapper->find('_schema', ['key' => $key]);
96
-        if(!count($rows)) {
96
+        if (!count($rows)) {
97 97
             $this->mapper->create('_schema', ['key' => $key]);
98 98
             return $callback($this->mapper);
99 99
         }
Please login to merge, or discard this patch.
src/Plugins/Annotation.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -120,6 +120,9 @@
 block discarded – undo
120 120
 
121 121
     private $underscores = [];
122 122
 
123
+    /**
124
+     * @param string $input
125
+     */
123 126
     private function toUnderscore($input)
124 127
     {
125 128
         if(!array_key_exists($input, $this->underscores)) {
Please login to merge, or discard this patch.
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -3,13 +3,10 @@
 block discarded – undo
3 3
 namespace Tarantool\Mapper\Plugins;
4 4
 
5 5
 use Exception;
6
-
7 6
 use phpDocumentor\Reflection\DocBlockFactory;
8 7
 use ReflectionClass;
9 8
 use ReflectionProperty;
10
-
11 9
 use Tarantool\Mapper\Entity;
12
-use Tarantool\Mapper\Plugin;
13 10
 use Tarantool\Mapper\Repository;
14 11
 
15 12
 class Annotation extends UserClasses
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -22,19 +22,19 @@  discard block
 block discarded – undo
22 22
         $isEntity = is_subclass_of($class, Entity::class);
23 23
         $isRepository = is_subclass_of($class, Repository::class);
24 24
 
25
-        if(!$isEntity && !$isRepository) {
25
+        if (!$isEntity && !$isRepository) {
26 26
             throw new Exception("Invalid registration");
27 27
         }
28 28
 
29
-        if($isEntity) {
30
-            if($class == Entity::class) {
29
+        if ($isEntity) {
30
+            if ($class == Entity::class) {
31 31
                 throw new Exception("Invalid entity registration");
32 32
             }
33 33
             $this->entities[] = $class;
34 34
         }
35 35
 
36
-        if($isRepository) {
37
-            if($class == Repository::class) {
36
+        if ($isRepository) {
37
+            if ($class == Repository::class) {
38 38
                 throw new Exception("Invalid repository registration");
39 39
             }
40 40
             $this->repositories[] = $class;
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 
43 43
         $reflection = new ReflectionClass($class);
44 44
         $space = $this->toUnderscore($reflection->getShortName());
45
-        if($this->mapper->getSchema()->hasSpace($space)) {
46
-            if($isEntity) {
45
+        if ($this->mapper->getSchema()->hasSpace($space)) {
46
+            if ($isEntity) {
47 47
                 $this->mapEntity($space, $class);
48 48
             } else {
49 49
                 $this->mapRepository($space, $class);
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 
59 59
         $schema = $this->mapper->getSchema();
60 60
 
61
-        foreach($this->entities as $entity) {
61
+        foreach ($this->entities as $entity) {
62 62
 
63 63
             $class = new ReflectionClass($entity);
64 64
             $spaceName = $this->toUnderscore($class->getShortName());
@@ -66,34 +66,34 @@  discard block
 block discarded – undo
66 66
             $space = $schema->hasSpace($spaceName) ? $schema->getSpace($spaceName) : $schema->createSpace($spaceName);
67 67
             $this->mapEntity($spaceName, $entity);
68 68
 
69
-            foreach($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
69
+            foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
70 70
 
71 71
                 $description = $factory->create($property->getDocComment());
72 72
                 $tags = $description->getTags('var');
73 73
 
74
-                if(!count($tags)) {
74
+                if (!count($tags)) {
75 75
                     throw new Exception("No var tag for ".$entity.'::'.$property->getName());
76 76
                 }
77 77
 
78
-                if(count($tags) > 1) {
78
+                if (count($tags) > 1) {
79 79
                     throw new Exception("Invalid var tag for ".$entity.'::'.$property->getName());
80 80
                 }
81 81
 
82 82
                 $property = $this->toUnderscore($property->getName());
83 83
                 $type = $this->getTarantoolType($tags[0]->getType());
84 84
 
85
-                if(!$space->hasProperty($property)) {
85
+                if (!$space->hasProperty($property)) {
86 86
                     $space->addProperty($property, $type);
87 87
                 }
88 88
             }
89 89
         }
90 90
 
91
-        foreach($this->repositories as $repository) {
91
+        foreach ($this->repositories as $repository) {
92 92
 
93 93
             $class = new ReflectionClass($repository);
94 94
             $spaceName = $this->toUnderscore($class->getShortName());
95 95
 
96
-            if(!$schema->hasSpace($spaceName)) {
96
+            if (!$schema->hasSpace($spaceName)) {
97 97
                 throw new Exception("Repository with no entity definition");
98 98
             }
99 99
 
@@ -101,12 +101,12 @@  discard block
 block discarded – undo
101 101
 
102 102
             $space = $schema->getSpace($spaceName);
103 103
             $properties = $class->getDefaultProperties();
104
-            if(array_key_exists('indexes', $properties)) {
105
-                foreach($properties['indexes'] as $index) {
106
-                    if(!is_array($index)) {
104
+            if (array_key_exists('indexes', $properties)) {
105
+                foreach ($properties['indexes'] as $index) {
106
+                    if (!is_array($index)) {
107 107
                         $index = (array) $index;
108 108
                     }
109
-                    if(!array_key_exists('fields', $index)) {
109
+                    if (!array_key_exists('fields', $index)) {
110 110
                         $index = ['fields' => $index];
111 111
                     }
112 112
 
@@ -116,11 +116,11 @@  discard block
 block discarded – undo
116 116
             }
117 117
         }
118 118
 
119
-        foreach($schema->getSpaces() as $space) {
119
+        foreach ($schema->getSpaces() as $space) {
120 120
 
121
-            if(!count($space->getIndexes())) {
122
-                if(!$space->hasProperty('id')) {
123
-                    throw new Exception("No primary index on ". $space->getName());
121
+            if (!count($space->getIndexes())) {
122
+                if (!$space->hasProperty('id')) {
123
+                    throw new Exception("No primary index on ".$space->getName());
124 124
                 }
125 125
                 $space->addIndex(['id']);
126 126
             }
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 
134 134
     private function toUnderscore($input)
135 135
     {
136
-        if(!array_key_exists($input, $this->underscores)) {
136
+        if (!array_key_exists($input, $this->underscores)) {
137 137
             preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
138 138
             $ret = $matches[0];
139 139
             foreach ($ret as &$match) {
@@ -148,15 +148,15 @@  discard block
 block discarded – undo
148 148
 
149 149
     private function getTarantoolType(string $type)
150 150
     {
151
-        if(array_key_exists($type, $this->tarantoolTypes)) {
151
+        if (array_key_exists($type, $this->tarantoolTypes)) {
152 152
             return $this->tarantoolTypes[$type];
153 153
         }
154 154
 
155
-        if($type[0] == '\\') {
155
+        if ($type[0] == '\\') {
156 156
             return $this->tarantoolTypes[$type] = 'unsigned';
157 157
         }
158 158
 
159
-        switch($type) {
159
+        switch ($type) {
160 160
             case 'int':
161 161
                 return $this->tarantoolTypes[$type] = 'unsigned';
162 162
 
Please login to merge, or discard this patch.
src/Repository.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -259,6 +259,9 @@
 block discarded – undo
259 259
         $this->results = [];
260 260
     }
261 261
 
262
+    /**
263
+     * @param Entity $instance
264
+     */
262 265
     public function save($instance)
263 266
     {
264 267
         $tuple = [];
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -24,20 +24,20 @@  discard block
 block discarded – undo
24 24
     {
25 25
         $data = (array) $data;
26 26
         $class = Entity::class;
27
-        foreach($this->space->getMapper()->getPlugins() as $plugin) {
27
+        foreach ($this->space->getMapper()->getPlugins() as $plugin) {
28 28
             $entityClass = $plugin->getEntityClass($this->space);
29
-            if($entityClass) {
30
-                if($class != Entity::class) {
29
+            if ($entityClass) {
30
+                if ($class != Entity::class) {
31 31
                     throw new Exception('Entity class override');
32 32
                 }
33 33
                 $class = $entityClass;
34 34
             }
35 35
         }
36 36
 
37
-        if(array_key_exists(0, $data)) {
37
+        if (array_key_exists(0, $data)) {
38 38
             $byType = [];
39
-            foreach($this->space->getFormat() as $row) {
40
-                if(!array_key_exists($row['type'], $byType)) {
39
+            foreach ($this->space->getFormat() as $row) {
40
+                if (!array_key_exists($row['type'], $byType)) {
41 41
                     $byType[$row['type']] = [$row['name']];
42 42
                 } else {
43 43
                     $byType[$row['type']][] = $row['name'];
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
                 'is_string' => 'str',
49 49
                 'is_array' => '*',
50 50
             ];
51
-            foreach($data as $k => $v) {
52
-                foreach($mapping as $function => $type) {
53
-                    if(call_user_func($function, $v)) {
54
-                        if(count($byType[$type]) == 1) {
51
+            foreach ($data as $k => $v) {
52
+                foreach ($mapping as $function => $type) {
53
+                    if (call_user_func($function, $v)) {
54
+                        if (count($byType[$type]) == 1) {
55 55
                             $data[$byType[$type][0]] = $v;
56 56
                             unset($data[$k]);
57 57
                         }
@@ -61,16 +61,16 @@  discard block
 block discarded – undo
61 61
         }
62 62
 
63 63
         $instance = new $class($this);
64
-        foreach($this->space->getFormat() as $row) {
65
-            if(array_key_exists($row['name'], $data)) {
64
+        foreach ($this->space->getFormat() as $row) {
65
+            if (array_key_exists($row['name'], $data)) {
66 66
                 $instance->{$row['name']} = $data[$row['name']];
67
-                if($data[$row['name']] instanceof Entity) {
67
+                if ($data[$row['name']] instanceof Entity) {
68 68
                     $instance->{$row['name']} = $instance->{$row['name']}->id;
69 69
                 }
70 70
             }
71 71
         }
72 72
 
73
-        foreach($this->space->getMapper()->getPlugins() as $plugin) {
73
+        foreach ($this->space->getMapper()->getPlugins() as $plugin) {
74 74
             $plugin->generateKey($instance, $this->space);
75 75
         }
76 76
 
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
     {
91 91
         $cacheKey = json_encode(func_get_args());
92 92
 
93
-        if(array_key_exists($cacheKey, $this->results)) {
93
+        if (array_key_exists($cacheKey, $this->results)) {
94 94
             return $this->results[$cacheKey];
95 95
         }
96 96
 
97
-        if(!is_array($params)) {
97
+        if (!is_array($params)) {
98 98
             $params = [$params];
99 99
         }
100
-        if(count($params) == 1 && array_key_exists(0, $params)) {
100
+        if (count($params) == 1 && array_key_exists(0, $params)) {
101 101
             $primary = $this->space->getPrimaryIndex();
102
-            if(count($primary->parts) == 1) {
102
+            if (count($primary->parts) == 1) {
103 103
                 $formatted = $this->space->getMapper()->getSchema()->formatValue($primary->parts[0][1], $params[0]);
104
-                if($params[0] == $formatted) {
104
+                if ($params[0] == $formatted) {
105 105
                     $params = [
106 106
                         $this->space->getFormat()[$primary->parts[0][0]]['name'] => $params[0]
107 107
                     ];
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
             }
110 110
         }
111 111
 
112
-        if(array_key_exists('id', $params)) {
113
-            if(array_key_exists($params['id'], $this->persisted)) {
112
+        if (array_key_exists('id', $params)) {
113
+            if (array_key_exists($params['id'], $this->persisted)) {
114 114
                 $instance = $this->persisted[$params['id']];
115 115
                 return $one ? $instance : [$instance];
116 116
             }
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 
119 119
 
120 120
         $index = $this->space->castIndex($params);
121
-        if(is_null($index)) {
121
+        if (is_null($index)) {
122 122
             throw new Exception("No index for params ".json_encode($params));
123 123
         }
124 124
 
@@ -128,15 +128,15 @@  discard block
 block discarded – undo
128 128
         $data = $client->getSpace($this->space->getId())->select($values, $index)->getData();
129 129
 
130 130
         $result = [];
131
-        foreach($data as $tuple) {
131
+        foreach ($data as $tuple) {
132 132
             $instance = $this->getInstance($tuple);
133
-            if($one) {
133
+            if ($one) {
134 134
                 return $this->results[$cacheKey] = $instance;
135 135
             }
136 136
             $result[] = $instance;
137 137
         }
138 138
 
139
-        if($one) {
139
+        if ($one) {
140 140
             return $this->results[$cacheKey] = null;
141 141
         }
142 142
 
@@ -147,15 +147,15 @@  discard block
 block discarded – undo
147 147
     {
148 148
         $key = $this->space->getTupleKey($tuple);
149 149
 
150
-        if(array_key_exists($key, $this->persisted)) {
150
+        if (array_key_exists($key, $this->persisted)) {
151 151
             return $this->persisted[$key];
152 152
         }
153 153
 
154 154
         $class = Entity::class;
155
-        foreach($this->space->getMapper()->getPlugins() as $plugin) {
155
+        foreach ($this->space->getMapper()->getPlugins() as $plugin) {
156 156
             $entityClass = $plugin->getEntityClass($this->space);
157
-            if($entityClass) {
158
-                if($class != Entity::class) {
157
+            if ($entityClass) {
158
+                if ($class != Entity::class) {
159 159
                     throw new Exception('Entity class override');
160 160
                 }
161 161
                 $class = $entityClass;
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 
166 166
         $this->original[$key] = $tuple;
167 167
 
168
-        foreach($this->space->getFormat() as $index => $info) {
168
+        foreach ($this->space->getFormat() as $index => $info) {
169 169
             $instance->{$info['name']} = array_key_exists($index, $tuple) ? $tuple[$index] : null;
170 170
         }
171 171
 
@@ -181,26 +181,26 @@  discard block
 block discarded – undo
181 181
 
182 182
     public function update(Entity $instance, $operations)
183 183
     {
184
-        if(!count($operations)) {
184
+        if (!count($operations)) {
185 185
             return;
186 186
         }
187 187
 
188 188
         $tupleOperations = [];
189
-        foreach($operations as $operation) {
189
+        foreach ($operations as $operation) {
190 190
             $tupleIndex = $this->space->getPropertyIndex($operation[1]);
191 191
             $tupleOperations[] = [$operation[0], $tupleIndex, $operation[2]];
192 192
         }
193 193
 
194 194
         $pk = [];
195
-        foreach($this->space->getPrimaryIndex()->parts as $part) {
195
+        foreach ($this->space->getPrimaryIndex()->parts as $part) {
196 196
             $pk[] = $instance->{$this->space->getFormat()[$part[0]]['name']};
197 197
         }
198 198
 
199 199
         $client = $this->space->getMapper()->getClient();
200 200
         $result = $client->getSpace($this->space->getId())->update($pk, $tupleOperations);
201
-        foreach($result->getData() as $tuple) {
202
-            foreach($this->space->getFormat() as $index => $info) {
203
-                if(array_key_exists($index, $tuple)) {
201
+        foreach ($result->getData() as $tuple) {
202
+            foreach ($this->space->getFormat() as $index => $info) {
203
+                if (array_key_exists($index, $tuple)) {
204 204
                     $instance->{$info['name']} = $tuple[$index];
205 205
                 }
206 206
             }
@@ -216,15 +216,15 @@  discard block
 block discarded – undo
216 216
 
217 217
     public function remove($params = [])
218 218
     {
219
-        if($params instanceof Entity) {
219
+        if ($params instanceof Entity) {
220 220
             return $this->removeEntity($params);
221 221
         }
222 222
 
223
-        if(!count($params)) {
223
+        if (!count($params)) {
224 224
             throw new Exception("Use truncate to flush space");
225 225
         }
226 226
 
227
-        foreach($this->find($params) as $entity) {
227
+        foreach ($this->find($params) as $entity) {
228 228
             $this->removeEntity($entity);
229 229
         }
230 230
     }
@@ -233,19 +233,19 @@  discard block
 block discarded – undo
233 233
     {
234 234
         $key = $this->space->getInstanceKey($instance);
235 235
 
236
-        if(!array_key_exists($key, $this->original)) {
236
+        if (!array_key_exists($key, $this->original)) {
237 237
             return;
238 238
         }
239 239
 
240
-        if(array_key_exists($key, $this->persisted)) {
240
+        if (array_key_exists($key, $this->persisted)) {
241 241
 
242 242
             unset($this->persisted[$key]);
243 243
 
244 244
             $pk = [];
245
-            foreach($this->space->getPrimaryIndex()->parts as $part) {
245
+            foreach ($this->space->getPrimaryIndex()->parts as $part) {
246 246
                 $pk[] = $this->original[$key][$part[0]];
247 247
             }
248
-            foreach($this->space->getMapper()->getPlugins() as $plugin) {
248
+            foreach ($this->space->getMapper()->getPlugins() as $plugin) {
249 249
                 $plugin->beforeRemove($instance, $this->space);
250 250
             }
251 251
 
@@ -266,10 +266,10 @@  discard block
 block discarded – undo
266 266
         $format = $this->space->getFormat();
267 267
 
268 268
         // complete indexes fields
269
-        foreach($this->space->getIndexes() as $index) {
270
-            foreach($index->parts as $part) {
269
+        foreach ($this->space->getIndexes() as $index) {
270
+            foreach ($index->parts as $part) {
271 271
                 $name = $format[$part[0]]['name'];
272
-                if(!property_exists($instance, $name)) {
272
+                if (!property_exists($instance, $name)) {
273 273
                     $instance->{$name} = null;
274 274
                 }
275 275
             }
@@ -278,8 +278,8 @@  discard block
 block discarded – undo
278 278
         $size = count(get_object_vars($instance));
279 279
         $skipped = 0;
280 280
 
281
-        foreach($format as $index => $info) {
282
-            if(!property_exists($instance, $info['name'])) {
281
+        foreach ($format as $index => $info) {
282
+            if (!property_exists($instance, $info['name'])) {
283 283
                 $skipped++;
284 284
                 $instance->{$info['name']} = null;
285 285
             }
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 ->formatValue($info['type'], $instance->{$info['name']});
289 289
             $tuple[$index] = $instance->{$info['name']};
290 290
 
291
-            if(count($tuple) == $size + $skipped) {
291
+            if (count($tuple) == $size + $skipped) {
292 292
                 break;
293 293
             }
294 294
         }
@@ -296,24 +296,24 @@  discard block
 block discarded – undo
296 296
         $key = $this->space->getInstanceKey($instance);
297 297
         $client = $this->space->getMapper()->getClient();
298 298
 
299
-        if(array_key_exists($key, $this->persisted)) {
299
+        if (array_key_exists($key, $this->persisted)) {
300 300
             // update
301 301
             $update = array_diff_assoc($tuple, $this->original[$key]);
302
-            if(!count($update)) {
302
+            if (!count($update)) {
303 303
                 return $instance;
304 304
             }
305 305
 
306 306
             $operations = [];
307
-            foreach($update as $index => $value) {
307
+            foreach ($update as $index => $value) {
308 308
                 $operations[] = ['=', $index, $value];
309 309
             }
310 310
 
311 311
             $pk = [];
312
-            foreach($this->space->getPrimaryIndex()->parts as $part) {
312
+            foreach ($this->space->getPrimaryIndex()->parts as $part) {
313 313
                 $pk[] = $this->original[$key][$part[0]];
314 314
             }
315 315
 
316
-            foreach($this->space->getMapper()->getPlugins() as $plugin) {
316
+            foreach ($this->space->getMapper()->getPlugins() as $plugin) {
317 317
                 $plugin->beforeUpdate($instance, $this->space);
318 318
             }
319 319
 
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 
323 323
         } else {
324 324
 
325
-            foreach($this->space->getMapper()->getPlugins() as $plugin) {
325
+            foreach ($this->space->getMapper()->getPlugins() as $plugin) {
326 326
                 $plugin->beforeCreate($instance, $this->space);
327 327
             }
328 328
 
Please login to merge, or discard this patch.