Completed
Push — master ( c32558...5e96b3 )
by Dmitry
02:04
created
src/Mapper.php 1 patch
Spacing   +10 added lines, -10 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
         }
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 
60 60
     public function getBootstrap()
61 61
     {
62
-        if(!$this->bootstrap) {
62
+        if (!$this->bootstrap) {
63 63
             $this->bootstrap = new Bootstrap($this);
64 64
         }
65 65
 
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 
74 74
     public function getPlugin($class)
75 75
     {
76
-        foreach($this->getPlugins() as $plugin) {
77
-            if(is_a($plugin, $class)) {
76
+        foreach ($this->getPlugins() as $plugin) {
77
+            if (is_a($plugin, $class)) {
78 78
                 return $plugin;
79 79
             }
80 80
         }
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
     public function getRepositories()
94 94
     {
95 95
         $repositories = [];
96
-        foreach($this->getSchema()->getSpaces() as $space) {
97
-            if($space->repositoryExists()) {
96
+        foreach ($this->getSchema()->getSpaces() as $space) {
97
+            if ($space->repositoryExists()) {
98 98
                 $repositories[] = $space->getRepository();
99 99
             }
100 100
         }
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 
109 109
     public function remove($space, $params = [])
110 110
     {
111
-        if($space instanceof Entity) {
111
+        if ($space instanceof Entity) {
112 112
             $this->findRepository($space)->removeEntity($space);
113 113
 
114 114
         } else {
Please login to merge, or discard this patch.
src/Repository.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -24,23 +24,23 @@  discard block
 block discarded – undo
24 24
     public function create($data)
25 25
     {
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
         $instance = new $class();
37
-        foreach($this->space->getFormat() as $row) {
38
-            if(array_key_exists($row['name'], $data)) {
37
+        foreach ($this->space->getFormat() as $row) {
38
+            if (array_key_exists($row['name'], $data)) {
39 39
                 $instance->{$row['name']} = $data[$row['name']];
40 40
             }
41 41
         }
42 42
 
43
-        foreach($this->space->getMapper()->getPlugins() as $plugin) {
43
+        foreach ($this->space->getMapper()->getPlugins() as $plugin) {
44 44
             $plugin->generateKey($instance, $this->space);
45 45
         }
46 46
 
@@ -59,18 +59,18 @@  discard block
 block discarded – undo
59 59
     public function find($params = [], $one = false)
60 60
     {
61 61
         $cacheIndex = array_search([$params, $one], $this->cache);
62
-        if($cacheIndex !== false) {
62
+        if ($cacheIndex !== false) {
63 63
             return $this->results[$cacheIndex];
64 64
         }
65 65
 
66
-        if(!is_array($params)) {
66
+        if (!is_array($params)) {
67 67
             $params = [$params];
68 68
         }
69
-        if(count($params) == 1 && array_key_exists(0, $params)) {
69
+        if (count($params) == 1 && array_key_exists(0, $params)) {
70 70
             $primary = $this->space->getPrimaryIndex();
71
-            if(count($primary->parts) == 1) {
71
+            if (count($primary->parts) == 1) {
72 72
                 $formatted = $this->space->getMapper()->getSchema()->formatValue($primary->parts[0][1], $params[0]);
73
-                if($params[0] == $formatted) {
73
+                if ($params[0] == $formatted) {
74 74
                     $params = [
75 75
                         $this->space->getFormat()[$primary->parts[0][0]]['name'] => $params[0]
76 76
                     ];
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
             }
79 79
         }
80 80
 
81
-        if(array_key_exists('id', $params)) {
82
-            if(array_key_exists($params['id'], $this->persisted)) {
81
+        if (array_key_exists('id', $params)) {
82
+            if (array_key_exists($params['id'], $this->persisted)) {
83 83
                 $instance = $this->persisted[$params['id']];
84 84
                 return $one ? $instance : [$instance];
85 85
             }
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 
88 88
 
89 89
         $index = $this->space->castIndex($params);
90
-        if(is_null($index)) {
90
+        if (is_null($index)) {
91 91
             throw new Exception("No index for params ".json_encode($params));
92 92
         }
93 93
 
@@ -100,15 +100,15 @@  discard block
 block discarded – undo
100 100
         $data = $client->getSpace($this->space->getId())->select($values, $index)->getData();
101 101
 
102 102
         $result = [];
103
-        foreach($data as $tuple) {
103
+        foreach ($data as $tuple) {
104 104
             $instance = $this->getInstance($tuple);
105
-            if($one) {
105
+            if ($one) {
106 106
                 return $this->results[$cacheIndex] = $instance;
107 107
             }
108 108
             $result[] = $instance;
109 109
         }
110 110
 
111
-        if($one) {
111
+        if ($one) {
112 112
             return $this->results[$cacheIndex] = null;
113 113
         }
114 114
 
@@ -119,15 +119,15 @@  discard block
 block discarded – undo
119 119
     {
120 120
         $key = $this->space->getTupleKey($tuple);
121 121
 
122
-        if(array_key_exists($key, $this->persisted)) {
122
+        if (array_key_exists($key, $this->persisted)) {
123 123
             return $this->persisted[$key];
124 124
         }
125 125
 
126 126
         $class = Entity::class;
127
-        foreach($this->space->getMapper()->getPlugins() as $plugin) {
127
+        foreach ($this->space->getMapper()->getPlugins() as $plugin) {
128 128
             $entityClass = $plugin->getEntityClass($this->space);
129
-            if($entityClass) {
130
-                if($class != Entity::class) {
129
+            if ($entityClass) {
130
+                if ($class != Entity::class) {
131 131
                     throw new Exception('Entity class override');
132 132
                 }
133 133
                 $class = $entityClass;
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 
138 138
         $this->original[$key] = $tuple;
139 139
 
140
-        foreach($this->space->getFormat() as $index => $info) {
140
+        foreach ($this->space->getFormat() as $index => $info) {
141 141
             $instance->{$info['name']} = array_key_exists($index, $tuple) ? $tuple[$index] : null;
142 142
         }
143 143
 
@@ -153,26 +153,26 @@  discard block
 block discarded – undo
153 153
 
154 154
     public function update(Entity $instance, $operations)
155 155
     {
156
-        if(!count($operations)) {
156
+        if (!count($operations)) {
157 157
             return;
158 158
         }
159 159
 
160 160
         $tupleOperations = [];
161
-        foreach($operations as $operation) {
161
+        foreach ($operations as $operation) {
162 162
             $tupleIndex = $this->space->getPropertyIndex($operation[1]);
163 163
             $tupleOperations[] = [$operation[0], $tupleIndex, $operation[2]];
164 164
         }
165 165
 
166 166
         $pk = [];
167
-        foreach($this->space->getPrimaryIndex()->parts as $part) {
167
+        foreach ($this->space->getPrimaryIndex()->parts as $part) {
168 168
             $pk[] = $instance->{$this->space->getFormat()[$part[0]]['name']};
169 169
         }
170 170
 
171 171
         $client = $this->space->getMapper()->getClient();
172 172
         $result = $client->getSpace($this->space->getId())->update($pk, $tupleOperations);
173
-        foreach($result->getData() as $tuple) {
174
-            foreach($this->space->getFormat() as $index => $info) {
175
-                if(array_key_exists($index, $tuple)) {
173
+        foreach ($result->getData() as $tuple) {
174
+            foreach ($this->space->getFormat() as $index => $info) {
175
+                if (array_key_exists($index, $tuple)) {
176 176
                     $instance->{$info['name']} = $tuple[$index];
177 177
                 }
178 178
             }
@@ -189,15 +189,15 @@  discard block
 block discarded – undo
189 189
 
190 190
     public function remove($params = [])
191 191
     {
192
-        if($params instanceof Entity) {
192
+        if ($params instanceof Entity) {
193 193
             return $this->removeEntity($params);
194 194
         }
195 195
 
196
-        if(!count($params)) {
196
+        if (!count($params)) {
197 197
             throw new Exception("Use truncate to flush space");
198 198
         }
199 199
 
200
-        foreach($this->find($params) as $entity) {
200
+        foreach ($this->find($params) as $entity) {
201 201
             $this->removeEntity($entity);
202 202
         }
203 203
     }
@@ -206,19 +206,19 @@  discard block
 block discarded – undo
206 206
     {
207 207
         $key = $this->space->getInstanceKey($instance);
208 208
 
209
-        if(!array_key_exists($key, $this->original)) {
209
+        if (!array_key_exists($key, $this->original)) {
210 210
             return;
211 211
         }
212 212
 
213
-        if(array_key_exists($key, $this->persisted)) {
213
+        if (array_key_exists($key, $this->persisted)) {
214 214
 
215 215
             unset($this->persisted[$key]);
216 216
 
217 217
             $pk = [];
218
-            foreach($this->space->getPrimaryIndex()->parts as $part) {
218
+            foreach ($this->space->getPrimaryIndex()->parts as $part) {
219 219
                 $pk[] = $this->original[$key][$part[0]];
220 220
             }
221
-            foreach($this->space->getMapper()->getPlugins() as $plugin) {
221
+            foreach ($this->space->getMapper()->getPlugins() as $plugin) {
222 222
                 $plugin->beforeRemove($instance, $this->space);
223 223
             }
224 224
 
@@ -240,8 +240,8 @@  discard block
 block discarded – undo
240 240
         $size = count(get_object_vars($instance));
241 241
         $skipped = 0;
242 242
 
243
-        foreach($this->space->getFormat() as $index => $info) {
244
-            if(!property_exists($instance, $info['name'])) {
243
+        foreach ($this->space->getFormat() as $index => $info) {
244
+            if (!property_exists($instance, $info['name'])) {
245 245
                 $skipped++;
246 246
                 $instance->{$info['name']} = null;
247 247
             }
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
                 ->formatValue($info['type'], $instance->{$info['name']});
251 251
             $tuple[$index] = $instance->{$info['name']};
252 252
 
253
-            if(count($tuple) == $size + $skipped) {
253
+            if (count($tuple) == $size + $skipped) {
254 254
                 break;
255 255
             }
256 256
         }
@@ -258,24 +258,24 @@  discard block
 block discarded – undo
258 258
         $key = $this->space->getInstanceKey($instance);
259 259
         $client = $this->space->getMapper()->getClient();
260 260
 
261
-        if(array_key_exists($key, $this->persisted)) {
261
+        if (array_key_exists($key, $this->persisted)) {
262 262
             // update
263 263
             $update = array_diff_assoc($tuple, $this->original[$key]);
264
-            if(!count($update)) {
264
+            if (!count($update)) {
265 265
                 return $instance;
266 266
             }
267 267
 
268 268
             $operations = [];
269
-            foreach($update as $index => $value) {
269
+            foreach ($update as $index => $value) {
270 270
                 $operations[] = ['=', $index, $value];
271 271
             }
272 272
 
273 273
             $pk = [];
274
-            foreach($this->space->getPrimaryIndex()->parts as $part) {
274
+            foreach ($this->space->getPrimaryIndex()->parts as $part) {
275 275
                 $pk[] = $this->original[$key][$part[0]];
276 276
             }
277 277
 
278
-            foreach($this->space->getMapper()->getPlugins() as $plugin) {
278
+            foreach ($this->space->getMapper()->getPlugins() as $plugin) {
279 279
                 $plugin->beforeUpdate($instance, $this->space);
280 280
             }
281 281
 
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 
285 285
         } else {
286 286
 
287
-            foreach($this->space->getMapper()->getPlugins() as $plugin) {
287
+            foreach ($this->space->getMapper()->getPlugins() as $plugin) {
288 288
                 $plugin->beforeCreate($instance, $this->space);
289 289
             }
290 290
 
Please login to merge, or discard this patch.