Completed
Push — master ( 050f53...d62e68 )
by Dmitry
02:09
created
src/Client.php 1 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/Repository.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -25,20 +25,20 @@  discard block
 block discarded – undo
25 25
     {
26 26
         $data = (array) $data;
27 27
         $class = Entity::class;
28
-        foreach($this->space->getMapper()->getPlugins() as $plugin) {
28
+        foreach ($this->space->getMapper()->getPlugins() as $plugin) {
29 29
             $entityClass = $plugin->getEntityClass($this->space);
30
-            if($entityClass) {
31
-                if($class != Entity::class) {
30
+            if ($entityClass) {
31
+                if ($class != Entity::class) {
32 32
                     throw new Exception('Entity class override');
33 33
                 }
34 34
                 $class = $entityClass;
35 35
             }
36 36
         }
37 37
 
38
-        if(array_key_exists(0, $data)) {
38
+        if (array_key_exists(0, $data)) {
39 39
             $byType = [];
40
-            foreach($this->space->getFormat() as $row) {
41
-                if(!array_key_exists($row['type'], $byType)) {
40
+            foreach ($this->space->getFormat() as $row) {
41
+                if (!array_key_exists($row['type'], $byType)) {
42 42
                     $byType[$row['type']] = [$row['name']];
43 43
                 } else {
44 44
                     $byType[$row['type']][] = $row['name'];
@@ -49,10 +49,10 @@  discard block
 block discarded – undo
49 49
                 'is_string' => 'str',
50 50
                 'is_array' => '*',
51 51
             ];
52
-            foreach($data as $k => $v) {
53
-                foreach($mapping as $function => $type) {
54
-                    if(call_user_func($function, $v)) {
55
-                        if(count($byType[$type]) == 1) {
52
+            foreach ($data as $k => $v) {
53
+                foreach ($mapping as $function => $type) {
54
+                    if (call_user_func($function, $v)) {
55
+                        if (count($byType[$type]) == 1) {
56 56
                             $data[$byType[$type][0]] = $v;
57 57
                             unset($data[$k]);
58 58
                         }
@@ -62,16 +62,16 @@  discard block
 block discarded – undo
62 62
         }
63 63
 
64 64
         $instance = new $class($this);
65
-        foreach($this->space->getFormat() as $row) {
66
-            if(array_key_exists($row['name'], $data)) {
65
+        foreach ($this->space->getFormat() as $row) {
66
+            if (array_key_exists($row['name'], $data)) {
67 67
                 $instance->{$row['name']} = $data[$row['name']];
68
-                if($data[$row['name']] instanceof Entity) {
68
+                if ($data[$row['name']] instanceof Entity) {
69 69
                     $instance->{$row['name']} = $instance->{$row['name']}->id;
70 70
                 }
71 71
             }
72 72
         }
73 73
 
74
-        foreach($this->space->getMapper()->getPlugins() as $plugin) {
74
+        foreach ($this->space->getMapper()->getPlugins() as $plugin) {
75 75
             $plugin->generateKey($instance, $this->space);
76 76
         }
77 77
 
@@ -91,18 +91,18 @@  discard block
 block discarded – undo
91 91
     {
92 92
         $cacheKey = json_encode(func_get_args());
93 93
 
94
-        if(array_key_exists($cacheKey, $this->results)) {
94
+        if (array_key_exists($cacheKey, $this->results)) {
95 95
             return $this->results[$cacheKey];
96 96
         }
97 97
 
98
-        if(!is_array($params)) {
98
+        if (!is_array($params)) {
99 99
             $params = [$params];
100 100
         }
101
-        if(count($params) == 1 && array_key_exists(0, $params)) {
101
+        if (count($params) == 1 && array_key_exists(0, $params)) {
102 102
             $primary = $this->space->getPrimaryIndex();
103
-            if(count($primary->parts) == 1) {
103
+            if (count($primary->parts) == 1) {
104 104
                 $formatted = $this->space->getMapper()->getSchema()->formatValue($primary->parts[0][1], $params[0]);
105
-                if($params[0] == $formatted) {
105
+                if ($params[0] == $formatted) {
106 106
                     $params = [
107 107
                         $this->space->getFormat()[$primary->parts[0][0]]['name'] => $params[0]
108 108
                     ];
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
             }
111 111
         }
112 112
 
113
-        if(array_key_exists('id', $params)) {
114
-            if(array_key_exists($params['id'], $this->persisted)) {
113
+        if (array_key_exists('id', $params)) {
114
+            if (array_key_exists($params['id'], $this->persisted)) {
115 115
                 $instance = $this->persisted[$params['id']];
116 116
                 return $one ? $instance : [$instance];
117 117
             }
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 
120 120
 
121 121
         $index = $this->space->castIndex($params);
122
-        if(is_null($index)) {
122
+        if (is_null($index)) {
123 123
             throw new Exception("No index for params ".json_encode($params));
124 124
         }
125 125
 
@@ -129,15 +129,15 @@  discard block
 block discarded – undo
129 129
         $data = $client->getSpace($this->space->getId())->select($values, $index)->getData();
130 130
 
131 131
         $result = [];
132
-        foreach($data as $tuple) {
132
+        foreach ($data as $tuple) {
133 133
             $instance = $this->getInstance($tuple);
134
-            if($one) {
134
+            if ($one) {
135 135
                 return $this->results[$cacheKey] = $instance;
136 136
             }
137 137
             $result[] = $instance;
138 138
         }
139 139
 
140
-        if($one) {
140
+        if ($one) {
141 141
             return $this->results[$cacheKey] = null;
142 142
         }
143 143
 
@@ -148,15 +148,15 @@  discard block
 block discarded – undo
148 148
     {
149 149
         $key = $this->space->getTupleKey($tuple);
150 150
 
151
-        if(array_key_exists($key, $this->persisted)) {
151
+        if (array_key_exists($key, $this->persisted)) {
152 152
             return $this->persisted[$key];
153 153
         }
154 154
 
155 155
         $class = Entity::class;
156
-        foreach($this->space->getMapper()->getPlugins() as $plugin) {
156
+        foreach ($this->space->getMapper()->getPlugins() as $plugin) {
157 157
             $entityClass = $plugin->getEntityClass($this->space);
158
-            if($entityClass) {
159
-                if($class != Entity::class) {
158
+            if ($entityClass) {
159
+                if ($class != Entity::class) {
160 160
                     throw new Exception('Entity class override');
161 161
                 }
162 162
                 $class = $entityClass;
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 
167 167
         $this->original[$key] = $tuple;
168 168
 
169
-        foreach($this->space->getFormat() as $index => $info) {
169
+        foreach ($this->space->getFormat() as $index => $info) {
170 170
             $instance->{$info['name']} = array_key_exists($index, $tuple) ? $tuple[$index] : null;
171 171
         }
172 172
 
@@ -182,26 +182,26 @@  discard block
 block discarded – undo
182 182
 
183 183
     public function update(Entity $instance, $operations)
184 184
     {
185
-        if(!count($operations)) {
185
+        if (!count($operations)) {
186 186
             return;
187 187
         }
188 188
 
189 189
         $tupleOperations = [];
190
-        foreach($operations as $operation) {
190
+        foreach ($operations as $operation) {
191 191
             $tupleIndex = $this->space->getPropertyIndex($operation[1]);
192 192
             $tupleOperations[] = [$operation[0], $tupleIndex, $operation[2]];
193 193
         }
194 194
 
195 195
         $pk = [];
196
-        foreach($this->space->getPrimaryIndex()->parts as $part) {
196
+        foreach ($this->space->getPrimaryIndex()->parts as $part) {
197 197
             $pk[] = $instance->{$this->space->getFormat()[$part[0]]['name']};
198 198
         }
199 199
 
200 200
         $client = $this->space->getMapper()->getClient();
201 201
         $result = $client->getSpace($this->space->getId())->update($pk, $tupleOperations);
202
-        foreach($result->getData() as $tuple) {
203
-            foreach($this->space->getFormat() as $index => $info) {
204
-                if(array_key_exists($index, $tuple)) {
202
+        foreach ($result->getData() as $tuple) {
203
+            foreach ($this->space->getFormat() as $index => $info) {
204
+                if (array_key_exists($index, $tuple)) {
205 205
                     $instance->{$info['name']} = $tuple[$index];
206 206
                 }
207 207
             }
@@ -218,15 +218,15 @@  discard block
 block discarded – undo
218 218
 
219 219
     public function remove($params = [])
220 220
     {
221
-        if($params instanceof Entity) {
221
+        if ($params instanceof Entity) {
222 222
             return $this->removeEntity($params);
223 223
         }
224 224
 
225
-        if(!count($params)) {
225
+        if (!count($params)) {
226 226
             throw new Exception("Use truncate to flush space");
227 227
         }
228 228
 
229
-        foreach($this->find($params) as $entity) {
229
+        foreach ($this->find($params) as $entity) {
230 230
             $this->removeEntity($entity);
231 231
         }
232 232
     }
@@ -235,19 +235,19 @@  discard block
 block discarded – undo
235 235
     {
236 236
         $key = $this->space->getInstanceKey($instance);
237 237
 
238
-        if(!array_key_exists($key, $this->original)) {
238
+        if (!array_key_exists($key, $this->original)) {
239 239
             return;
240 240
         }
241 241
 
242
-        if(array_key_exists($key, $this->persisted)) {
242
+        if (array_key_exists($key, $this->persisted)) {
243 243
 
244 244
             unset($this->persisted[$key]);
245 245
 
246 246
             $pk = [];
247
-            foreach($this->space->getPrimaryIndex()->parts as $part) {
247
+            foreach ($this->space->getPrimaryIndex()->parts as $part) {
248 248
                 $pk[] = $this->original[$key][$part[0]];
249 249
             }
250
-            foreach($this->space->getMapper()->getPlugins() as $plugin) {
250
+            foreach ($this->space->getMapper()->getPlugins() as $plugin) {
251 251
                 $plugin->beforeRemove($instance, $this->space);
252 252
             }
253 253
 
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
         $size = count(get_object_vars($instance));
270 270
         $skipped = 0;
271 271
 
272
-        foreach($this->space->getFormat() as $index => $info) {
273
-            if(!property_exists($instance, $info['name'])) {
272
+        foreach ($this->space->getFormat() as $index => $info) {
273
+            if (!property_exists($instance, $info['name'])) {
274 274
                 $skipped++;
275 275
                 $instance->{$info['name']} = null;
276 276
             }
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
                 ->formatValue($info['type'], $instance->{$info['name']});
280 280
             $tuple[$index] = $instance->{$info['name']};
281 281
 
282
-            if(count($tuple) == $size + $skipped) {
282
+            if (count($tuple) == $size + $skipped) {
283 283
                 break;
284 284
             }
285 285
         }
@@ -287,24 +287,24 @@  discard block
 block discarded – undo
287 287
         $key = $this->space->getInstanceKey($instance);
288 288
         $client = $this->space->getMapper()->getClient();
289 289
 
290
-        if(array_key_exists($key, $this->persisted)) {
290
+        if (array_key_exists($key, $this->persisted)) {
291 291
             // update
292 292
             $update = array_diff_assoc($tuple, $this->original[$key]);
293
-            if(!count($update)) {
293
+            if (!count($update)) {
294 294
                 return $instance;
295 295
             }
296 296
 
297 297
             $operations = [];
298
-            foreach($update as $index => $value) {
298
+            foreach ($update as $index => $value) {
299 299
                 $operations[] = ['=', $index, $value];
300 300
             }
301 301
 
302 302
             $pk = [];
303
-            foreach($this->space->getPrimaryIndex()->parts as $part) {
303
+            foreach ($this->space->getPrimaryIndex()->parts as $part) {
304 304
                 $pk[] = $this->original[$key][$part[0]];
305 305
             }
306 306
 
307
-            foreach($this->space->getMapper()->getPlugins() as $plugin) {
307
+            foreach ($this->space->getMapper()->getPlugins() as $plugin) {
308 308
                 $plugin->beforeUpdate($instance, $this->space);
309 309
             }
310 310
 
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 
314 314
         } else {
315 315
 
316
-            foreach($this->space->getMapper()->getPlugins() as $plugin) {
316
+            foreach ($this->space->getMapper()->getPlugins() as $plugin) {
317 317
                 $plugin->beforeCreate($instance, $this->space);
318 318
             }
319 319
 
Please login to merge, or discard this patch.