Completed
Push — master ( 3e8a03...43ff2c )
by Dmitry
02:19
created
src/Plugins/Spy.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
     public function beforeUpdate(Entity $instance, Space $space)
21 21
     {
22 22
         $key = $this->getKey($instance, $space);
23
-        if(!array_key_exists($key, $this->create)) {
23
+        if (!array_key_exists($key, $this->create)) {
24 24
             $this->update[$key] = $instance;
25 25
         }
26 26
     }
@@ -29,12 +29,12 @@  discard block
 block discarded – undo
29 29
     {
30 30
         $key = $this->getKey($instance, $space);
31 31
 
32
-        if(array_key_exists($key, $this->create)) {
32
+        if (array_key_exists($key, $this->create)) {
33 33
             unset($this->create[$key]);
34 34
             return;
35 35
         }
36 36
 
37
-        if(array_key_exists($key, $this->update)) {
37
+        if (array_key_exists($key, $this->update)) {
38 38
             unset($this->update[$key]);
39 39
         }
40 40
 
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
         $key = [$space->getName()];
54 54
 
55 55
         $format = $space->getFormat();
56
-        foreach($space->getPrimaryIndex()->parts as $part) {
56
+        foreach ($space->getPrimaryIndex()->parts as $part) {
57 57
             $key[] = $instance->{$format[$part[0]]['name']};
58 58
         }
59 59
 
Please login to merge, or discard this patch.
src/Plugins/Sequence.php 1 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');
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
         }
38 38
 
39 39
         $entity = $this->mapper->findOne('sequence', $space->getId());
40
-        if(!$entity) {
40
+        if (!$entity) {
41 41
             $entity = $this->mapper->create('sequence', [
42 42
                 'space' => $space->getId(),
43 43
                 'counter' => 0,
Please login to merge, or discard this patch.
src/Repository.php 1 patch
Spacing   +41 added lines, -41 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
             }
@@ -183,19 +183,19 @@  discard block
 block discarded – undo
183 183
     {
184 184
         $key = $this->space->getInstanceKey($instance);
185 185
 
186
-        if(!array_key_exists($key, $this->original)) {
186
+        if (!array_key_exists($key, $this->original)) {
187 187
             return;
188 188
         }
189 189
 
190
-        if(array_key_exists($key, $this->persisted)) {
190
+        if (array_key_exists($key, $this->persisted)) {
191 191
 
192 192
             unset($this->persisted[$key]);
193 193
 
194 194
             $pk = [];
195
-            foreach($this->space->getPrimaryIndex()->parts as $part) {
195
+            foreach ($this->space->getPrimaryIndex()->parts as $part) {
196 196
                 $pk[] = $this->original[$key][$part[0]];
197 197
             }
198
-            foreach($this->space->getMapper()->getPlugins() as $plugin) {
198
+            foreach ($this->space->getMapper()->getPlugins() as $plugin) {
199 199
                 $plugin->beforeRemove($instance, $this->space);
200 200
             }
201 201
 
@@ -217,8 +217,8 @@  discard block
 block discarded – undo
217 217
         $size = count(get_object_vars($instance));
218 218
         $skipped = 0;
219 219
 
220
-        foreach($this->space->getFormat() as $index => $info) {
221
-            if(!property_exists($instance, $info['name'])) {
220
+        foreach ($this->space->getFormat() as $index => $info) {
221
+            if (!property_exists($instance, $info['name'])) {
222 222
                 $skipped++;
223 223
                 $instance->{$info['name']} = null;
224 224
             }
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
                 ->formatValue($info['type'], $instance->{$info['name']});
228 228
             $tuple[$index] = $instance->{$info['name']};
229 229
 
230
-            if(count($tuple) == $size + $skipped) {
230
+            if (count($tuple) == $size + $skipped) {
231 231
                 break;
232 232
             }
233 233
         }
@@ -235,24 +235,24 @@  discard block
 block discarded – undo
235 235
         $key = $this->space->getInstanceKey($instance);
236 236
         $client = $this->space->getMapper()->getClient();
237 237
 
238
-        if(array_key_exists($key, $this->persisted)) {
238
+        if (array_key_exists($key, $this->persisted)) {
239 239
             // update
240 240
             $update = array_diff_assoc($tuple, $this->original[$key]);
241
-            if(!count($update)) {
241
+            if (!count($update)) {
242 242
                 return $instance;
243 243
             }
244 244
 
245 245
             $operations = [];
246
-            foreach($update as $index => $value) {
246
+            foreach ($update as $index => $value) {
247 247
                 $operations[] = ['=', $index, $value];
248 248
             }
249 249
 
250 250
             $pk = [];
251
-            foreach($this->space->getPrimaryIndex()->parts as $part) {
251
+            foreach ($this->space->getPrimaryIndex()->parts as $part) {
252 252
                 $pk[] = $this->original[$key][$part[0]];
253 253
             }
254 254
 
255
-            foreach($this->space->getMapper()->getPlugins() as $plugin) {
255
+            foreach ($this->space->getMapper()->getPlugins() as $plugin) {
256 256
                 $plugin->beforeUpdate($instance, $this->space);
257 257
             }
258 258
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 
262 262
         } else {
263 263
 
264
-            foreach($this->space->getMapper()->getPlugins() as $plugin) {
264
+            foreach ($this->space->getMapper()->getPlugins() as $plugin) {
265 265
                 $plugin->beforeCreate($instance, $this->space);
266 266
             }
267 267
 
Please login to merge, or discard this patch.
src/Mapper.php 1 patch
Spacing   +9 added lines, -9 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
         }
Please login to merge, or discard this patch.