Completed
Push — master ( 45846d...2ad132 )
by Dmitry
02:06
created
src/Space.php 1 patch
Spacing   +43 added lines, -43 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
 
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
 
139 139
     public function getFormat()
140 140
     {
141
-        if(!$this->format) {
142
-            if($this->isSpecial()) {
141
+        if (!$this->format) {
142
+            if ($this->isSpecial()) {
143 143
                 $this->format = $this->mapper->getClient()
144 144
                     ->getSpace(280)->select([$this->id])->getData()[0][6];
145 145
 
146 146
             } else {
147 147
                 $this->format = $this->mapper->findOne('_space', ['id' => $this->id])->format;
148 148
             }
149
-            if(!$this->format) {
149
+            if (!$this->format) {
150 150
                 $this->format = [];
151 151
             }
152 152
             $this->parseFormat();
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
     {
170 170
         $this->formatTypesHash = [];
171 171
         $this->formatNamesHash = [];
172
-        foreach($this->format as $key => $row) {
172
+        foreach ($this->format as $key => $row) {
173 173
             $this->formatTypesHash[$row['name']] = $row['type'];
174 174
             $this->formatNamesHash[$row['name']] = $key;
175 175
         }
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 
185 185
     public function getPropertyType($name)
186 186
     {
187
-        if(!$this->hasProperty($name)) {
187
+        if (!$this->hasProperty($name)) {
188 188
             throw new Exception("No property $name");
189 189
         }
190 190
         return $this->formatTypesHash[$name];
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
     public function getPropertyIndex($name)
194 194
     {
195
-        if(!$this->hasProperty($name)) {
195
+        if (!$this->hasProperty($name)) {
196 196
             throw new Exception("No property $name");
197 197
         }
198 198
         return $this->formatNamesHash[$name];
@@ -200,14 +200,14 @@  discard block
 block discarded – undo
200 200
 
201 201
     public function getIndexes()
202 202
     {
203
-        if(!$this->indexes) {
204
-            if($this->isSpecial()) {
203
+        if (!$this->indexes) {
204
+            if ($this->isSpecial()) {
205 205
                 $this->indexes = [];
206 206
                 $indexTuples = $this->mapper->getClient()->getSpace(288)->select([$this->id])->getData();
207 207
                 $indexFormat = $this->mapper->getSchema()->getSpace(288)->getFormat();
208
-                foreach($indexTuples as $tuple) {
208
+                foreach ($indexTuples as $tuple) {
209 209
                     $instance = (object) [];
210
-                    foreach($indexFormat as $index => $format) {
210
+                    foreach ($indexFormat as $index => $format) {
211 211
                         $instance->{$format['name']} = $tuple[$index];
212 212
                     }
213 213
                     $this->indexes[] = $instance;
@@ -225,44 +225,44 @@  discard block
 block discarded – undo
225 225
         $keys = array_keys($params);
226 226
 
227 227
         $keys = [];
228
-        foreach($params as $name => $value) {
228
+        foreach ($params as $name => $value) {
229 229
             $keys[] = $this->getPropertyIndex($name);
230 230
         }
231
-        if($keys == [0]) {
231
+        if ($keys == [0]) {
232 232
             // primary index
233 233
             return 0;
234 234
         }
235 235
 
236 236
         // equals
237
-        foreach($this->getIndexes() as $index) {
237
+        foreach ($this->getIndexes() as $index) {
238 238
             $equals = false;
239
-            if(count($keys) == count($index->parts)) {
239
+            if (count($keys) == count($index->parts)) {
240 240
                 // same length
241 241
                 $equals = true;
242
-                foreach($index->parts as $part) {
242
+                foreach ($index->parts as $part) {
243 243
                     $equals = $equals && in_array($part[0], $keys);
244 244
                 }
245 245
             }
246 246
 
247
-            if($equals) {
247
+            if ($equals) {
248 248
                 return $index->iid;
249 249
             }
250 250
         }
251 251
 
252 252
         // index part
253
-        foreach($this->getIndexes() as $index) {
253
+        foreach ($this->getIndexes() as $index) {
254 254
             $partial = [];
255
-            foreach($index->parts as $n => $part) {
256
-                if(!array_key_exists($n, $keys)) {
255
+            foreach ($index->parts as $n => $part) {
256
+                if (!array_key_exists($n, $keys)) {
257 257
                     break;
258 258
                 }
259
-                if($keys[$n] != $part[0]) {
259
+                if ($keys[$n] != $part[0]) {
260 260
                     break;
261 261
                 }
262 262
                 $partial[] = $keys[$n];
263 263
             }
264 264
 
265
-            if(count($partial) == count($keys)) {
265
+            if (count($partial) == count($keys)) {
266 266
                 return $index->iid;
267 267
             }
268 268
         }
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
         $format = $this->getFormat();
277 277
 
278 278
         $values = [];
279
-        foreach($index->parts as $part) {
279
+        foreach ($index->parts as $part) {
280 280
             $name = $format[$part[0]]['name'];
281
-            if(!array_key_exists($name, $params)) {
281
+            if (!array_key_exists($name, $params)) {
282 282
                 break;
283 283
             }
284 284
             $values[] = $this->mapper->getSchema()->formatValue($part[1], $params[$name]);
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
     public function getPrimaryIndex()
290 290
     {
291 291
         $indexes = $this->getIndexes();
292
-        if(!count($indexes)) {
292
+        if (!count($indexes)) {
293 293
             throw new Exception("No primary index");
294 294
         }
295 295
         return $indexes[0];
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
     public function getTupleKey($tuple)
299 299
     {
300 300
         $key = [];
301
-        foreach($this->getPrimaryIndex()->parts as $part) {
301
+        foreach ($this->getPrimaryIndex()->parts as $part) {
302 302
             $key[] = $tuple[$part[0]];
303 303
         }
304 304
         return count($key) == 1 ? $key[0] : implode(':', $key);
@@ -309,9 +309,9 @@  discard block
 block discarded – undo
309 309
 
310 310
         $key = [];
311 311
 
312
-        foreach($this->getPrimaryIndex()->parts as $part) {
312
+        foreach ($this->getPrimaryIndex()->parts as $part) {
313 313
             $name = $this->getFormat()[$part[0]]['name'];
314
-            if(!property_exists($instance, $name)) {
314
+            if (!property_exists($instance, $name)) {
315 315
                 throw new Exception("Field $name is undefined", 1);
316 316
             }
317 317
             $key[] = $instance->$name;
@@ -323,10 +323,10 @@  discard block
 block discarded – undo
323 323
     public function getRepository()
324 324
     {
325 325
         $class = Repository::class;
326
-        foreach($this->mapper->getPlugins() as $plugin) {
326
+        foreach ($this->mapper->getPlugins() as $plugin) {
327 327
             $repositoryClass = $plugin->getRepositoryClass($this);
328
-            if($repositoryClass) {
329
-                if($class != Repository::class) {
328
+            if ($repositoryClass) {
329
+                if ($class != Repository::class) {
330 330
                     throw new Exception('Repository class override');
331 331
                 }
332 332
                 $class = $repositoryClass;
Please login to merge, or discard this patch.