Passed
Push — master ( bd418e...873950 )
by y
01:50
created
src/DB/SQL/ComparisonTrait.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -64,8 +64,7 @@
 block discarded – undo
64 64
         }
65 65
         if ($arg === null or is_bool($arg)) {
66 66
             $arg = ['' => 'NULL', 1 => 'TRUE', 0 => 'FALSE'][$arg];
67
-        }
68
-        else {
67
+        } else {
69 68
             $arg = $this->db->quote($arg);
70 69
         }
71 70
         if ($this->db->isMySQL()) {
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      * @param array $values
27 27
      * @return Value
28 28
      */
29
-    public function coalesce (array $values) {
29
+    public function coalesce(array $values) {
30 30
         array_unshift($values, $this);
31 31
         $values = $this->db->quoteList($values);
32 32
         return $this->db->factory(Value::class, $this->db, "COALESCE({$values})");
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      * @param array $values `[when => then]`
39 39
      * @return Choice
40 40
      */
41
-    public function getChoice (array $values) {
41
+    public function getChoice(array $values) {
42 42
         return $this->db->factory(Choice::class, $this->db, "{$this}", $values);
43 43
     }
44 44
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      * @param null|bool|number|string|Select $arg
52 52
      * @return Predicate
53 53
      */
54
-    public function is ($arg): Predicate {
54
+    public function is($arg): Predicate {
55 55
         if ($arg instanceof Select) {
56 56
             if ($this->db->isSQLite()) {
57 57
                 /** @var Select $sub */
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      * @param number $max
80 80
      * @return Predicate
81 81
      */
82
-    public function isBetween ($min, $max) {
82
+    public function isBetween($min, $max) {
83 83
         $min = $this->db->quote($min);
84 84
         $max = $this->db->quote($max);
85 85
         return $this->db->factory(Predicate::class, "{$this} BETWEEN {$min} AND {$max}");
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      * @param bool|number|string|array|Select $arg
92 92
      * @return Predicate
93 93
      */
94
-    public function isEqual ($arg) {
94
+    public function isEqual($arg) {
95 95
         return $this->db->match($this, $arg);
96 96
     }
97 97
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      *
101 101
      * @return Predicate
102 102
      */
103
-    public function isFalse () {
103
+    public function isFalse() {
104 104
         return $this->db->factory(Predicate::class, "{$this} IS FALSE");
105 105
     }
106 106
 
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      * @param string $multi `ALL|ANY`
117 117
      * @return Predicate
118 118
      */
119
-    public function isGreater ($arg, string $multi = 'ALL') {
119
+    public function isGreater($arg, string $multi = 'ALL') {
120 120
         if ($arg instanceof Select) {
121 121
             switch ($this->db) {
122 122
                 case 'sqlite':
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
      * @param string $multi `ALL|ANY`
148 148
      * @return Predicate
149 149
      */
150
-    public function isGreaterOrEqual ($arg, string $multi = 'ALL') {
150
+    public function isGreaterOrEqual($arg, string $multi = 'ALL') {
151 151
         if ($arg instanceof Select) {
152 152
             switch ($this->db) {
153 153
                 case 'sqlite':
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
      * @param string $multi `ALL|ANY`
179 179
      * @return Predicate
180 180
      */
181
-    public function isLess ($arg, string $multi = 'ALL') {
181
+    public function isLess($arg, string $multi = 'ALL') {
182 182
         if ($arg instanceof Select) {
183 183
             switch ($this->db) {
184 184
                 case 'sqlite':
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
      * @param string $multi `ALL|ANY`
210 210
      * @return Predicate
211 211
      */
212
-    public function isLessOrEqual ($arg, string $multi = 'ALL') {
212
+    public function isLessOrEqual($arg, string $multi = 'ALL') {
213 213
         if ($arg instanceof Select) {
214 214
             switch ($this->db) {
215 215
                 case 'sqlite':
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
      * @param string $pattern
235 235
      * @return Predicate
236 236
      */
237
-    public function isLike (string $pattern) {
237
+    public function isLike(string $pattern) {
238 238
         $pattern = $this->db->quote($pattern);
239 239
         return $this->db->factory(Predicate::class, "{$this} LIKE {$pattern}");
240 240
     }
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
      * @param null|bool|number|string|Select $arg
246 246
      * @return Predicate
247 247
      */
248
-    public function isNot ($arg) {
248
+    public function isNot($arg) {
249 249
         return $this->is($arg)->not();
250 250
     }
251 251
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
      * @param number $max
257 257
      * @return Predicate
258 258
      */
259
-    public function isNotBetween ($min, $max) {
259
+    public function isNotBetween($min, $max) {
260 260
         $min = $this->db->quote($min);
261 261
         $max = $this->db->quote($max);
262 262
         return $this->db->factory(Predicate::class, "{$this} NOT BETWEEN {$min} AND {$max}");
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      * @param bool|number|string|array|Select $arg
269 269
      * @return Predicate
270 270
      */
271
-    public function isNotEqual ($arg) {
271
+    public function isNotEqual($arg) {
272 272
         if ($arg instanceof Select) {
273 273
             return $this->db->factory(Predicate::class, "{$this} NOT IN ({$arg->toSql()})");
274 274
         }
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
      * @param string $pattern
285 285
      * @return Predicate
286 286
      */
287
-    public function isNotLike (string $pattern) {
287
+    public function isNotLike(string $pattern) {
288 288
         $pattern = $this->db->quote($pattern);
289 289
         return $this->db->factory(Predicate::class, "{$this} NOT LIKE {$pattern}");
290 290
     }
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
      *
295 295
      * @return Predicate
296 296
      */
297
-    public function isNotNull () {
297
+    public function isNotNull() {
298 298
         return $this->db->factory(Predicate::class, "{$this} IS NOT NULL");
299 299
     }
300 300
 
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
      * @param string $pattern
305 305
      * @return Predicate
306 306
      */
307
-    public function isNotRegExp (string $pattern) {
307
+    public function isNotRegExp(string $pattern) {
308 308
         $pattern = $this->db->quote($pattern);
309 309
         return $this->db->factory(Predicate::class, "{$this} NOT REGEXP {$pattern}");
310 310
     }
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
      *
315 315
      * @return Predicate
316 316
      */
317
-    public function isNull () {
317
+    public function isNull() {
318 318
         return $this->db->factory(Predicate::class, "{$this} IS NULL");
319 319
     }
320 320
 
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
      * @param string $pattern
325 325
      * @return Predicate
326 326
      */
327
-    public function isRegExp (string $pattern) {
327
+    public function isRegExp(string $pattern) {
328 328
         $pattern = $this->db->quote($pattern);
329 329
         return $this->db->factory(Predicate::class, "{$this} REGEXP {$pattern}");
330 330
     }
Please login to merge, or discard this patch.
src/DB/Record.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
      * @param string|EntityInterface $class
65 65
      * @return Record
66 66
      */
67
-    public static function fromClass (DB $db, $class) {
67
+    public static function fromClass(DB $db, $class) {
68 68
         return (function() use ($db, $class) {
69 69
             $rClass = new ReflectionClass($class);
70 70
             $columns = [];
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      * @param string[] $columns Property names.
94 94
      * @param EAV[] $eav Keyed by property name.
95 95
      */
96
-    public function __construct (DB $db, EntityInterface $proto, string $table, array $columns, array $eav = []) {
96
+    public function __construct(DB $db, EntityInterface $proto, string $table, array $columns, array $eav = []) {
97 97
         parent::__construct($db, $table, $columns);
98 98
         $this->proto = $proto;
99 99
         (function() use ($proto, $columns, $eav) {
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      * @param array[] $eavMatch `[eav property => attribute => mixed]`
131 131
      * @return Select
132 132
      */
133
-    public function find (array $match, array $eavMatch = []) {
133
+    public function find(array $match, array $eavMatch = []) {
134 134
         $select = $this->select();
135 135
         foreach ($match as $a => $b) {
136 136
             $select->where($this->db->match($this[$a] ?? $a, $b));
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      * @param Statement $statement
149 149
      * @return EntityInterface[] Keyed by ID
150 150
      */
151
-    public function getAll (Statement $statement): array {
151
+    public function getAll(Statement $statement): array {
152 152
         return iterator_to_array($this->getEach($statement));
153 153
     }
154 154
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      * @param Statement $statement
160 160
      * @return Generator|EntityInterface[] Keyed by ID
161 161
      */
162
-    public function getEach (Statement $statement) {
162
+    public function getEach(Statement $statement) {
163 163
         do {
164 164
             $entities = [];
165 165
             for ($i = 0; $i < 256 and false !== $row = $statement->fetch(); $i++) {
@@ -176,14 +176,14 @@  discard block
 block discarded – undo
176 176
      * @param string $property
177 177
      * @return EAV
178 178
      */
179
-    final public function getEav (string $property) {
179
+    final public function getEav(string $property) {
180 180
         return $this->eav[$property];
181 181
     }
182 182
 
183 183
     /**
184 184
      * @return EntityInterface
185 185
      */
186
-    public function getProto () {
186
+    public function getProto() {
187 187
         return $this->proto;
188 188
     }
189 189
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      * @param EntityInterface $entity
192 192
      * @return array
193 193
      */
194
-    protected function getValues (EntityInterface $entity): array {
194
+    protected function getValues(EntityInterface $entity): array {
195 195
         $values = [];
196 196
         foreach (array_keys($this->columns) as $name) {
197 197
             $values[$name] = $this->properties[$name]->getValue($entity);
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      * @param int $id
206 206
      * @return null|EntityInterface
207 207
      */
208
-    public function load (int $id) {
208
+    public function load(int $id) {
209 209
         $load = $this->cache(__FUNCTION__, function() {
210 210
             return $this->select(array_keys($this->columns))->where('id = ?')->prepare();
211 211
         });
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      *
224 224
      * @param EntityInterface[] $entities
225 225
      */
226
-    protected function loadEav (array $entities): void {
226
+    protected function loadEav(array $entities): void {
227 227
         $ids = array_keys($entities);
228 228
         foreach ($this->eav as $name => $eav) {
229 229
             foreach ($eav->loadAll($ids) as $id => $values) {
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
      * @param EntityInterface $entity
239 239
      * @return int ID
240 240
      */
241
-    public function save (EntityInterface $entity): int {
241
+    public function save(EntityInterface $entity): int {
242 242
         if (!$entity->getId()) {
243 243
             $this->saveInsert($entity);
244 244
         }
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
     /**
253 253
      * @param EntityInterface $entity
254 254
      */
255
-    protected function saveEav (EntityInterface $entity): void {
255
+    protected function saveEav(EntityInterface $entity): void {
256 256
         $id = $entity->getId();
257 257
         foreach ($this->eav as $name => $eav) {
258 258
             // may be null to skip
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      *
269 269
      * @param EntityInterface $entity
270 270
      */
271
-    protected function saveInsert (EntityInterface $entity): void {
271
+    protected function saveInsert(EntityInterface $entity): void {
272 272
         $insert = $this->cache(__FUNCTION__, function() {
273 273
             $slots = SQL::slots(array_keys($this->columns));
274 274
             unset($slots['id']);
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
      *
287 287
      * @param EntityInterface $entity
288 288
      */
289
-    protected function saveUpdate (EntityInterface $entity): void {
289
+    protected function saveUpdate(EntityInterface $entity): void {
290 290
         $this->cache(__FUNCTION__, function() {
291 291
             $slots = SQL::slotsEqual(array_keys($this->columns));
292 292
             unset($slots['id']);
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
      * @param array $columns Defaults to all columns.
302 302
      * @return Select
303 303
      */
304
-    public function select (array $columns = []) {
304
+    public function select(array $columns = []) {
305 305
         $select = parent::select($columns);
306 306
         if (empty($columns)) {
307 307
             $select->setFetcher(function(Statement $statement) {
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
      * @param EntityInterface $proto
316 316
      * @return $this
317 317
      */
318
-    public function setProto (EntityInterface $proto) {
318
+    public function setProto(EntityInterface $proto) {
319 319
         $this->proto = $proto;
320 320
         return $this;
321 321
     }
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
      * @param EntityInterface $entity
325 325
      * @param array $values
326 326
      */
327
-    protected function setValues (EntityInterface $entity, array $values): void {
327
+    protected function setValues(EntityInterface $entity, array $values): void {
328 328
         foreach ($values as $name => $value) {
329 329
             settype($value, $this->types[$name]);
330 330
             $this->properties[$name]->setValue($entity, $value);
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -73,8 +73,7 @@  discard block
 block discarded – undo
73 73
             foreach ($rClass->getProperties() as $rProp) {
74 74
                 if (preg_match('/@col(umn)?[\s$]/', $rProp->getDocComment())) {
75 75
                     $columns[] = $rProp->getName();
76
-                }
77
-                elseif (preg_match('/@eav\s+(?<table>\S+)/', $rProp->getDocComment(), $attr)) {
76
+                } elseif (preg_match('/@eav\s+(?<table>\S+)/', $rProp->getDocComment(), $attr)) {
78 77
                     $eav[$rProp->getName()] = $db->factory(EAV::class, $db, $attr['table']);
79 78
                 }
80 79
             }
@@ -241,8 +240,7 @@  discard block
 block discarded – undo
241 240
     public function save (EntityInterface $entity): int {
242 241
         if (!$entity->getId()) {
243 242
             $this->saveInsert($entity);
244
-        }
245
-        else {
243
+        } else {
246 244
             $this->saveUpdate($entity);
247 245
         }
248 246
         $this->saveEav($entity);
Please login to merge, or discard this patch.
src/DB/Table.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      * @param string $name
40 40
      * @param string[] $columns
41 41
      */
42
-    public function __construct (DB $db, $name, array $columns) {
42
+    public function __construct(DB $db, $name, array $columns) {
43 43
         parent::__construct($db);
44 44
         $this->name = $name;
45 45
         foreach ($columns as $column) {
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @return string
54 54
      */
55
-    final public function __toString () {
55
+    final public function __toString() {
56 56
         return $this->name;
57 57
     }
58 58
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
      * @param array $values
63 63
      * @return int Rows affected.
64 64
      */
65
-    public function apply (array $values): int {
65
+    public function apply(array $values): int {
66 66
         $columns = implode(',', array_keys($values));
67 67
         $values = $this->db->quoteList($values);
68 68
         switch ($this->db) {
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      * @param Closure $prepare `():Statement`
85 85
      * @return Statement
86 86
      */
87
-    protected function cache (string $key, Closure $prepare) {
87
+    protected function cache(string $key, Closure $prepare) {
88 88
         return $this->_cache[$key] ?? $this->_cache[$key] = $prepare->__invoke();
89 89
     }
90 90
 
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
      * @param array $match `[a => b]`
93 93
      * @return int
94 94
      */
95
-    public function count (array $match = []) {
95
+    public function count(array $match = []) {
96 96
         $select = $this->select(['COUNT(*)']);
97 97
         foreach ($match as $a => $b) {
98 98
             $select->where($this->db->match($this[$a] ?? $a, $b));
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      * @param array $match
109 109
      * @return int Rows affected.
110 110
      */
111
-    public function delete (array $match): int {
111
+    public function delete(array $match): int {
112 112
         foreach ($match as $a => $b) {
113 113
             $match[$a] = $this->db->match($this[$a] ?? $a, $b);
114 114
         }
@@ -119,14 +119,14 @@  discard block
 block discarded – undo
119 119
     /**
120 120
      * @return Column[]
121 121
      */
122
-    final public function getColumns (): array {
122
+    final public function getColumns(): array {
123 123
         return $this->columns;
124 124
     }
125 125
 
126 126
     /**
127 127
      * @return string
128 128
      */
129
-    final public function getName (): string {
129
+    final public function getName(): string {
130 130
         return $this->name;
131 131
     }
132 132
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
      * @param array $values
137 137
      * @return Statement
138 138
      */
139
-    public function insert (array $values) {
139
+    public function insert(array $values) {
140 140
         $columns = implode(',', array_keys($values));
141 141
         $values = $this->db->quoteList($values);
142 142
         return $this->db->query("INSERT INTO {$this} ($columns) VALUES ($values)");
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      * @param int|string $column
147 147
      * @return Column
148 148
      */
149
-    public function offsetGet ($column) {
149
+    public function offsetGet($column) {
150 150
         if (is_int($column)) {
151 151
             return current(array_slice($this->columns, $column, 1)) ?: null;
152 152
         }
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      * @param string[] $columns Defaults to all columns.
160 160
      * @return Select
161 161
      */
162
-    public function select (array $columns = []) {
162
+    public function select(array $columns = []) {
163 163
         if (empty($columns)) {
164 164
             $columns = $this->columns;
165 165
         }
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      * @param string $name
173 173
      * @return Table
174 174
      */
175
-    public function setName (string $name) {
175
+    public function setName(string $name) {
176 176
         $clone = clone $this;
177 177
         $clone->name = $name;
178 178
         foreach ($this->columns as $name => $column) {
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
      * @param array $match
191 191
      * @return int Rows affected.
192 192
      */
193
-    public function update (array $values, array $match): int {
193
+    public function update(array $values, array $match): int {
194 194
         foreach ($this->db->quoteArray($values) as $key => $value) {
195 195
             $values[$key] = "{$key} = {$value}";
196 196
         }
Please login to merge, or discard this patch.
src/DB/SQL/Predicate.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
      *
13 13
      * @return Predicate
14 14
      */
15
-    public function not () {
15
+    public function not() {
16 16
         return new static("NOT({$this})");
17 17
     }
18 18
 
Please login to merge, or discard this patch.