@@ -10,5 +10,5 @@ |
||
10 | 10 | /** |
11 | 11 | * @return string |
12 | 12 | */ |
13 | - public function __toString (); |
|
13 | + public function __toString(); |
|
14 | 14 | } |
15 | 15 | \ No newline at end of file |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @param string $subject |
53 | 53 | * @param array $values `[when => then]` for the subject. |
54 | 54 | */ |
55 | - public function __construct (DB $db, string $subject = null, array $values = []) { |
|
55 | + public function __construct(DB $db, string $subject = null, array $values = []) { |
|
56 | 56 | parent::__construct($db, ''); |
57 | 57 | $this->subject = $subject; |
58 | 58 | $this->setValues($values); |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | /** |
62 | 62 | * @return string |
63 | 63 | */ |
64 | - public function __toString () { |
|
64 | + public function __toString() { |
|
65 | 65 | $sql = 'CASE'; |
66 | 66 | if (isset($this->subject)) { |
67 | 67 | $sql .= " {$this->subject}"; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @param string|ValueInterface $else |
81 | 81 | * @return $this |
82 | 82 | */ |
83 | - public function setElse ($else) { |
|
83 | + public function setElse($else) { |
|
84 | 84 | $this->else = isset($else) ? $this->db->quote($else) : null; |
85 | 85 | return $this; |
86 | 86 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * @param string|ValueInterface $then |
93 | 93 | * @return $this |
94 | 94 | */ |
95 | - public function setValue ($when, $then) { |
|
95 | + public function setValue($when, $then) { |
|
96 | 96 | $this->values[$this->db->quote($when)] = $this->db->quote($then); |
97 | 97 | return $this; |
98 | 98 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @param array $values `[when => then]` |
104 | 104 | * @return $this |
105 | 105 | */ |
106 | - public function setValues (array $values) { |
|
106 | + public function setValues(array $values) { |
|
107 | 107 | foreach ($values as $when => $then) { |
108 | 108 | $this->setValue($when, $then); |
109 | 109 | } |
@@ -66,8 +66,7 @@ |
||
66 | 66 | } |
67 | 67 | if ($arg === null or is_bool($arg)) { |
68 | 68 | $arg = ['' => 'NULL', 1 => 'TRUE', 0 => 'FALSE'][$arg]; |
69 | - } |
|
70 | - else { |
|
69 | + } else { |
|
71 | 70 | $arg = $this->db->quote($arg); |
72 | 71 | } |
73 | 72 | $oper = ['mysql' => '<=>', 'sqlite' => 'IS'][$driver]; |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param array $values |
29 | 29 | * @return Value |
30 | 30 | */ |
31 | - public function coalesce (array $values) { |
|
31 | + public function coalesce(array $values) { |
|
32 | 32 | array_unshift($values, $this); |
33 | 33 | $values = $this->db->quoteList($values); |
34 | 34 | return $this->db->factory(Value::class, $this->db, "COALESCE({$values})"); |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @param array $values `[when => then]` |
41 | 41 | * @return Choice |
42 | 42 | */ |
43 | - public function getChoice (array $values) { |
|
43 | + public function getChoice(array $values) { |
|
44 | 44 | return $this->db->factory(Choice::class, $this->db, "{$this}", $values); |
45 | 45 | } |
46 | 46 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param null|bool|number|string|Select $arg |
54 | 54 | * @return Predicate |
55 | 55 | */ |
56 | - public function is ($arg): Predicate { |
|
56 | + public function is($arg): Predicate { |
|
57 | 57 | $driver = $this->db->getDriver(); |
58 | 58 | if ($arg instanceof Select) { |
59 | 59 | switch ($driver) { |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @param number $max |
83 | 83 | * @return Predicate |
84 | 84 | */ |
85 | - public function isBetween ($min, $max) { |
|
85 | + public function isBetween($min, $max) { |
|
86 | 86 | $min = $this->db->quote($min); |
87 | 87 | $max = $this->db->quote($max); |
88 | 88 | return $this->db->factory(Predicate::class, "{$this} BETWEEN {$min} AND {$max}"); |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @param bool|number|string|array|Select $arg |
95 | 95 | * @return Predicate |
96 | 96 | */ |
97 | - public function isEqual ($arg) { |
|
97 | + public function isEqual($arg) { |
|
98 | 98 | return $this->db->match($this, $arg); |
99 | 99 | } |
100 | 100 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param string $multi `ALL|ANY` |
111 | 111 | * @return Predicate |
112 | 112 | */ |
113 | - public function isGreater ($arg, string $multi = 'ALL') { |
|
113 | + public function isGreater($arg, string $multi = 'ALL') { |
|
114 | 114 | if ($arg instanceof Select) { |
115 | 115 | switch ($this->db) { |
116 | 116 | case 'sqlite': |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @param string $multi `ALL|ANY` |
142 | 142 | * @return Predicate |
143 | 143 | */ |
144 | - public function isGreaterOrEqual ($arg, string $multi = 'ALL') { |
|
144 | + public function isGreaterOrEqual($arg, string $multi = 'ALL') { |
|
145 | 145 | if ($arg instanceof Select) { |
146 | 146 | switch ($this->db) { |
147 | 147 | case 'sqlite': |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @param string $multi `ALL|ANY` |
173 | 173 | * @return Predicate |
174 | 174 | */ |
175 | - public function isLess ($arg, string $multi = 'ALL') { |
|
175 | + public function isLess($arg, string $multi = 'ALL') { |
|
176 | 176 | if ($arg instanceof Select) { |
177 | 177 | switch ($this->db) { |
178 | 178 | case 'sqlite': |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @param string $multi `ALL|ANY` |
204 | 204 | * @return Predicate |
205 | 205 | */ |
206 | - public function isLessOrEqual ($arg, string $multi = 'ALL') { |
|
206 | + public function isLessOrEqual($arg, string $multi = 'ALL') { |
|
207 | 207 | if ($arg instanceof Select) { |
208 | 208 | switch ($this->db) { |
209 | 209 | case 'sqlite': |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * @param string $pattern |
229 | 229 | * @return Predicate |
230 | 230 | */ |
231 | - public function isLike (string $pattern) { |
|
231 | + public function isLike(string $pattern) { |
|
232 | 232 | $pattern = $this->db->quote($pattern); |
233 | 233 | return $this->db->factory(Predicate::class, "{$this} LIKE {$pattern}"); |
234 | 234 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @param null|bool|number|string|Select $arg |
240 | 240 | * @return Predicate |
241 | 241 | */ |
242 | - public function isNot ($arg) { |
|
242 | + public function isNot($arg) { |
|
243 | 243 | return $this->is($arg)->invert(); |
244 | 244 | } |
245 | 245 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * @param number $max |
251 | 251 | * @return Predicate |
252 | 252 | */ |
253 | - public function isNotBetween ($min, $max) { |
|
253 | + public function isNotBetween($min, $max) { |
|
254 | 254 | $min = $this->db->quote($min); |
255 | 255 | $max = $this->db->quote($max); |
256 | 256 | return $this->db->factory(Predicate::class, "{$this} NOT BETWEEN {$min} AND {$max}"); |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @param bool|number|string|array|Select $arg |
263 | 263 | * @return Predicate |
264 | 264 | */ |
265 | - public function isNotEqual ($arg) { |
|
265 | + public function isNotEqual($arg) { |
|
266 | 266 | if ($arg instanceof Select) { |
267 | 267 | return $this->db->factory(Predicate::class, "{$this} NOT IN ({$arg->toSql()})"); |
268 | 268 | } |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @param string $pattern |
279 | 279 | * @return Predicate |
280 | 280 | */ |
281 | - public function isNotLike (string $pattern) { |
|
281 | + public function isNotLike(string $pattern) { |
|
282 | 282 | $pattern = $this->db->quote($pattern); |
283 | 283 | return $this->db->factory(Predicate::class, "{$this} NOT LIKE {$pattern}"); |
284 | 284 | } |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * @param string $pattern |
290 | 290 | * @return Predicate |
291 | 291 | */ |
292 | - public function isNotRegExp (string $pattern) { |
|
292 | + public function isNotRegExp(string $pattern) { |
|
293 | 293 | $pattern = $this->db->quote($pattern); |
294 | 294 | return $this->db->factory(Predicate::class, "{$this} NOT REGEXP {$pattern}"); |
295 | 295 | } |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * @param string $pattern |
301 | 301 | * @return Predicate |
302 | 302 | */ |
303 | - public function isRegExp (string $pattern) { |
|
303 | + public function isRegExp(string $pattern) { |
|
304 | 304 | $pattern = $this->db->quote($pattern); |
305 | 305 | return $this->db->factory(Predicate::class, "{$this} REGEXP {$pattern}"); |
306 | 306 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @param string|EntityInterface $class |
60 | 60 | * @return Record |
61 | 61 | */ |
62 | - public static function fromClass (DB $db, $class) { |
|
62 | + public static function fromClass(DB $db, $class) { |
|
63 | 63 | try { |
64 | 64 | $rClass = new ReflectionClass($class); |
65 | 65 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * @param string[] $columns Property names. |
93 | 93 | * @param EAV[] $eav Keyed by property name. |
94 | 94 | */ |
95 | - public function __construct (DB $db, EntityInterface $proto, string $table, array $columns, array $eav = []) { |
|
95 | + public function __construct(DB $db, EntityInterface $proto, string $table, array $columns, array $eav = []) { |
|
96 | 96 | parent::__construct($db, $table, $columns); |
97 | 97 | $this->proto = $proto; |
98 | 98 | try { |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @param array[] $eavMatch `[eav property => attribute => mixed]` |
129 | 129 | * @return Select |
130 | 130 | */ |
131 | - public function find (array $match, array $eavMatch = []) { |
|
131 | + public function find(array $match, array $eavMatch = []) { |
|
132 | 132 | $select = $this->select(); |
133 | 133 | foreach ($match as $a => $b) { |
134 | 134 | $select->where($this->db->match($this[$a] ?? $a, $b)); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * @param Statement $statement |
147 | 147 | * @return EntityInterface[] Enumerated |
148 | 148 | */ |
149 | - public function getAll (Statement $statement): array { |
|
149 | + public function getAll(Statement $statement): array { |
|
150 | 150 | return iterator_to_array($this->getEach($statement)); |
151 | 151 | } |
152 | 152 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @param Statement $statement |
158 | 158 | * @return Generator |
159 | 159 | */ |
160 | - public function getEach (Statement $statement) { |
|
160 | + public function getEach(Statement $statement) { |
|
161 | 161 | do { |
162 | 162 | $entities = []; |
163 | 163 | for ($i = 0; $i < 256 and false !== $row = $statement->fetch(); $i++) { |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | * @param string $property |
176 | 176 | * @return EAV |
177 | 177 | */ |
178 | - final public function getEav (string $property) { |
|
178 | + final public function getEav(string $property) { |
|
179 | 179 | return $this->eav[$property]; |
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
183 | 183 | * @return EntityInterface |
184 | 184 | */ |
185 | - public function getProto () { |
|
185 | + public function getProto() { |
|
186 | 186 | return $this->proto; |
187 | 187 | } |
188 | 188 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * @param EntityInterface $entity |
191 | 191 | * @return array |
192 | 192 | */ |
193 | - protected function getValues (EntityInterface $entity): array { |
|
193 | + protected function getValues(EntityInterface $entity): array { |
|
194 | 194 | $values = []; |
195 | 195 | foreach (array_keys($this->columns) as $name) { |
196 | 196 | $values[$name] = $this->properties[$name]->getValue($entity); |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @param int $id |
205 | 205 | * @return null|EntityInterface |
206 | 206 | */ |
207 | - public function load (int $id) { |
|
207 | + public function load(int $id) { |
|
208 | 208 | $load = $this->cache(__FUNCTION__, function() { |
209 | 209 | return $this->select(array_keys($this->columns))->where('id = ?')->prepare(); |
210 | 210 | }); |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | * |
223 | 223 | * @param EntityInterface[] $entities |
224 | 224 | */ |
225 | - protected function loadEav (array $entities): void { |
|
225 | + protected function loadEav(array $entities): void { |
|
226 | 226 | $ids = array_keys($entities); |
227 | 227 | foreach ($this->eav as $name => $eav) { |
228 | 228 | foreach ($eav->loadAll($ids) as $id => $values) { |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @param EntityInterface $entity |
240 | 240 | * @return int ID |
241 | 241 | */ |
242 | - public function save (EntityInterface $entity): int { |
|
242 | + public function save(EntityInterface $entity): int { |
|
243 | 243 | if (!$entity->getId()) { |
244 | 244 | $this->saveInsert($entity); |
245 | 245 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | /** |
254 | 254 | * @param EntityInterface $entity |
255 | 255 | */ |
256 | - protected function saveEav (EntityInterface $entity): void { |
|
256 | + protected function saveEav(EntityInterface $entity): void { |
|
257 | 257 | $id = $entity->getId(); |
258 | 258 | foreach ($this->eav as $name => $eav) { |
259 | 259 | $values = $this->properties[$name]->getValue($entity); |
@@ -268,7 +268,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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); |
@@ -62,8 +62,7 @@ discard block |
||
62 | 62 | public static function fromClass (DB $db, $class) { |
63 | 63 | try { |
64 | 64 | $rClass = new ReflectionClass($class); |
65 | - } |
|
66 | - catch (ReflectionException $exception) { |
|
65 | + } catch (ReflectionException $exception) { |
|
67 | 66 | throw new LogicException('Unexpected ReflectionException', 0, $exception); |
68 | 67 | } |
69 | 68 | $columns = []; |
@@ -74,8 +73,7 @@ discard block |
||
74 | 73 | $name = $rProp->getName(); |
75 | 74 | if (preg_match('/@col(umn)?[\s$]/', $doc)) { |
76 | 75 | $columns[] = $name; |
77 | - } |
|
78 | - elseif (preg_match('/@eav\s+(?<table>\S+)/', $doc, $attr)) { |
|
76 | + } elseif (preg_match('/@eav\s+(?<table>\S+)/', $doc, $attr)) { |
|
79 | 77 | $eav[$name] = $db->factory(EAV::class, $db, $attr['table']); |
80 | 78 | } |
81 | 79 | } |
@@ -114,8 +112,7 @@ discard block |
||
114 | 112 | $rProp->setAccessible(true); |
115 | 113 | $this->properties[$name] = $rProp; |
116 | 114 | } |
117 | - } |
|
118 | - catch (ReflectionException $exception) { |
|
115 | + } catch (ReflectionException $exception) { |
|
119 | 116 | throw new LogicException('Unexpected ReflectionException', 0, $exception); |
120 | 117 | } |
121 | 118 | } |
@@ -242,8 +239,7 @@ discard block |
||
242 | 239 | public function save (EntityInterface $entity): int { |
243 | 240 | if (!$entity->getId()) { |
244 | 241 | $this->saveInsert($entity); |
245 | - } |
|
246 | - else { |
|
242 | + } else { |
|
247 | 243 | $this->saveUpdate($entity); |
248 | 244 | } |
249 | 245 | $this->saveEav($entity); |
@@ -39,7 +39,7 @@ discard block |
||
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 | asort($columns); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return string |
55 | 55 | */ |
56 | - final public function __toString () { |
|
56 | + final public function __toString() { |
|
57 | 57 | return $this->name; |
58 | 58 | } |
59 | 59 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param array $values |
64 | 64 | * @return int Rows affected. |
65 | 65 | */ |
66 | - public function apply (array $values): int { |
|
66 | + public function apply(array $values): int { |
|
67 | 67 | $columns = implode(',', array_keys($values)); |
68 | 68 | $values = $this->db->quoteList($values); |
69 | 69 | switch ($this->db) { |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param Closure $prepare `():Statement` |
86 | 86 | * @return Statement |
87 | 87 | */ |
88 | - protected function cache (string $key, Closure $prepare) { |
|
88 | + protected function cache(string $key, Closure $prepare) { |
|
89 | 89 | return $this->_cache[$key] ?? $this->_cache[$key] = $prepare->__invoke(); |
90 | 90 | } |
91 | 91 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param array $match `[a => b]` |
94 | 94 | * @return int |
95 | 95 | */ |
96 | - public function count (array $match = []) { |
|
96 | + public function count(array $match = []) { |
|
97 | 97 | $select = $this->select(['COUNT(*)']); |
98 | 98 | foreach ($match as $a => $b) { |
99 | 99 | $select->where($this->db->match($this[$a] ?? $a, $b)); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @param array $match |
110 | 110 | * @return int Rows affected. |
111 | 111 | */ |
112 | - public function delete (array $match): int { |
|
112 | + public function delete(array $match): int { |
|
113 | 113 | foreach ($match as $a => $b) { |
114 | 114 | $match[$a] = $this->db->match($this[$a] ?? $a, $b); |
115 | 115 | } |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | /** |
121 | 121 | * @return Column[] |
122 | 122 | */ |
123 | - final public function getColumns (): array { |
|
123 | + final public function getColumns(): array { |
|
124 | 124 | return $this->columns; |
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | 128 | * @return string |
129 | 129 | */ |
130 | - final public function getName (): string { |
|
130 | + final public function getName(): string { |
|
131 | 131 | return $this->name; |
132 | 132 | } |
133 | 133 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param array $values |
138 | 138 | * @return Statement |
139 | 139 | */ |
140 | - public function insert (array $values) { |
|
140 | + public function insert(array $values) { |
|
141 | 141 | $columns = implode(',', array_keys($values)); |
142 | 142 | $values = $this->db->quoteList($values); |
143 | 143 | return $this->db->query("INSERT INTO {$this} ($columns) VALUES ($values)"); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * @param string $name |
148 | 148 | * @return bool |
149 | 149 | */ |
150 | - public function offsetExists ($name): bool { |
|
150 | + public function offsetExists($name): bool { |
|
151 | 151 | return isset($this->columns[$name]); |
152 | 152 | } |
153 | 153 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @param string $name |
156 | 156 | * @return Column |
157 | 157 | */ |
158 | - public function offsetGet ($name) { |
|
158 | + public function offsetGet($name) { |
|
159 | 159 | return $this->columns[$name]; |
160 | 160 | } |
161 | 161 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @param string[] $columns Defaults to all columns. |
166 | 166 | * @return Select |
167 | 167 | */ |
168 | - public function select (array $columns = []) { |
|
168 | + public function select(array $columns = []) { |
|
169 | 169 | if (empty($columns)) { |
170 | 170 | $columns = $this->columns; |
171 | 171 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @param string $name |
179 | 179 | * @return Table |
180 | 180 | */ |
181 | - public function setName (string $name) { |
|
181 | + public function setName(string $name) { |
|
182 | 182 | $clone = clone $this; |
183 | 183 | $clone->name = $name; |
184 | 184 | foreach ($this->columns as $name => $column) { |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * @param array $match |
197 | 197 | * @return int Rows affected. |
198 | 198 | */ |
199 | - public function update (array $values, array $match): int { |
|
199 | + public function update(array $values, array $match): int { |
|
200 | 200 | foreach ($this->db->quoteArray($values) as $key => $value) { |
201 | 201 | $values[$key] = "{$key} = {$value}"; |
202 | 202 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @param string[] $conditions |
18 | 18 | * @return Predicate |
19 | 19 | */ |
20 | - public static function all (array $conditions) { |
|
20 | + public static function all(array $conditions) { |
|
21 | 21 | if (count($conditions) === 1) { |
22 | 22 | return new static(reset($conditions)); |
23 | 23 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param string[] $conditions |
31 | 31 | * @return Predicate |
32 | 32 | */ |
33 | - public static function any (array $conditions) { |
|
33 | + public static function any(array $conditions) { |
|
34 | 34 | if (count($conditions) === 1) { |
35 | 35 | return new static(reset($conditions)); |
36 | 36 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return Predicate |
44 | 44 | */ |
45 | - public function invert () { |
|
45 | + public function invert() { |
|
46 | 46 | return new static("NOT({$this})"); |
47 | 47 | } |
48 | 48 | } |
49 | 49 | \ No newline at end of file |
@@ -117,8 +117,7 @@ discard block |
||
117 | 117 | if ($table instanceof Select) { |
118 | 118 | $this->table = $table->toSubquery(); |
119 | 119 | $this->alias = uniqid('_') . "_{$table->alias}"; |
120 | - } |
|
121 | - else { |
|
120 | + } else { |
|
122 | 121 | $this->table = (string)$table; |
123 | 122 | $this->alias = uniqid('_') . "__{$table}"; |
124 | 123 | } |
@@ -228,8 +227,7 @@ discard block |
||
228 | 227 | public function group (string $column) { |
229 | 228 | if (!strlen($this->_group)) { |
230 | 229 | $this->_group = " GROUP BY {$column}"; |
231 | - } |
|
232 | - else { |
|
230 | + } else { |
|
233 | 231 | $this->_group .= ", {$column}"; |
234 | 232 | } |
235 | 233 | return $this; |
@@ -244,8 +242,7 @@ discard block |
||
244 | 242 | public function having (string $condition) { |
245 | 243 | if (!strlen($this->_having)) { |
246 | 244 | $this->_having = " HAVING {$condition}"; |
247 | - } |
|
248 | - else { |
|
245 | + } else { |
|
249 | 246 | $this->_having .= " AND {$condition}"; |
250 | 247 | } |
251 | 248 | return $this; |
@@ -264,8 +261,7 @@ discard block |
||
264 | 261 | $select->_limit = ''; |
265 | 262 | if ($all) { |
266 | 263 | $this->_import .= " INTERSECT ALL {$select->toSql()}"; |
267 | - } |
|
268 | - else { |
|
264 | + } else { |
|
269 | 265 | $this->_import .= " INTERSECT {$select->toSql()}"; |
270 | 266 | } |
271 | 267 | return $this; |
@@ -315,8 +311,7 @@ discard block |
||
315 | 311 | public function limit (int $limit, int $offset = 0) { |
316 | 312 | if ($limit == 0) { |
317 | 313 | $this->_limit = ''; |
318 | - } |
|
319 | - else { |
|
314 | + } else { |
|
320 | 315 | $this->_limit = " LIMIT {$limit}"; |
321 | 316 | if ($offset > 1) { |
322 | 317 | $this->_limit .= " OFFSET {$offset}"; |
@@ -454,8 +449,7 @@ discard block |
||
454 | 449 | $select->_limit = ''; |
455 | 450 | if ($all) { |
456 | 451 | $this->_import .= " UNION ALL {$select->toSql()}"; |
457 | - } |
|
458 | - else { |
|
452 | + } else { |
|
459 | 453 | $this->_import .= " UNION {$select->toSql()}"; |
460 | 454 | } |
461 | 455 | return $this; |
@@ -470,8 +464,7 @@ discard block |
||
470 | 464 | public function where (string $condition) { |
471 | 465 | if (!strlen($this->_where)) { |
472 | 466 | $this->_where = " WHERE {$condition}"; |
473 | - } |
|
474 | - else { |
|
467 | + } else { |
|
475 | 468 | $this->_where .= " AND {$condition}"; |
476 | 469 | } |
477 | 470 | return $this; |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @param string|Select $table |
113 | 113 | * @param string[] $columns |
114 | 114 | */ |
115 | - public function __construct (DB $db, $table, array $columns) { |
|
115 | + public function __construct(DB $db, $table, array $columns) { |
|
116 | 116 | parent::__construct($db); |
117 | 117 | if ($table instanceof Select) { |
118 | 118 | $this->table = $table->toSubquery(); |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @param array $args |
133 | 133 | * @return Statement |
134 | 134 | */ |
135 | - public function __invoke (array $args = []) { |
|
135 | + public function __invoke(array $args = []) { |
|
136 | 136 | return $this->execute($args); |
137 | 137 | } |
138 | 138 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return string |
143 | 143 | */ |
144 | - final public function __toString () { |
|
144 | + final public function __toString() { |
|
145 | 145 | return $this->alias; |
146 | 146 | } |
147 | 147 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @param array $args Execution arguments. |
152 | 152 | * @return int |
153 | 153 | */ |
154 | - public function count (array $args = []): int { |
|
154 | + public function count(array $args = []): int { |
|
155 | 155 | $clone = clone $this; |
156 | 156 | $clone->_columns = 'COUNT(*)'; |
157 | 157 | $clone->_order = ''; |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * @param array $args |
165 | 165 | * @return Statement |
166 | 166 | */ |
167 | - public function execute (array $args = []) { |
|
167 | + public function execute(array $args = []) { |
|
168 | 168 | if (empty($args)) { |
169 | 169 | return $this->db->query($this->toSql()); |
170 | 170 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @param array $args Execution arguments. |
180 | 180 | * @return array |
181 | 181 | */ |
182 | - public function getAll (array $args = []): array { |
|
182 | + public function getAll(array $args = []): array { |
|
183 | 183 | return iterator_to_array($this->fetcher->__invoke($this->execute($args))); |
184 | 184 | } |
185 | 185 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @param array $args Execution arguments. |
193 | 193 | * @return Generator |
194 | 194 | */ |
195 | - public function getEach (array $args = []) { |
|
195 | + public function getEach(array $args = []) { |
|
196 | 196 | yield from $this->fetcher->__invoke($this->execute($args)); |
197 | 197 | } |
198 | 198 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @param array $args |
205 | 205 | * @return mixed |
206 | 206 | */ |
207 | - public function getFirst (array $args = []) { |
|
207 | + public function getFirst(array $args = []) { |
|
208 | 208 | return $this->getEach($args)->current(); |
209 | 209 | } |
210 | 210 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return Generator |
217 | 217 | */ |
218 | - public function getIterator () { |
|
218 | + public function getIterator() { |
|
219 | 219 | yield from $this->getEach(); |
220 | 220 | } |
221 | 221 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @param string $column |
226 | 226 | * @return $this |
227 | 227 | */ |
228 | - public function group (string $column) { |
|
228 | + public function group(string $column) { |
|
229 | 229 | if (!strlen($this->_group)) { |
230 | 230 | $this->_group = " GROUP BY {$column}"; |
231 | 231 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @param string $condition |
242 | 242 | * @return $this |
243 | 243 | */ |
244 | - public function having (string $condition) { |
|
244 | + public function having(string $condition) { |
|
245 | 245 | if (!strlen($this->_having)) { |
246 | 246 | $this->_having = " HAVING {$condition}"; |
247 | 247 | } |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * @param bool $all |
259 | 259 | * @return $this |
260 | 260 | */ |
261 | - public function intersect (Select $select, $all = false) { |
|
261 | + public function intersect(Select $select, $all = false) { |
|
262 | 262 | $select = clone $select; |
263 | 263 | $select->_order = ''; |
264 | 264 | $select->_limit = ''; |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return Predicate |
278 | 278 | */ |
279 | - public function isEmpty () { |
|
279 | + public function isEmpty() { |
|
280 | 280 | return $this->db->factory(Predicate::class, "NOT EXISTS ({$this->toSql()})"); |
281 | 281 | } |
282 | 282 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @return Predicate |
287 | 287 | */ |
288 | - public function isNotEmpty () { |
|
288 | + public function isNotEmpty() { |
|
289 | 289 | return $this->db->factory(Predicate::class, "EXISTS ({$this->toSql()})"); |
290 | 290 | } |
291 | 291 | |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | * @param string $type |
298 | 298 | * @return $this |
299 | 299 | */ |
300 | - public function join ($table, string $condition, string $type = 'INNER') { |
|
300 | + public function join($table, string $condition, string $type = 'INNER') { |
|
301 | 301 | if ($table instanceof Select) { |
302 | 302 | $table = $table->toSubquery(); |
303 | 303 | } |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | * @param int $offset |
313 | 313 | * @return $this |
314 | 314 | */ |
315 | - public function limit (int $limit, int $offset = 0) { |
|
315 | + public function limit(int $limit, int $offset = 0) { |
|
316 | 316 | if ($limit == 0) { |
317 | 317 | $this->_limit = ''; |
318 | 318 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | * @param mixed $offset Ordinal or reference name. |
332 | 332 | * @return bool |
333 | 333 | */ |
334 | - public function offsetExists ($offset): bool { |
|
334 | + public function offsetExists($offset): bool { |
|
335 | 335 | return isset($this->refs[$offset]); |
336 | 336 | } |
337 | 337 | |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | * @param mixed $offset Ordinal or reference name. |
342 | 342 | * @return Column |
343 | 343 | */ |
344 | - public function offsetGet ($offset) { |
|
344 | + public function offsetGet($offset) { |
|
345 | 345 | return $this->refs[$offset]; |
346 | 346 | } |
347 | 347 | |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | * @param string $order |
352 | 352 | * @return $this |
353 | 353 | */ |
354 | - public function order (string $order) { |
|
354 | + public function order(string $order) { |
|
355 | 355 | if (strlen($order)) { |
356 | 356 | $order = " ORDER BY {$order}"; |
357 | 357 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | /** |
363 | 363 | * @return Statement |
364 | 364 | */ |
365 | - public function prepare () { |
|
365 | + public function prepare() { |
|
366 | 366 | return $this->db->prepare($this->toSql()); |
367 | 367 | } |
368 | 368 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | * @param string $alias |
371 | 371 | * @return $this |
372 | 372 | */ |
373 | - public function setAlias (string $alias) { |
|
373 | + public function setAlias(string $alias) { |
|
374 | 374 | $this->alias = $alias; |
375 | 375 | foreach ($this->refs as $k => $column) { |
376 | 376 | $this->refs[$k] = $column->setQualifier($alias); |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | * @param string[] $columns |
385 | 385 | * @return $this |
386 | 386 | */ |
387 | - public function setColumns (array $columns) { |
|
387 | + public function setColumns(array $columns) { |
|
388 | 388 | $this->refs = []; |
389 | 389 | $_columns = []; |
390 | 390 | $i = 0; |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | * @param Closure $fetcher |
415 | 415 | * @return $this |
416 | 416 | */ |
417 | - public function setFetcher (Closure $fetcher) { |
|
417 | + public function setFetcher(Closure $fetcher) { |
|
418 | 418 | $this->fetcher = $fetcher; |
419 | 419 | return $this; |
420 | 420 | } |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | * |
425 | 425 | * @return string |
426 | 426 | */ |
427 | - public function toSql (): string { |
|
427 | + public function toSql(): string { |
|
428 | 428 | $sql = "SELECT {$this->_columns} FROM {$this->table}"; |
429 | 429 | $sql .= $this->_join; |
430 | 430 | $sql .= $this->_where; |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | * |
442 | 442 | * @return string |
443 | 443 | */ |
444 | - public function toSubquery (): string { |
|
444 | + public function toSubquery(): string { |
|
445 | 445 | return "({$this->toSql()}) AS {$this->alias}"; |
446 | 446 | } |
447 | 447 | |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | * @param bool $all |
453 | 453 | * @return $this |
454 | 454 | */ |
455 | - public function union (Select $select, $all = false) { |
|
455 | + public function union(Select $select, $all = false) { |
|
456 | 456 | $select = clone $select; |
457 | 457 | $select->_order = ''; |
458 | 458 | $select->_limit = ''; |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | * @param string $condition |
472 | 472 | * @return $this |
473 | 473 | */ |
474 | - public function where (string $condition) { |
|
474 | + public function where(string $condition) { |
|
475 | 475 | if (!strlen($this->_where)) { |
476 | 476 | $this->_where = " WHERE {$condition}"; |
477 | 477 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * @return array |
32 | 32 | */ |
33 | - public function getAttributes (): array { |
|
33 | + public function getAttributes(): array { |
|
34 | 34 | return $this->attributes ?: []; |
35 | 35 | } |
36 | 36 | |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @param mixed $attr |
39 | 39 | * @return bool |
40 | 40 | */ |
41 | - public function offsetExists ($attr): bool { |
|
41 | + public function offsetExists($attr): bool { |
|
42 | 42 | return $this->attributes and array_key_exists($attr, $this->attributes); |
43 | 43 | } |
44 | 44 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @param mixed $attr |
47 | 47 | * @return null|mixed |
48 | 48 | */ |
49 | - public function offsetGet ($attr) { |
|
49 | + public function offsetGet($attr) { |
|
50 | 50 | return $this->attributes[$attr] ?? null; |
51 | 51 | } |
52 | 52 | |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | * @param mixed $attr |
55 | 55 | * @param mixed $value |
56 | 56 | */ |
57 | - public function offsetSet ($attr, $value): void { |
|
57 | + public function offsetSet($attr, $value): void { |
|
58 | 58 | $this->attributes[$attr] = $value; |
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | 62 | * @param mixed $attr |
63 | 63 | */ |
64 | - public function offsetUnset ($attr): void { |
|
64 | + public function offsetUnset($attr): void { |
|
65 | 65 | unset($this->attributes[$attr]); |
66 | 66 | } |
67 | 67 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @param array $attributes |
70 | 70 | * @return $this |
71 | 71 | */ |
72 | - public function setAttributes (array $attributes) { |
|
72 | + public function setAttributes(array $attributes) { |
|
73 | 73 | $this->attributes = $attributes; |
74 | 74 | return $this; |
75 | 75 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * |
13 | 13 | * @return Predicate |
14 | 14 | */ |
15 | - public function isFalse () { |
|
15 | + public function isFalse() { |
|
16 | 16 | return $this->db->factory(Predicate::class, "{$this} IS FALSE"); |
17 | 17 | } |
18 | 18 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @return Predicate |
23 | 23 | */ |
24 | - public function isNotNull () { |
|
24 | + public function isNotNull() { |
|
25 | 25 | return $this->db->factory(Predicate::class, "{$this} IS NOT NULL"); |
26 | 26 | } |
27 | 27 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return Predicate |
32 | 32 | */ |
33 | - public function isNull () { |
|
33 | + public function isNull() { |
|
34 | 34 | return $this->db->factory(Predicate::class, "{$this} IS NULL"); |
35 | 35 | } |
36 | 36 | } |
37 | 37 | \ No newline at end of file |