Passed
Branch master (af4849)
by y
01:47
created
src/DB.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      * @param string $passwd
47 47
      * @param array $options
48 48
      */
49
-    public function __construct ($dsn, $username = null, $passwd = null, $options = null) {
49
+    public function __construct($dsn, $username = null, $passwd = null, $options = null) {
50 50
         parent::__construct(...func_get_args());
51 51
         $this->setAttribute(self::ATTR_ERRMODE, self::ERRMODE_EXCEPTION);
52 52
         $this->setAttribute(self::ATTR_DEFAULT_FETCH_MODE, self::FETCH_ASSOC);
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
      * @param string $sql
63 63
      * @return int
64 64
      */
65
-    public function exec ($sql) {
65
+    public function exec($sql) {
66 66
         $this->logger->__invoke($sql);
67 67
         return parent::exec($sql);
68 68
     }
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      *
73 73
      * @return string
74 74
      */
75
-    final public function getDriver () {
75
+    final public function getDriver() {
76 76
         return $this->getAttribute(self::ATTR_DRIVER_NAME);
77 77
     }
78 78
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      * @param string $interface
83 83
      * @return Junction
84 84
      */
85
-    public function getJunction ($interface) {
85
+    public function getJunction($interface) {
86 86
         if (!isset($this->junctions[$interface])) {
87 87
             $this->junctions[$interface] = new Junction($this, $interface);
88 88
         }
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      * @param string|EntityInterface $class
96 96
      * @return Record
97 97
      */
98
-    public function getRecord ($class) {
98
+    public function getRecord($class) {
99 99
         if (is_object($class)) {
100 100
             $class = get_class($class);
101 101
         }
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      * @param string|array|Select|Closure $b
123 123
      * @return string|string[] Same type as `$a`, keys are not preserved.
124 124
      */
125
-    public function match ($a, $b = null) {
125
+    public function match($a, $b = null) {
126 126
         if (is_array($a)) {
127 127
             return array_map([$this, __FUNCTION__], array_keys($a), $a);
128 128
         }
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      * @param string $access Class or interface name.
140 140
      * @return bool
141 141
      */
142
-    public function offsetExists ($access) {
142
+    public function offsetExists($access) {
143 143
         return (bool)$this->offsetGet($access);
144 144
     }
145 145
 
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
      * @param string $access Class or interface name.
148 148
      * @return Record|Junction|null
149 149
      */
150
-    public function offsetGet ($access) {
150
+    public function offsetGet($access) {
151 151
         if (class_exists($access)) {
152 152
             return $this->getRecord($access);
153 153
         }
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
      * @param void $value
165 165
      * @throws LogicException
166 166
      */
167
-    final public function offsetSet ($access, $value) {
167
+    final public function offsetSet($access, $value) {
168 168
         throw new LogicException('The schema cannot be altered by ArrayAccess.');
169 169
     }
170 170
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      * @param void $access
175 175
      * @throws LogicException
176 176
      */
177
-    final public function offsetUnset ($access) {
177
+    final public function offsetUnset($access) {
178 178
         $this->offsetSet($access, null);
179 179
     }
180 180
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
      * @param array $options
186 186
      * @return PDOStatement
187 187
      */
188
-    public function prepare ($sql, $options = null) {
188
+    public function prepare($sql, $options = null) {
189 189
         $this->logger->__invoke($sql);
190 190
         return parent::prepare(...func_get_args());
191 191
     }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      * @param array $ctorargs
200 200
      * @return PDOStatement
201 201
      */
202
-    public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) {
202
+    public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) {
203 203
         $this->logger->__invoke($sql);
204 204
         return parent::query(...func_get_args());
205 205
     }
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
      * @param int $type Ignored.
218 218
      * @return mixed
219 219
      */
220
-    public function quote ($value, $type = null) {
220
+    public function quote($value, $type = null) {
221 221
         switch (gettype($value)) {
222 222
             case 'array' :
223 223
                 return array_map([$this, __FUNCTION__], $value);
@@ -236,14 +236,14 @@  discard block
 block discarded – undo
236 236
      * @param EntityInterface $entity
237 237
      * @return int ID
238 238
      */
239
-    public function save (EntityInterface $entity) {
239
+    public function save(EntityInterface $entity) {
240 240
         return $this->getRecord($entity)->save($entity);
241 241
     }
242 242
 
243 243
     /**
244 244
      * @param Closure $logger
245 245
      */
246
-    public function setLogger (Closure $logger) {
246
+    public function setLogger(Closure $logger) {
247 247
         $this->logger = $logger;
248 248
     }
249 249
 }
250 250
\ No newline at end of file
Please login to merge, or discard this patch.
src/DB/EntityInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,5 +10,5 @@
 block discarded – undo
10 10
     /**
11 11
      * @return int
12 12
      */
13
-    public function getId (): int;
13
+    public function getId(): int;
14 14
 }
15 15
\ No newline at end of file
Please login to merge, or discard this patch.
src/DB/Select.php 2 patches
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
      * @param string|Select $table
76 76
      * @param array $columns Strings or {@link Column}. Keys are used for aliasing.
77 77
      */
78
-    public function __construct (DB $db, $table, array $columns) {
78
+    public function __construct(DB $db, $table, array $columns) {
79 79
         parent::__construct($db);
80 80
         if ($table instanceof Select) {
81 81
             $table = $table->toSubquery();
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
     /**
92 92
      * Gives the instance a new alias.
93 93
      */
94
-    public function __clone () {
94
+    public function __clone() {
95 95
         $this->alias = uniqid('_');
96 96
     }
97 97
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
      * @param array $args
100 100
      * @return PDOStatement
101 101
      */
102
-    public function __invoke (array $args = []) {
102
+    public function __invoke(array $args = []) {
103 103
         return $this->execute($args);
104 104
     }
105 105
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      *
109 109
      * @return string
110 110
      */
111
-    public function __toString (): string {
111
+    public function __toString(): string {
112 112
         return $this->alias;
113 113
     }
114 114
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
      * @param array $args Execution arguments.
119 119
      * @return int
120 120
      */
121
-    public function count (array $args = []): int {
121
+    public function count(array $args = []): int {
122 122
         $clone = clone $this;
123 123
         $clone->setColumns(['COUNT(*)']);
124 124
         return (int)$clone->execute($args)->fetchColumn();
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      * @param array $args
131 131
      * @return PDOStatement
132 132
      */
133
-    public function execute (array $args = []): PDOStatement {
133
+    public function execute(array $args = []): PDOStatement {
134 134
         $statement = $this->prepare();
135 135
         $statement->execute($args);
136 136
         return $statement;
@@ -144,21 +144,21 @@  discard block
 block discarded – undo
144 144
      * @param array $args Execution arguments.
145 145
      * @return array
146 146
      */
147
-    public function fetchAll (array $args = []): array {
147
+    public function fetchAll(array $args = []): array {
148 148
         return $this->fetcher->__invoke($this->execute($args));
149 149
     }
150 150
 
151 151
     /**
152 152
      * @return string
153 153
      */
154
-    final public function getAlias (): string {
154
+    final public function getAlias(): string {
155 155
         return $this->alias;
156 156
     }
157 157
 
158 158
     /**
159 159
      * @return Closure
160 160
      */
161
-    public function getFetcher (): Closure {
161
+    public function getFetcher(): Closure {
162 162
         return $this->fetcher;
163 163
     }
164 164
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
      *
170 170
      * @return ArrayIterator
171 171
      */
172
-    public function getIterator () {
172
+    public function getIterator() {
173 173
         return new ArrayIterator($this->fetchAll());
174 174
     }
175 175
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
      * @param string $column
180 180
      * @return $this
181 181
      */
182
-    public function group ($column) {
182
+    public function group($column) {
183 183
         $this->_group[] = $column;
184 184
         return $this;
185 185
     }
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
      * @param string $condition
191 191
      * @return $this
192 192
      */
193
-    public function having ($condition) {
193
+    public function having($condition) {
194 194
         $this->_having[] = $condition;
195 195
         return $this;
196 196
     }
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      * @param string $type
204 204
      * @return $this
205 205
      */
206
-    public function join ($table, $condition, $type = 'INNER') {
206
+    public function join($table, $condition, $type = 'INNER') {
207 207
         if ($table instanceof Select) {
208 208
             $table = $table->toSubquery();
209 209
         }
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
      * @param int $offset
219 219
      * @return $this
220 220
      */
221
-    public function limit ($limit, $offset = 0) {
221
+    public function limit($limit, $offset = 0) {
222 222
         $this->_limit = " LIMIT {$limit}";
223 223
         if ($offset) {
224 224
             $this->_limit .= " OFFSET {$offset}";
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
      * @param string $name Name or alias if used.
233 233
      * @return bool
234 234
      */
235
-    public function offsetExists ($name): bool {
235
+    public function offsetExists($name): bool {
236 236
         return isset($this->columns[$name]);
237 237
     }
238 238
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
      * @param string $name Name or alias if used.
243 243
      * @return Column
244 244
      */
245
-    public function offsetGet ($name): Column {
245
+    public function offsetGet($name): Column {
246 246
         return new Column($this->db, $name, $this->alias);
247 247
     }
248 248
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
      * @param string $order
253 253
      * @return $this
254 254
      */
255
-    public function order ($order) {
255
+    public function order($order) {
256 256
         $this->_order = " ORDER BY {$order}";
257 257
         return $this;
258 258
     }
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
     /**
261 261
      * @return PDOStatement
262 262
      */
263
-    public function prepare (): PDOStatement {
263
+    public function prepare(): PDOStatement {
264 264
         return $this->db->prepare($this->toSql());
265 265
     }
266 266
 
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
      * @param array $columns Strings or {@link Column}. Keys are used for aliasing.
271 271
      * @return $this
272 272
      */
273
-    public function setColumns (array $columns) {
273
+    public function setColumns(array $columns) {
274 274
         $this->columns = [];
275 275
         foreach ($columns as $alias => $column) {
276 276
             if ($column instanceof Column) {
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
      * @param Closure $fetcher
295 295
      * @return $this
296 296
      */
297
-    public function setFetcher (Closure $fetcher) {
297
+    public function setFetcher(Closure $fetcher) {
298 298
         $this->fetcher = $fetcher;
299 299
         return $this;
300 300
     }
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
     /**
303 303
      * @return string
304 304
      */
305
-    public function toSql (): string {
305
+    public function toSql(): string {
306 306
         $columns = [];
307 307
         foreach ($this->columns as $alias => $column) {
308 308
             if ($alias !== $column) {
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
      *
337 337
      * @return string
338 338
      */
339
-    public function toSubquery (): string {
339
+    public function toSubquery(): string {
340 340
         return "({$this->toSql()}) AS {$this->getAlias()}";
341 341
     }
342 342
 
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
      * @param string $condition
347 347
      * @return $this
348 348
      */
349
-    public function where ($condition) {
349
+    public function where($condition) {
350 350
         $this->_where[] = $condition;
351 351
         return $this;
352 352
     }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -276,14 +276,12 @@  discard block
 block discarded – undo
276 276
             if ($column instanceof Column) {
277 277
                 $name = $column->getName();
278 278
                 $column = (string)$column;
279
-            }
280
-            else {
279
+            } else {
281 280
                 $name = $column = (string)$column;
282 281
             }
283 282
             if (is_string($alias) and $alias !== $name) {
284 283
                 $this->columns[$alias] = $column;
285
-            }
286
-            else {
284
+            } else {
287 285
                 $this->columns[$column] = $column;
288 286
             }
289 287
         }
@@ -307,8 +305,7 @@  discard block
 block discarded – undo
307 305
         foreach ($this->columns as $alias => $column) {
308 306
             if ($alias !== $column) {
309 307
                 $columns[] = "{$column} AS {$alias}";
310
-            }
311
-            else {
308
+            } else {
312 309
                 $columns[] = "{$column}";
313 310
             }
314 311
         }
Please login to merge, or discard this patch.
src/DB/AbstractAccess.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
     /**
27 27
      * @param DB $db
28 28
      */
29
-    public function __construct (DB $db) {
29
+    public function __construct(DB $db) {
30 30
         $this->db = $db;
31 31
     }
32 32
 
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      * @param Closure $prepare `():PDOStatement`
38 38
      * @return PDOStatement
39 39
      */
40
-    protected function cache (string $key, Closure $prepare): PDOStatement {
40
+    protected function cache(string $key, Closure $prepare): PDOStatement {
41 41
         return $this->_cache[$key] ?? $this->_cache[$key] = $prepare->__invoke();
42 42
     }
43 43
 
Please login to merge, or discard this patch.
src/DB/Record.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      * @param DB $db
64 64
      * @param string $class
65 65
      */
66
-    public function __construct (DB $db, string $class) {
66
+    public function __construct(DB $db, string $class) {
67 67
         $this->db = $db;
68 68
         $this->class = $class;
69 69
         try {
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
      * @param PDOStatement $statement
110 110
      * @return EntityInterface[] Enumerated
111 111
      */
112
-    public function fetchAll (PDOStatement $statement): array {
112
+    public function fetchAll(PDOStatement $statement): array {
113 113
         $entities = [];
114 114
         foreach ($statement->fetchAll() as $row) {
115 115
             $clone = clone $this->proto;
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      * @param array[] $eavMatch Additional `[eav property => attribute => mixed]`
130 130
      * @return Select
131 131
      */
132
-    public function find (array $match, array $eavMatch = []): Select {
132
+    public function find(array $match, array $eavMatch = []): Select {
133 133
         $select = $this->select();
134 134
         foreach ($match as $column => $value) {
135 135
             $select->where($this->db->match($column, $value));
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
     /**
145 145
      * @return string
146 146
      */
147
-    final public function getClass (): string {
147
+    final public function getClass(): string {
148 148
         return $this->class;
149 149
     }
150 150
 
@@ -152,14 +152,14 @@  discard block
 block discarded – undo
152 152
      * @param string $property
153 153
      * @return EAV
154 154
      */
155
-    final public function getEav ($property): EAV {
155
+    final public function getEav($property): EAV {
156 156
         return $this->eav[$property];
157 157
     }
158 158
 
159 159
     /**
160 160
      * @return EntityInterface
161 161
      */
162
-    public function getProto (): EntityInterface {
162
+    public function getProto(): EntityInterface {
163 163
         return $this->proto;
164 164
     }
165 165
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
      * @param EntityInterface $entity
168 168
      * @return array
169 169
      */
170
-    protected function getValues (EntityInterface $entity): array {
170
+    protected function getValues(EntityInterface $entity): array {
171 171
         $values = [];
172 172
         foreach (array_keys($this->columns) as $name) {
173 173
             $values[$name] = $this->properties[$name]->getValue($entity);
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
      * @param int $id
182 182
      * @return null|EntityInterface
183 183
      */
184
-    public function load ($id): ?EntityInterface {
184
+    public function load($id): ?EntityInterface {
185 185
         $load = $this->cache(__FUNCTION__, function() {
186 186
             return $this->select()->where('id=:id')->prepare();
187 187
         });
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
      *
201 201
      * @param EntityInterface[] $entities
202 202
      */
203
-    protected function loadEav (array $entities): void {
203
+    protected function loadEav(array $entities): void {
204 204
         $ids = array_keys($entities);
205 205
         foreach ($this->eav as $name => $eav) {
206 206
             foreach ($eav->loadAll($ids) as $id => $values) {
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
      * @param EntityInterface $entity
216 216
      * @return int ID
217 217
      */
218
-    public function save (EntityInterface $entity): int {
218
+    public function save(EntityInterface $entity): int {
219 219
         if (!$entity->getId()) {
220 220
             $this->saveInsert($entity);
221 221
         }
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
     /**
230 230
      * @param EntityInterface $entity
231 231
      */
232
-    protected function saveEav (EntityInterface $entity): void {
232
+    protected function saveEav(EntityInterface $entity): void {
233 233
         $id = $entity->getId();
234 234
         foreach ($this->eav as $name => $eav) {
235 235
             $values = $this->properties[$name]->getValue($entity);
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      *
245 245
      * @param EntityInterface $entity
246 246
      */
247
-    protected function saveInsert (EntityInterface $entity): void {
247
+    protected function saveInsert(EntityInterface $entity): void {
248 248
         $insert = $this->cache(__FUNCTION__, function() {
249 249
             $slots = SQL::slots(array_keys($this->columns));
250 250
             unset($slots['id']);
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
      *
264 264
      * @param EntityInterface $entity
265 265
      */
266
-    protected function saveUpdate (EntityInterface $entity): void {
266
+    protected function saveUpdate(EntityInterface $entity): void {
267 267
         $this->cache(__FUNCTION__, function() {
268 268
             $slots = SQL::slots(array_keys($this->columns));
269 269
             unset($slots['id']);
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      * @param array $columns Defaults to all columns.
279 279
      * @return Select
280 280
      */
281
-    public function select (array $columns = []): Select {
281
+    public function select(array $columns = []): Select {
282 282
         $select = parent::select($columns);
283 283
         $select->setFetcher(function(PDOStatement $statement) {
284 284
             return $this->fetchAll($statement);
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      * @param EntityInterface $proto
291 291
      * @return $this
292 292
      */
293
-    public function setProto (EntityInterface $proto) {
293
+    public function setProto(EntityInterface $proto) {
294 294
         $this->proto = $proto;
295 295
         return $this;
296 296
     }
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
      * @param EntityInterface $entity
300 300
      * @param array $values
301 301
      */
302
-    protected function setValues (EntityInterface $entity, array $values): void {
302
+    protected function setValues(EntityInterface $entity, array $values): void {
303 303
         foreach ($values as $name => $value) {
304 304
             settype($value, $this->types[$name]);
305 305
             $this->properties[$name]->setValue($entity, $value);
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -68,8 +68,7 @@  discard block
 block discarded – undo
68 68
         $this->class = $class;
69 69
         try {
70 70
             $class = new ReflectionClass($class);
71
-        }
72
-        catch (ReflectionException $exception) {
71
+        } catch (ReflectionException $exception) {
73 72
             throw new LogicException('Unexpected ReflectionException', 0, $exception);
74 73
         }
75 74
         $this->proto = $class->newInstanceWithoutConstructor();
@@ -88,8 +87,7 @@  discard block
 block discarded – undo
88 87
                 if (preg_match('/@var\s+(?<type>\S+)/', $doc, $var)) {
89 88
                     $types[$name] = $var['type'];
90 89
                 }
91
-            }
92
-            elseif (preg_match('/@eav\s+(?<table>\S+)/', $doc, $match)) {
90
+            } elseif (preg_match('/@eav\s+(?<table>\S+)/', $doc, $match)) {
93 91
                 $eav[$name] = $match['table'];
94 92
                 $this->properties[$name] = $property;
95 93
             }
@@ -218,8 +216,7 @@  discard block
 block discarded – undo
218 216
     public function save (EntityInterface $entity): int {
219 217
         if (!$entity->getId()) {
220 218
             $this->saveInsert($entity);
221
-        }
222
-        else {
219
+        } else {
223 220
             $this->saveUpdate($entity);
224 221
         }
225 222
         $this->saveEav($entity);
Please login to merge, or discard this patch.
src/DB/AttributesTrait.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
     /**
23 23
      * @return array
24 24
      */
25
-    public function getAttributes (): array {
25
+    public function getAttributes(): array {
26 26
         return $this->attributes ?: [];
27 27
     }
28 28
 
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      * @param $offset
31 31
      * @return bool
32 32
      */
33
-    public function offsetExists ($offset): bool {
33
+    public function offsetExists($offset): bool {
34 34
         return $this->attributes and array_key_exists($offset, $this->attributes);
35 35
     }
36 36
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      * @param $offset
39 39
      * @return mixed Returns `NULL` for nonexistent attributes.
40 40
      */
41
-    public function offsetGet ($offset) {
41
+    public function offsetGet($offset) {
42 42
         return $this->attributes[$offset] ?? null;
43 43
     }
44 44
 
@@ -46,14 +46,14 @@  discard block
 block discarded – undo
46 46
      * @param $offset
47 47
      * @param $value
48 48
      */
49
-    public function offsetSet ($offset, $value): void {
49
+    public function offsetSet($offset, $value): void {
50 50
         $this->attributes[$offset] = $value;
51 51
     }
52 52
 
53 53
     /**
54 54
      * @param $offset
55 55
      */
56
-    public function offsetUnset ($offset): void {
56
+    public function offsetUnset($offset): void {
57 57
         unset($this->attributes[$offset]);
58 58
     }
59 59
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      * @param array $attributes
62 62
      * @return $this
63 63
      */
64
-    public function setAttributes (array $attributes) {
64
+    public function setAttributes(array $attributes) {
65 65
         $this->attributes = $attributes;
66 66
         return $this;
67 67
     }
Please login to merge, or discard this patch.
src/DB/SQL.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
      * @param string[] $conditions
16 16
      * @return string
17 17
      */
18
-    public static function all (array $conditions): string {
18
+    public static function all(array $conditions): string {
19 19
         if (count($conditions) === 1) {
20 20
             return reset($conditions);
21 21
         }
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      * @param string[] $conditions
29 29
      * @return string
30 30
      */
31
-    public static function any (array $conditions): string {
31
+    public static function any(array $conditions): string {
32 32
         if (count($conditions) === 1) {
33 33
             return reset($conditions);
34 34
         }
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      * @param string $listOperator
68 68
      * @return string|array
69 69
      */
70
-    public static function compare ($a, $operator, $b = null, $subqueryOperator = null, $listOperator = null) {
70
+    public static function compare($a, $operator, $b = null, $subqueryOperator = null, $listOperator = null) {
71 71
         if (is_array($a)) {
72 72
             $cmp = [];
73 73
             foreach ($a as $k => $v) {
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      * @param string|array|Select $b
92 92
      * @return string|array
93 93
      */
94
-    public static function isEqual ($a, $b = null) {
94
+    public static function isEqual($a, $b = null) {
95 95
         return static::compare($a, '=', $b, 'ANY', 'IN');
96 96
     }
97 97
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      * @param string|Select $b
103 103
      * @return string|array
104 104
      */
105
-    public static function isGreater ($a, $b = null) {
105
+    public static function isGreater($a, $b = null) {
106 106
         return static::compare($a, '>', $b, 'ALL');
107 107
     }
108 108
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      * @param string|Select $b
114 114
      * @return string|array
115 115
      */
116
-    public static function isGreaterOrEqual ($a, $b = null) {
116
+    public static function isGreaterOrEqual($a, $b = null) {
117 117
         return static::compare($a, '>=', $b, 'ALL');
118 118
     }
119 119
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      * @param string|Select $b
125 125
      * @return string|array
126 126
      */
127
-    public static function isLess ($a, $b = null) {
127
+    public static function isLess($a, $b = null) {
128 128
         return static::compare($a, '<', $b, 'ALL');
129 129
     }
130 130
 
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      * @param string|Select $b
136 136
      * @return string|array
137 137
      */
138
-    public static function isLessOrEqual ($a, $b = null) {
138
+    public static function isLessOrEqual($a, $b = null) {
139 139
         return static::compare($a, '<=', $b, 'ALL');
140 140
     }
141 141
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      * @param string $pattern
147 147
      * @return string|array
148 148
      */
149
-    public static function isLike ($x, string $pattern = null) {
149
+    public static function isLike($x, string $pattern = null) {
150 150
         return static::compare($x, 'LIKE', $pattern);
151 151
     }
152 152
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      * @param null|bool $identity
158 158
      * @return string|array
159 159
      */
160
-    public static function isNot ($x, $identity) {
160
+    public static function isNot($x, $identity) {
161 161
         return static::compare($x, 'IS NOT', ['' => 'UNKNOWN', 1 => 'TRUE', 0 => 'FALSE'][$identity]);
162 162
     }
163 163
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
      * @param string|array|Select $b
169 169
      * @return string|array
170 170
      */
171
-    public static function isNotEqual ($a, $b = null) {
171
+    public static function isNotEqual($a, $b = null) {
172 172
         return static::compare($a, '<>', $b, 'ALL', 'NOT IN');
173 173
     }
174 174
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
      * @param string $pattern
180 180
      * @return string|array
181 181
      */
182
-    public static function isNotLike ($x, string $pattern = null) {
182
+    public static function isNotLike($x, string $pattern = null) {
183 183
         return static::compare($x, 'NOT LIKE', $pattern);
184 184
     }
185 185
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      * @param string|array $x
190 190
      * @return string|array
191 191
      */
192
-    public static function isNotNull ($x) {
192
+    public static function isNotNull($x) {
193 193
         if (is_array($x)) {
194 194
             return array_map(__METHOD__, $x);
195 195
         }
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      * @param string $pattern
204 204
      * @return string|array
205 205
      */
206
-    public static function isNotRegExp ($x, string $pattern = null) {
206
+    public static function isNotRegExp($x, string $pattern = null) {
207 207
         return static::compare($x, 'NOT REGEXP', $pattern);
208 208
     }
209 209
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
      * @param string $pattern
215 215
      * @return string|array
216 216
      */
217
-    public static function isRegExp ($x, string $pattern = null) {
217
+    public static function isRegExp($x, string $pattern = null) {
218 218
         return static::compare($x, 'REGEXP', $pattern);
219 219
     }
220 220
 
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      * @param string|array $x
225 225
      * @return string|array
226 226
      */
227
-    public static function not ($x) {
227
+    public static function not($x) {
228 228
         if (is_array($x)) {
229 229
             return array_map(__METHOD__, $x);
230 230
         }
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
      * @param string[] $columns
240 240
      * @return string[] `[column => :column]`
241 241
      */
242
-    public static function slots (array $columns): array {
242
+    public static function slots(array $columns): array {
243 243
         $slots = [];
244 244
         foreach ($columns as $column) {
245 245
             $slots[(string)$column] = ':' . str_replace('.', '__', $column);
@@ -247,6 +247,6 @@  discard block
 block discarded – undo
247 247
         return $slots;
248 248
     }
249 249
 
250
-    final private function __construct () { }
250
+    final private function __construct() { }
251 251
 
252 252
 }
253 253
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -74,11 +74,9 @@
 block discarded – undo
74 74
                 $cmp[$k] = static::compare($k, $operator, $v, $subqueryOperator, $listOperator);
75 75
             }
76 76
             return $cmp;
77
-        }
78
-        elseif (is_array($b)) {
77
+        } elseif (is_array($b)) {
79 78
             return "{$a} {$listOperator} (" . implode(',', $b) . ")";
80
-        }
81
-        elseif ($b instanceof Select) {
79
+        } elseif ($b instanceof Select) {
82 80
             return "{$a} {$operator} {$subqueryOperator} ({$b->toSql()})";
83 81
         }
84 82
         return "{$a} {$operator} {$b}";
Please login to merge, or discard this patch.
src/DB/Table.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      * @param string $name
29 29
      * @param string[] $columns
30 30
      */
31
-    public function __construct (DB $db, $name, array $columns) {
31
+    public function __construct(DB $db, $name, array $columns) {
32 32
         parent::__construct($db);
33 33
         $this->name = $name;
34 34
         foreach ($columns as $column) {
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      *
42 42
      * @return string
43 43
      */
44
-    final public function __toString (): string {
44
+    final public function __toString(): string {
45 45
         return $this->name;
46 46
     }
47 47
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      * @param array $values
52 52
      * @return int Rows affected.
53 53
      */
54
-    public function apply (array $values): int {
54
+    public function apply(array $values): int {
55 55
         $columns = implode(',', array_keys($values));
56 56
         $values = implode(',', $this->db->quote($values));
57 57
         switch ($this->db->getDriver()) {
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
      * @param array $match
71 71
      * @return int Rows affected.
72 72
      */
73
-    public function delete (array $match): int {
73
+    public function delete(array $match): int {
74 74
         $match = SQL::all($this->db->match($match));
75 75
         return $this->db->exec("DELETE FROM {$this} WHERE {$match}");
76 76
     }
@@ -78,14 +78,14 @@  discard block
 block discarded – undo
78 78
     /**
79 79
      * @return Column[]
80 80
      */
81
-    final public function getColumns (): array {
81
+    final public function getColumns(): array {
82 82
         return $this->columns;
83 83
     }
84 84
 
85 85
     /**
86 86
      * @return string
87 87
      */
88
-    final public function getName (): string {
88
+    final public function getName(): string {
89 89
         return $this->name;
90 90
     }
91 91
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      * @param array $values
96 96
      * @return int Insertion ID.
97 97
      */
98
-    public function insert (array $values): int {
98
+    public function insert(array $values): int {
99 99
         $columns = implode(',', array_keys($values));
100 100
         $values = implode(',', $this->db->quote($values));
101 101
         $this->db->exec("INSERT INTO {$this} ($columns) VALUES ($values)");
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      * @param string $name
107 107
      * @return bool
108 108
      */
109
-    final public function offsetExists ($name): bool {
109
+    final public function offsetExists($name): bool {
110 110
         return isset($this->columns[$name]);
111 111
     }
112 112
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      * @param string $name
115 115
      * @return Column
116 116
      */
117
-    final public function offsetGet ($name): Column {
117
+    final public function offsetGet($name): Column {
118 118
         return $this->columns[$name];
119 119
     }
120 120
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      * @param string[] $columns Defaults to all columns.
125 125
      * @return Select
126 126
      */
127
-    public function select (array $columns = []): Select {
127
+    public function select(array $columns = []): Select {
128 128
         if (!$columns) {
129 129
             $columns = $this->columns;
130 130
         }
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      * @param array $match
141 141
      * @return int Rows affected.
142 142
      */
143
-    public function update (array $values, array $match): int {
143
+    public function update(array $values, array $match): int {
144 144
         $values = implode(', ', SQL::isEqual($this->db->quote($values)));
145 145
         $match = SQL::all($this->db->match($match));
146 146
         return $this->db->exec("UPDATE {$this} SET {$values} WHERE {$match}");
Please login to merge, or discard this patch.
src/DB/Junction.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      * @param DB $db
32 32
      * @param string $interface
33 33
      */
34
-    public function __construct (DB $db, string $interface) {
34
+    public function __construct(DB $db, string $interface) {
35 35
         $this->interface = $interface;
36 36
         try {
37 37
             $interface = new ReflectionClass($interface);
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      * @param EntityInterface $entity
58 58
      * @return int
59 59
      */
60
-    public function count (EntityInterface $entity): int {
60
+    public function count(EntityInterface $entity): int {
61 61
         $key = $this->getKey($entity);
62 62
         $count = $this->cache("count.{$key}", function() use ($key) {
63 63
             return $this->select(['COUNT(*)'])->where("{$key}=:id")->prepare();
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
      * @param string $class
76 76
      * @return Select
77 77
      */
78
-    public function getCollection (EntityInterface $owner, string $class): Select {
78
+    public function getCollection(EntityInterface $owner, string $class): Select {
79 79
         $record = $this->db->getRecord($class);
80 80
         $select = $record->select();
81 81
         $select->join($this, "{$this}.{$this->getKey($class)}={$record}.id");
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
     /**
87 87
      * @return string
88 88
      */
89
-    final public function getInterface (): string {
89
+    final public function getInterface(): string {
90 90
         return $this->interface;
91 91
     }
92 92
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
      * @param EntityInterface|string $class
97 97
      * @return string
98 98
      */
99
-    public function getKey ($class): string {
99
+    public function getKey($class): string {
100 100
         if (is_object($class)) {
101 101
             $class = get_class($class);
102 102
         }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      * @param EntityInterface[] $entities
115 115
      * @return int Rows affected.
116 116
      */
117
-    public function link (array $entities): int {
117
+    public function link(array $entities): int {
118 118
         $apply = [];
119 119
         foreach ($entities as $entity) {
120 120
             $apply[$this->getKey($entity)] = $entity->getId();
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      * @param EntityInterface[] $entities
132 132
      * @return int Rows affected.
133 133
      */
134
-    public function unlink (array $entities): int {
134
+    public function unlink(array $entities): int {
135 135
         $match = [];
136 136
         foreach ($entities as $entity) {
137 137
             $match[$this->getKey($entity)] = $entity->getId();
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,8 +35,7 @@
 block discarded – undo
35 35
         $this->interface = $interface;
36 36
         try {
37 37
             $interface = new ReflectionClass($interface);
38
-        }
39
-        catch (ReflectionException $exception) {
38
+        } catch (ReflectionException $exception) {
40 39
             throw new LogicException('Unexpected ReflectionException', 0, $exception);
41 40
         }
42 41
         $doc = $interface->getDocComment();
Please login to merge, or discard this patch.