@@ -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 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return Numeric |
21 | 21 | */ |
22 | - public function abs () { |
|
22 | + public function abs() { |
|
23 | 23 | return new Numeric($this->db, "ABS({$this})"); |
24 | 24 | } |
25 | 25 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param number|ValueInterface $arg |
30 | 30 | * @return Numeric |
31 | 31 | */ |
32 | - public function add ($arg) { |
|
32 | + public function add($arg) { |
|
33 | 33 | return new Numeric($this->db, "({$this} + {$arg})"); |
34 | 34 | } |
35 | 35 | |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return Numeric |
40 | 40 | */ |
41 | - public function ceil () { |
|
41 | + public function ceil() { |
|
42 | 42 | return new Numeric($this->db, "CEIL({$this})"); |
43 | 43 | } |
44 | 44 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @param number|ValueInterface $arg |
49 | 49 | * @return Numeric |
50 | 50 | */ |
51 | - public function divide ($arg) { |
|
51 | + public function divide($arg) { |
|
52 | 52 | return new Numeric($this->db, "({$this} / {$arg})"); |
53 | 53 | } |
54 | 54 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return Numeric |
59 | 59 | */ |
60 | - public function floor () { |
|
60 | + public function floor() { |
|
61 | 61 | return new Numeric($this->db, "FLOOR({$this})"); |
62 | 62 | } |
63 | 63 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return Predicate |
68 | 68 | */ |
69 | - public function isEven () { |
|
69 | + public function isEven() { |
|
70 | 70 | return new Predicate("({$this} % 2) = 0"); |
71 | 71 | } |
72 | 72 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return Predicate |
77 | 77 | */ |
78 | - public function isNegative () { |
|
78 | + public function isNegative() { |
|
79 | 79 | return new Predicate("{$this} < 0"); |
80 | 80 | } |
81 | 81 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @return Predicate |
86 | 86 | */ |
87 | - public function isOdd () { |
|
87 | + public function isOdd() { |
|
88 | 88 | return new Predicate("({$this} % 2) <> 0"); |
89 | 89 | } |
90 | 90 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return Predicate |
95 | 95 | */ |
96 | - public function isPositive () { |
|
96 | + public function isPositive() { |
|
97 | 97 | return new Predicate("{$this} > 0"); |
98 | 98 | } |
99 | 99 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @param number|ValueInterface $arg |
104 | 104 | * @return Numeric |
105 | 105 | */ |
106 | - public function modulo ($arg) { |
|
106 | + public function modulo($arg) { |
|
107 | 107 | return new Numeric($this->db, "({$this} % {$arg})"); |
108 | 108 | } |
109 | 109 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @param number|ValueInterface $arg |
114 | 114 | * @return Numeric |
115 | 115 | */ |
116 | - public function multiply ($arg) { |
|
116 | + public function multiply($arg) { |
|
117 | 117 | return new Numeric($this->db, "({$this} * {$arg})"); |
118 | 118 | } |
119 | 119 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @param number|ValueInterface $exponent |
124 | 124 | * @return Numeric |
125 | 125 | */ |
126 | - public function pow ($exponent) { |
|
126 | + public function pow($exponent) { |
|
127 | 127 | return new Numeric($this->db, "POW({$this},{$exponent})"); |
128 | 128 | } |
129 | 129 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @param int $decimals |
134 | 134 | * @return Numeric |
135 | 135 | */ |
136 | - public function round (int $decimals = 0) { |
|
136 | + public function round(int $decimals = 0) { |
|
137 | 137 | return new Numeric($this->db, "ROUND({$this},{$decimals})"); |
138 | 138 | } |
139 | 139 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @param number|ValueInterface $arg |
144 | 144 | * @return Numeric |
145 | 145 | */ |
146 | - public function subtract ($arg) { |
|
146 | + public function subtract($arg) { |
|
147 | 147 | return new Numeric($this->db, "({$this} - {$arg})"); |
148 | 148 | } |
149 | 149 | } |
150 | 150 | \ 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 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param string $interface |
30 | 30 | * @return Junction |
31 | 31 | */ |
32 | - public static function fromInterface (DB $db, string $interface) { |
|
32 | + public static function fromInterface(DB $db, string $interface) { |
|
33 | 33 | try { |
34 | 34 | $ref = new ReflectionClass($interface); |
35 | 35 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @param string $table |
53 | 53 | * @param string[] $classes |
54 | 54 | */ |
55 | - public function __construct (DB $db, string $table, array $classes) { |
|
55 | + public function __construct(DB $db, string $table, array $classes) { |
|
56 | 56 | parent::__construct($db, $table, array_keys($classes)); |
57 | 57 | $this->classes = $classes; |
58 | 58 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param array $match Keyed by junction column. |
67 | 67 | * @return Select |
68 | 68 | */ |
69 | - public function getCollection (string $key, array $match = []) { |
|
69 | + public function getCollection(string $key, array $match = []) { |
|
70 | 70 | $record = $this->db->getRecord($this->classes[$key]); |
71 | 71 | $select = $record->select(); |
72 | 72 | $select->join($this, $this[$key]->isEqual($record['id'])); |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @param int[] $ids Keyed by column. |
83 | 83 | * @return int Rows affected. |
84 | 84 | */ |
85 | - public function link (array $ids): int { |
|
85 | + public function link(array $ids): int { |
|
86 | 86 | $link = $this->cache(__FUNCTION__, function() { |
87 | 87 | $columns = implode(',', array_keys($this->columns)); |
88 | 88 | $slots = implode(',', SQL::slots(array_keys($this->columns))); |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @param string $passwd |
53 | 53 | * @param array $options |
54 | 54 | */ |
55 | - public function __construct ($dsn, $username = null, $passwd = null, $options = null) { |
|
55 | + public function __construct($dsn, $username = null, $passwd = null, $options = null) { |
|
56 | 56 | parent::__construct($dsn, $username, $passwd, $options); |
57 | 57 | $this->driver = $this->getAttribute(self::ATTR_DRIVER_NAME); |
58 | 58 | $this->setAttribute(self::ATTR_DEFAULT_FETCH_MODE, self::FETCH_ASSOC); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return string |
75 | 75 | */ |
76 | - final public function __toString () { |
|
76 | + final public function __toString() { |
|
77 | 77 | return $this->driver; |
78 | 78 | } |
79 | 79 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @param string $sql |
84 | 84 | * @return int |
85 | 85 | */ |
86 | - public function exec ($sql): int { |
|
86 | + public function exec($sql): int { |
|
87 | 87 | $this->logger->__invoke($sql); |
88 | 88 | return parent::exec($sql); |
89 | 89 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | /** |
92 | 92 | * @return string |
93 | 93 | */ |
94 | - final public function getDriver (): string { |
|
94 | + final public function getDriver(): string { |
|
95 | 95 | return $this->driver; |
96 | 96 | } |
97 | 97 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @param string $interface |
102 | 102 | * @return Junction |
103 | 103 | */ |
104 | - public function getJunction ($interface) { |
|
104 | + public function getJunction($interface) { |
|
105 | 105 | if (!isset($this->junctions[$interface])) { |
106 | 106 | $this->junctions[$interface] = Junction::fromInterface($this, $interface); |
107 | 107 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | /** |
112 | 112 | * @return Closure |
113 | 113 | */ |
114 | - public function getLogger () { |
|
114 | + public function getLogger() { |
|
115 | 115 | return $this->logger; |
116 | 116 | } |
117 | 117 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @param string|EntityInterface $class |
122 | 122 | * @return Record |
123 | 123 | */ |
124 | - public function getRecord ($class) { |
|
124 | + public function getRecord($class) { |
|
125 | 125 | $name = $class; |
126 | 126 | if (is_object($name)) { |
127 | 127 | $name = get_class($name); |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * @param mixed $b |
149 | 149 | * @return string |
150 | 150 | */ |
151 | - public function match ($a, $b) { |
|
151 | + public function match($a, $b) { |
|
152 | 152 | if ($b instanceof Closure) { |
153 | 153 | if (!$a instanceof Column) { |
154 | 154 | $a = new Column($this, $a); |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @param array $match |
175 | 175 | * @return string[] |
176 | 176 | */ |
177 | - public function matchArray (array $match) { |
|
177 | + public function matchArray(array $match) { |
|
178 | 178 | return array_map([$this, 'match'], array_keys($match), $match); |
179 | 179 | } |
180 | 180 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @param string $class Class or interface name. |
183 | 183 | * @return bool |
184 | 184 | */ |
185 | - public function offsetExists ($class): bool { |
|
185 | + public function offsetExists($class): bool { |
|
186 | 186 | return (bool)$this->offsetGet($class); |
187 | 187 | } |
188 | 188 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * @param string $class Class or interface name. |
191 | 191 | * @return null|Record|Junction |
192 | 192 | */ |
193 | - public function offsetGet ($class) { |
|
193 | + public function offsetGet($class) { |
|
194 | 194 | if (class_exists($class)) { |
195 | 195 | return $this->getRecord($class); |
196 | 196 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @param string $class Class or interface name. |
205 | 205 | * @param Record|Junction $access |
206 | 206 | */ |
207 | - public function offsetSet ($class, $access) { |
|
207 | + public function offsetSet($class, $access) { |
|
208 | 208 | if ($access instanceof Record) { |
209 | 209 | $this->setRecord($class, $access); |
210 | 210 | } |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | /** |
217 | 217 | * @param string $class Class or interface name. |
218 | 218 | */ |
219 | - public function offsetUnset ($class) { |
|
219 | + public function offsetUnset($class) { |
|
220 | 220 | unset($this->records[$class]); |
221 | 221 | unset($this->junctions[$class]); |
222 | 222 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * @param array $options |
229 | 229 | * @return Statement |
230 | 230 | */ |
231 | - public function prepare ($sql, $options = []) { |
|
231 | + public function prepare($sql, $options = []) { |
|
232 | 232 | $this->logger->__invoke($sql); |
233 | 233 | /** @var Statement $statement */ |
234 | 234 | $statement = parent::prepare($sql, $options); |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * @param array $ctorargs |
245 | 245 | * @return Statement |
246 | 246 | */ |
247 | - public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) { |
|
247 | + public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []) { |
|
248 | 248 | $this->logger->__invoke($sql); |
249 | 249 | /** @var Statement $statement */ |
250 | 250 | $statement = parent::query(...func_get_args()); |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | * @param int $type Ignored. |
264 | 264 | * @return string |
265 | 265 | */ |
266 | - public function quote ($value, $type = null) { |
|
266 | + public function quote($value, $type = null) { |
|
267 | 267 | if ($value instanceof ExpressionInterface) { |
268 | 268 | return $value; |
269 | 269 | } |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @param array $values |
284 | 284 | * @return string[] |
285 | 285 | */ |
286 | - public function quoteArray (array $values): array { |
|
286 | + public function quoteArray(array $values): array { |
|
287 | 287 | return array_map([$this, 'quote'], $values); |
288 | 288 | } |
289 | 289 | |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | * @param array $values |
294 | 294 | * @return string |
295 | 295 | */ |
296 | - public function quoteList (array $values): string { |
|
296 | + public function quoteList(array $values): string { |
|
297 | 297 | return implode(',', $this->quoteArray($values)); |
298 | 298 | } |
299 | 299 | |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | * @param mixed $value |
304 | 304 | * @return string|string[] |
305 | 305 | */ |
306 | - public function quoteMixed ($value) { |
|
306 | + public function quoteMixed($value) { |
|
307 | 307 | if (is_array($value)) { |
308 | 308 | return $this->quoteArray($value); |
309 | 309 | } |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @param EntityInterface $entity |
317 | 317 | * @return int ID |
318 | 318 | */ |
319 | - public function save (EntityInterface $entity): int { |
|
319 | + public function save(EntityInterface $entity): int { |
|
320 | 320 | return $this->getRecord($entity)->save($entity); |
321 | 321 | } |
322 | 322 | |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @param Junction $junction |
326 | 326 | * @return $this |
327 | 327 | */ |
328 | - public function setJunction (string $interface, Junction $junction) { |
|
328 | + public function setJunction(string $interface, Junction $junction) { |
|
329 | 329 | $this->junctions[$interface] = $junction; |
330 | 330 | return $this; |
331 | 331 | } |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | * @param Closure $logger |
335 | 335 | * @return $this |
336 | 336 | */ |
337 | - public function setLogger (Closure $logger) { |
|
337 | + public function setLogger(Closure $logger) { |
|
338 | 338 | $this->logger = $logger; |
339 | 339 | return $this; |
340 | 340 | } |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | * @param Record $record |
345 | 345 | * @return $this |
346 | 346 | */ |
347 | - public function setRecord (string $class, Record $record) { |
|
347 | + public function setRecord(string $class, Record $record) { |
|
348 | 348 | $this->records[$class] = $record; |
349 | 349 | return $this; |
350 | 350 | } |
@@ -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 | foreach ($columns as $column) { |
@@ -52,7 +52,7 @@ discard block |
||
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 |
||
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 = implode(', ', $this->db->quoteArray($values)); |
68 | 68 | switch ($this->db) { |
@@ -84,7 +84,7 @@ discard block |
||
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 |
||
92 | 92 | * @param array $match |
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 ($this->db->matchArray($match) as $condition) { |
98 | 98 | $select->where($condition); |
@@ -108,7 +108,7 @@ discard block |
||
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 | $match = Predicate::all($this->db->matchArray($match)); |
113 | 113 | return $this->db->exec("DELETE FROM {$this} WHERE {$match}"); |
114 | 114 | } |
@@ -116,14 +116,14 @@ discard block |
||
116 | 116 | /** |
117 | 117 | * @return Column[] |
118 | 118 | */ |
119 | - final public function getColumns (): array { |
|
119 | + final public function getColumns(): array { |
|
120 | 120 | return $this->columns; |
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | 124 | * @return string |
125 | 125 | */ |
126 | - final public function getName (): string { |
|
126 | + final public function getName(): string { |
|
127 | 127 | return $this->name; |
128 | 128 | } |
129 | 129 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @param array $values |
134 | 134 | * @return Statement |
135 | 135 | */ |
136 | - public function insert (array $values) { |
|
136 | + public function insert(array $values) { |
|
137 | 137 | $columns = implode(',', array_keys($values)); |
138 | 138 | $values = implode(', ', $this->db->quoteArray($values)); |
139 | 139 | return $this->db->query("INSERT INTO {$this} ($columns) VALUES ($values)"); |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @param string $name |
144 | 144 | * @return bool |
145 | 145 | */ |
146 | - public function offsetExists ($name): bool { |
|
146 | + public function offsetExists($name): bool { |
|
147 | 147 | return isset($this->columns[$name]); |
148 | 148 | } |
149 | 149 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @param string $name |
152 | 152 | * @return Column |
153 | 153 | */ |
154 | - public function offsetGet ($name) { |
|
154 | + public function offsetGet($name) { |
|
155 | 155 | return $this->columns[$name]; |
156 | 156 | } |
157 | 157 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * @param string[] $columns Defaults to all columns. |
162 | 162 | * @return Select |
163 | 163 | */ |
164 | - public function select (array $columns = []) { |
|
164 | + public function select(array $columns = []) { |
|
165 | 165 | if (empty($columns)) { |
166 | 166 | $columns = $this->columns; |
167 | 167 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @param string $name |
175 | 175 | * @return Table |
176 | 176 | */ |
177 | - public function setName (string $name) { |
|
177 | + public function setName(string $name) { |
|
178 | 178 | $clone = clone $this; |
179 | 179 | $clone->name = $name; |
180 | 180 | foreach ($this->columns as $name => $column) { |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @param array $match |
193 | 193 | * @return int Rows affected. |
194 | 194 | */ |
195 | - public function update (array $values, array $match): int { |
|
195 | + public function update(array $values, array $match): int { |
|
196 | 196 | $values = implode(', ', $this->db->matchArray($values)); |
197 | 197 | $match = Predicate::all($this->db->matchArray($match)); |
198 | 198 | return $this->db->exec("UPDATE {$this} SET {$values} WHERE {$match}"); |
@@ -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 Additional `[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 ($this->db->matchArray($match) as $condition) { |
134 | 134 | $select->where($condition); |
@@ -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); |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return Text |
21 | 21 | */ |
22 | - public function getDate () { |
|
22 | + public function getDate() { |
|
23 | 23 | return new Text($this->db, $this->getDateTimeFormat('%Y-%m-%d')); |
24 | 24 | } |
25 | 25 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param string|array $format Format, or formats keyed by driver name. |
30 | 30 | * @return Text |
31 | 31 | */ |
32 | - public function getDateTimeFormat ($format) { |
|
32 | + public function getDateTimeFormat($format) { |
|
33 | 33 | $driver = $this->db->getDriver(); |
34 | 34 | if (is_array($format)) { |
35 | 35 | $format = $format[$driver]; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return Numeric |
50 | 50 | */ |
51 | - public function getDay () { |
|
51 | + public function getDay() { |
|
52 | 52 | return new Numeric($this->db, $this->getDateTimeFormat('%d')); |
53 | 53 | } |
54 | 54 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return Numeric |
59 | 59 | */ |
60 | - public function getDayOfWeek () { |
|
60 | + public function getDayOfWeek() { |
|
61 | 61 | return new Numeric($this->db, $this->getDateTimeFormat('%w')); |
62 | 62 | } |
63 | 63 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return Numeric |
68 | 68 | */ |
69 | - public function getDayOfYear () { |
|
69 | + public function getDayOfYear() { |
|
70 | 70 | return new Numeric($this->db, $this->getDateTimeFormat('%j')); |
71 | 71 | } |
72 | 72 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return Numeric |
77 | 77 | */ |
78 | - public function getHours () { |
|
78 | + public function getHours() { |
|
79 | 79 | return new Numeric($this->db, $this->getDateTimeFormat('%H')); |
80 | 80 | } |
81 | 81 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @return Numeric |
86 | 86 | */ |
87 | - public function getMinutes () { |
|
87 | + public function getMinutes() { |
|
88 | 88 | return new Numeric($this->db, $this->getDateTimeFormat([ |
89 | 89 | 'mysql' => '%i', |
90 | 90 | 'sqlite' => '%M' |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @return Numeric |
98 | 98 | */ |
99 | - public function getMonth () { |
|
99 | + public function getMonth() { |
|
100 | 100 | return new Numeric($this->db, $this->getDateTimeFormat('%m')); |
101 | 101 | } |
102 | 102 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return Numeric |
107 | 107 | */ |
108 | - public function getSeconds () { |
|
108 | + public function getSeconds() { |
|
109 | 109 | return new Numeric($this->db, $this->getDateTimeFormat('%S')); |
110 | 110 | } |
111 | 111 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @return Text |
116 | 116 | */ |
117 | - public function getTime () { |
|
117 | + public function getTime() { |
|
118 | 118 | return new Text($this->db, $this->getDateTimeFormat([ |
119 | 119 | 'mysql' => '%H:%i:%S', |
120 | 120 | 'sqlite' => '%H:%M:%S' |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @return Numeric |
128 | 128 | */ |
129 | - public function getTimestamp () { |
|
129 | + public function getTimestamp() { |
|
130 | 130 | switch ($this->db) { |
131 | 131 | case 'sqlite': |
132 | 132 | return new Numeric($this->db, "STRFTIME('%s',{$this})"); |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return Numeric |
142 | 142 | */ |
143 | - public function getWeekOfYear () { |
|
143 | + public function getWeekOfYear() { |
|
144 | 144 | return new Numeric($this->db, $this->getDateTimeFormat([ |
145 | 145 | 'mysql' => '%U', |
146 | 146 | 'sqlite' => '%W' |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return Numeric |
154 | 154 | */ |
155 | - public function getYear () { |
|
155 | + public function getYear() { |
|
156 | 156 | return new Numeric($this->db, $this->getDateTimeFormat('%Y')); |
157 | 157 | } |
158 | 158 | } |
159 | 159 | \ No newline at end of file |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @return Numeric |
16 | 16 | */ |
17 | - public function toFloat () { |
|
17 | + public function toFloat() { |
|
18 | 18 | switch ($this->db) { |
19 | 19 | case 'sqlite': |
20 | 20 | return new Numeric($this->db, "CAST({$this} AS REAL)"); |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return Numeric |
30 | 30 | */ |
31 | - public function toInt () { |
|
31 | + public function toInt() { |
|
32 | 32 | switch ($this->db) { |
33 | 33 | case 'sqlite': |
34 | 34 | return new Numeric($this->db, "CAST({$this} AS INTEGER)"); |