@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @param DB $db |
63 | 63 | * @param string $class |
64 | 64 | */ |
65 | - public function __construct (DB $db, string $class) { |
|
65 | + public function __construct(DB $db, string $class) { |
|
66 | 66 | $this->class = $class; |
67 | 67 | try { |
68 | 68 | $class = new ReflectionClass($class); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @param Statement $statement |
106 | 106 | * @return EntityInterface[] Enumerated |
107 | 107 | */ |
108 | - public function fetchAll (Statement $statement): array { |
|
108 | + public function fetchAll(Statement $statement): array { |
|
109 | 109 | $entities = []; |
110 | 110 | foreach ($statement->fetchAll() as $row) { |
111 | 111 | $clone = clone $this->proto; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @param array[] $eavMatch Additional `[eav property => attribute => mixed]` |
126 | 126 | * @return Select |
127 | 127 | */ |
128 | - public function find (array $match, array $eavMatch = []): Select { |
|
128 | + public function find(array $match, array $eavMatch = []): Select { |
|
129 | 129 | $select = $this->select(); |
130 | 130 | foreach ($match as $column => $value) { |
131 | 131 | $select->where($this->db->match($column, $value)); |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | /** |
141 | 141 | * @return string |
142 | 142 | */ |
143 | - final public function getClass (): string { |
|
143 | + final public function getClass(): string { |
|
144 | 144 | return $this->class; |
145 | 145 | } |
146 | 146 | |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | * @param string $property |
149 | 149 | * @return EAV |
150 | 150 | */ |
151 | - final public function getEav (string $property): EAV { |
|
151 | + final public function getEav(string $property): EAV { |
|
152 | 152 | return $this->eav[$property]; |
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
156 | 156 | * @return EntityInterface |
157 | 157 | */ |
158 | - public function getProto (): EntityInterface { |
|
158 | + public function getProto(): EntityInterface { |
|
159 | 159 | return $this->proto; |
160 | 160 | } |
161 | 161 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @param EntityInterface $entity |
164 | 164 | * @return array |
165 | 165 | */ |
166 | - protected function getValues (EntityInterface $entity): array { |
|
166 | + protected function getValues(EntityInterface $entity): array { |
|
167 | 167 | $values = []; |
168 | 168 | foreach (array_keys($this->columns) as $name) { |
169 | 169 | $values[$name] = $this->properties[$name]->getValue($entity); |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @param int $id |
178 | 178 | * @return null|EntityInterface |
179 | 179 | */ |
180 | - public function load (int $id): ?EntityInterface { |
|
180 | + public function load(int $id): ?EntityInterface { |
|
181 | 181 | $load = $this->cache(__FUNCTION__, function() { |
182 | 182 | return $this->select()->where('id = ?')->prepare(); |
183 | 183 | })->execute([$id]); |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * |
196 | 196 | * @param EntityInterface[] $entities |
197 | 197 | */ |
198 | - protected function loadEav (array $entities): void { |
|
198 | + protected function loadEav(array $entities): void { |
|
199 | 199 | $ids = array_keys($entities); |
200 | 200 | foreach ($this->eav as $name => $eav) { |
201 | 201 | foreach ($eav->loadAll($ids) as $id => $values) { |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * @param EntityInterface $entity |
211 | 211 | * @return int ID |
212 | 212 | */ |
213 | - public function save (EntityInterface $entity): int { |
|
213 | + public function save(EntityInterface $entity): int { |
|
214 | 214 | if (!$entity->getId()) { |
215 | 215 | $this->saveInsert($entity); |
216 | 216 | } |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | /** |
225 | 225 | * @param EntityInterface $entity |
226 | 226 | */ |
227 | - protected function saveEav (EntityInterface $entity): void { |
|
227 | + protected function saveEav(EntityInterface $entity): void { |
|
228 | 228 | $id = $entity->getId(); |
229 | 229 | foreach ($this->eav as $name => $eav) { |
230 | 230 | $values = $this->properties[$name]->getValue($entity); |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * |
240 | 240 | * @param EntityInterface $entity |
241 | 241 | */ |
242 | - protected function saveInsert (EntityInterface $entity): void { |
|
242 | + protected function saveInsert(EntityInterface $entity): void { |
|
243 | 243 | $values = $this->getValues($entity); |
244 | 244 | unset($values['id']); |
245 | 245 | $insert = $this->cache(__FUNCTION__, function() { |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | * |
258 | 258 | * @param EntityInterface $entity |
259 | 259 | */ |
260 | - protected function saveUpdate (EntityInterface $entity): void { |
|
260 | + protected function saveUpdate(EntityInterface $entity): void { |
|
261 | 261 | $this->cache(__FUNCTION__, function() { |
262 | 262 | $slots = SQL::slots(array_keys($this->columns)); |
263 | 263 | unset($slots['id']); |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * @param array $columns Defaults to all columns. |
273 | 273 | * @return Select |
274 | 274 | */ |
275 | - public function select (array $columns = []): Select { |
|
275 | + public function select(array $columns = []): Select { |
|
276 | 276 | return parent::select($columns)->setFetcher(function(Statement $statement) { |
277 | 277 | return $this->fetchAll($statement); |
278 | 278 | }); |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @param EntityInterface $proto |
283 | 283 | * @return $this |
284 | 284 | */ |
285 | - public function setProto (EntityInterface $proto) { |
|
285 | + public function setProto(EntityInterface $proto) { |
|
286 | 286 | $this->proto = $proto; |
287 | 287 | return $this; |
288 | 288 | } |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @param EntityInterface $entity |
292 | 292 | * @param array $values |
293 | 293 | */ |
294 | - protected function setValues (EntityInterface $entity, array $values): void { |
|
294 | + protected function setValues(EntityInterface $entity, array $values): void { |
|
295 | 295 | foreach ($values as $name => $value) { |
296 | 296 | settype($value, $this->types[$name]); |
297 | 297 | $this->properties[$name]->setValue($entity, $value); |
@@ -66,8 +66,7 @@ discard block |
||
66 | 66 | $this->class = $class; |
67 | 67 | try { |
68 | 68 | $class = new ReflectionClass($class); |
69 | - } |
|
70 | - catch (ReflectionException $exception) { |
|
69 | + } catch (ReflectionException $exception) { |
|
71 | 70 | throw new LogicException('Unexpected ReflectionException', 0, $exception); |
72 | 71 | } |
73 | 72 | $this->proto = $class->newInstanceWithoutConstructor(); |
@@ -84,8 +83,7 @@ discard block |
||
84 | 83 | if (preg_match('/@var\s+(?<type>[a-z]+)[\s$]/', $doc, $match)) { |
85 | 84 | $types[$name] = $match['type']; |
86 | 85 | } |
87 | - } |
|
88 | - elseif (preg_match('/@eav\s+(?<table>\S+)/', $doc, $match)) { |
|
86 | + } elseif (preg_match('/@eav\s+(?<table>\S+)/', $doc, $match)) { |
|
89 | 87 | $eav[$name] = $match['table']; |
90 | 88 | $this->properties[$name] = $property; |
91 | 89 | } |
@@ -213,8 +211,7 @@ discard block |
||
213 | 211 | public function save (EntityInterface $entity): int { |
214 | 212 | if (!$entity->getId()) { |
215 | 213 | $this->saveInsert($entity); |
216 | - } |
|
217 | - else { |
|
214 | + } else { |
|
218 | 215 | $this->saveUpdate($entity); |
219 | 216 | } |
220 | 217 | $this->saveEav($entity); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param string|Select $table |
80 | 80 | * @param string[] $columns |
81 | 81 | */ |
82 | - public function __construct (DB $db, $table, array $columns) { |
|
82 | + public function __construct(DB $db, $table, array $columns) { |
|
83 | 83 | parent::__construct($db); |
84 | 84 | if ($table instanceof Select) { |
85 | 85 | $table = $table->toSubquery(); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | /** |
96 | 96 | * Gives the clone a new alias. |
97 | 97 | */ |
98 | - public function __clone () { |
|
98 | + public function __clone() { |
|
99 | 99 | $this->alias = uniqid('_') . "__{$this->table}"; |
100 | 100 | } |
101 | 101 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @param array $args |
104 | 104 | * @return Statement |
105 | 105 | */ |
106 | - public function __invoke (array $args = []): Statement { |
|
106 | + public function __invoke(array $args = []): Statement { |
|
107 | 107 | return $this->execute($args); |
108 | 108 | } |
109 | 109 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return string |
114 | 114 | */ |
115 | - public function __toString (): string { |
|
115 | + public function __toString(): string { |
|
116 | 116 | return $this->alias; |
117 | 117 | } |
118 | 118 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * @param array $args Execution arguments. |
123 | 123 | * @return int |
124 | 124 | */ |
125 | - public function count (array $args = []): int { |
|
125 | + public function count(array $args = []): int { |
|
126 | 126 | $clone = clone $this; |
127 | 127 | $clone->columns = ['COUNT(*)']; |
128 | 128 | return (int)$clone->execute($args)->fetchColumn(); |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @param array $args |
135 | 135 | * @return Statement |
136 | 136 | */ |
137 | - public function execute (array $args = []): Statement { |
|
137 | + public function execute(array $args = []): Statement { |
|
138 | 138 | if ($args) { |
139 | 139 | return $this->prepare()->execute($args); |
140 | 140 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param array $args Execution arguments. |
150 | 150 | * @return array |
151 | 151 | */ |
152 | - public function fetchAll (array $args = []): array { |
|
152 | + public function fetchAll(array $args = []): array { |
|
153 | 153 | return $this->fetcher->__invoke($this->execute($args)); |
154 | 154 | } |
155 | 155 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @return ArrayIterator |
162 | 162 | */ |
163 | - public function getIterator () { |
|
163 | + public function getIterator() { |
|
164 | 164 | return new ArrayIterator($this->fetchAll()); |
165 | 165 | } |
166 | 166 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @param string $column |
171 | 171 | * @return $this |
172 | 172 | */ |
173 | - public function group (string $column) { |
|
173 | + public function group(string $column) { |
|
174 | 174 | $this->_group[] = $column; |
175 | 175 | return $this; |
176 | 176 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @param string $condition |
182 | 182 | * @return $this |
183 | 183 | */ |
184 | - public function having (string $condition) { |
|
184 | + public function having(string $condition) { |
|
185 | 185 | $this->_having[] = $condition; |
186 | 186 | return $this; |
187 | 187 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * @param string $type |
195 | 195 | * @return $this |
196 | 196 | */ |
197 | - public function join ($table, string $condition, string $type = 'INNER') { |
|
197 | + public function join($table, string $condition, string $type = 'INNER') { |
|
198 | 198 | if ($table instanceof Select) { |
199 | 199 | $table = $table->toSubquery(); |
200 | 200 | } |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @param int $offset |
210 | 210 | * @return $this |
211 | 211 | */ |
212 | - public function limit (int $limit, int $offset = 0) { |
|
212 | + public function limit(int $limit, int $offset = 0) { |
|
213 | 213 | $this->_limit = $limit; |
214 | 214 | $this->_offset = $offset; |
215 | 215 | return $this; |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @param string $name Name or alias if used. |
222 | 222 | * @return bool |
223 | 223 | */ |
224 | - public function offsetExists ($name): bool { |
|
224 | + public function offsetExists($name): bool { |
|
225 | 225 | return true; |
226 | 226 | } |
227 | 227 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @param string $name Name, or alias if used. |
232 | 232 | * @return Column |
233 | 233 | */ |
234 | - public function offsetGet ($name): Column { |
|
234 | + public function offsetGet($name): Column { |
|
235 | 235 | return new Column($this->db, $name, $this->alias); |
236 | 236 | } |
237 | 237 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @param string $order |
242 | 242 | * @return $this |
243 | 243 | */ |
244 | - public function order (string $order) { |
|
244 | + public function order(string $order) { |
|
245 | 245 | $this->_order = $order; |
246 | 246 | return $this; |
247 | 247 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | /** |
250 | 250 | * @return Statement |
251 | 251 | */ |
252 | - public function prepare (): Statement { |
|
252 | + public function prepare(): Statement { |
|
253 | 253 | return $this->db->prepare($this->toSql()); |
254 | 254 | } |
255 | 255 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | * @param Closure $fetcher |
258 | 258 | * @return $this |
259 | 259 | */ |
260 | - public function setFetcher (Closure $fetcher) { |
|
260 | + public function setFetcher(Closure $fetcher) { |
|
261 | 261 | $this->fetcher = $fetcher; |
262 | 262 | return $this; |
263 | 263 | } |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | /** |
266 | 266 | * @return string |
267 | 267 | */ |
268 | - public function toSql (): string { |
|
268 | + public function toSql(): string { |
|
269 | 269 | $sql = SQL::select($this->table, $this->columns); |
270 | 270 | foreach ($this->_join as $join) { |
271 | 271 | $sql .= " {$join}"; |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * |
284 | 284 | * @return string |
285 | 285 | */ |
286 | - public function toSubquery (): string { |
|
286 | + public function toSubquery(): string { |
|
287 | 287 | return "({$this->toSql()}) AS {$this->alias}"; |
288 | 288 | } |
289 | 289 | |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | * @param string $condition |
294 | 294 | * @return $this |
295 | 295 | */ |
296 | - public function where (string $condition) { |
|
296 | + public function where(string $condition) { |
|
297 | 297 | $this->_where[] = $condition; |
298 | 298 | return $this; |
299 | 299 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param string $name |
30 | 30 | * @param string $qualifier |
31 | 31 | */ |
32 | - public function __construct (DB $db, string $name, string $qualifier = '') { |
|
32 | + public function __construct(DB $db, string $name, string $qualifier = '') { |
|
33 | 33 | parent::__construct($db); |
34 | 34 | $this->name = $name; |
35 | 35 | $this->qualifier = $qualifier; |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @return string |
42 | 42 | */ |
43 | - public function __toString (): string { |
|
43 | + public function __toString(): string { |
|
44 | 44 | if (strlen($this->qualifier)) { |
45 | 45 | return "{$this->qualifier}.{$this->name}"; |
46 | 46 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return ExpressionInterface |
54 | 54 | */ |
55 | - public function avg (): ExpressionInterface { |
|
55 | + public function avg(): ExpressionInterface { |
|
56 | 56 | return SQL::avg($this); |
57 | 57 | } |
58 | 58 | |
@@ -61,21 +61,21 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return ExpressionInterface |
63 | 63 | */ |
64 | - public function count (): ExpressionInterface { |
|
64 | + public function count(): ExpressionInterface { |
|
65 | 65 | return SQL::count($this); |
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @return string |
70 | 70 | */ |
71 | - final public function getName (): string { |
|
71 | + final public function getName(): string { |
|
72 | 72 | return $this->name; |
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
76 | 76 | * @return string |
77 | 77 | */ |
78 | - final public function getQualifier (): string { |
|
78 | + final public function getQualifier(): string { |
|
79 | 79 | return $this->qualifier; |
80 | 80 | } |
81 | 81 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @param null|bool|string|Select $arg |
89 | 89 | * @return string |
90 | 90 | */ |
91 | - public function is ($arg): string { |
|
91 | + public function is($arg): string { |
|
92 | 92 | if ($arg === null or is_bool($arg)) { |
93 | 93 | $arg = ['' => 'NULL', 1 => 'TRUE', 0 => 'FALSE'][$arg]; |
94 | 94 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @param string|array|Select $arg |
106 | 106 | * @return string |
107 | 107 | */ |
108 | - public function isEqual ($arg): string { |
|
108 | + public function isEqual($arg): string { |
|
109 | 109 | return SQL::isEqual($this, $this->db->quote($arg)); |
110 | 110 | } |
111 | 111 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @param string|Select $arg |
116 | 116 | * @return string |
117 | 117 | */ |
118 | - public function isGreater ($arg): string { |
|
118 | + public function isGreater($arg): string { |
|
119 | 119 | return SQL::isGreater($this, $this->db->quote($arg)); |
120 | 120 | } |
121 | 121 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @param string|Select $arg |
126 | 126 | * @return string |
127 | 127 | */ |
128 | - public function isGreaterOrEqual ($arg): string { |
|
128 | + public function isGreaterOrEqual($arg): string { |
|
129 | 129 | return SQL::isGreaterOrEqual($this, $this->db->quote($arg)); |
130 | 130 | } |
131 | 131 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @param string|Select $arg |
136 | 136 | * @return string |
137 | 137 | */ |
138 | - public function isLess ($arg): string { |
|
138 | + public function isLess($arg): string { |
|
139 | 139 | return SQL::isLess($this, $this->db->quote($arg)); |
140 | 140 | } |
141 | 141 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @param string|Select $arg |
146 | 146 | * @return string |
147 | 147 | */ |
148 | - public function isLessOrEqual ($arg): string { |
|
148 | + public function isLessOrEqual($arg): string { |
|
149 | 149 | return SQL::isLessOrEqual($this, $this->db->quote($arg)); |
150 | 150 | } |
151 | 151 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @param string $pattern |
156 | 156 | * @return string |
157 | 157 | */ |
158 | - public function isLike (string $pattern): string { |
|
158 | + public function isLike(string $pattern): string { |
|
159 | 159 | return SQL::isLike($this, $this->db->quote($pattern)); |
160 | 160 | } |
161 | 161 | |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @param null|bool|string|Select $arg |
168 | 168 | * @return string |
169 | 169 | */ |
170 | - public function isNot ($arg): string { |
|
170 | + public function isNot($arg): string { |
|
171 | 171 | return SQL::not($this->is($arg)); |
172 | 172 | } |
173 | 173 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @param string|array|Select $arg |
178 | 178 | * @return string |
179 | 179 | */ |
180 | - public function isNotEqual ($arg): string { |
|
180 | + public function isNotEqual($arg): string { |
|
181 | 181 | return SQL::isNotEqual($this, $this->db->quote($arg)); |
182 | 182 | } |
183 | 183 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @param string $pattern |
188 | 188 | * @return string |
189 | 189 | */ |
190 | - public function isNotLike (string $pattern): string { |
|
190 | + public function isNotLike(string $pattern): string { |
|
191 | 191 | return SQL::isNotLike($this, $this->db->quote($pattern)); |
192 | 192 | } |
193 | 193 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - public function isNotNull (): string { |
|
199 | + public function isNotNull(): string { |
|
200 | 200 | return SQL::isNotNull($this); |
201 | 201 | } |
202 | 202 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * @param string $pattern |
207 | 207 | * @return string |
208 | 208 | */ |
209 | - public function isNotRegExp (string $pattern): string { |
|
209 | + public function isNotRegExp(string $pattern): string { |
|
210 | 210 | return SQL::isNotRegExp($this, $this->db->quote($pattern)); |
211 | 211 | } |
212 | 212 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * @param string $pattern |
217 | 217 | * @return string |
218 | 218 | */ |
219 | - public function isRegExp (string $pattern): string { |
|
219 | + public function isRegExp(string $pattern): string { |
|
220 | 220 | return SQL::isRegExp($this, $this->db->quote($pattern)); |
221 | 221 | } |
222 | 222 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * |
226 | 226 | * @return ExpressionInterface |
227 | 227 | */ |
228 | - public function max (): ExpressionInterface { |
|
228 | + public function max(): ExpressionInterface { |
|
229 | 229 | return SQL::max($this); |
230 | 230 | } |
231 | 231 | |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * |
235 | 235 | * @return ExpressionInterface |
236 | 236 | */ |
237 | - public function min (): ExpressionInterface { |
|
237 | + public function min(): ExpressionInterface { |
|
238 | 238 | return SQL::min($this); |
239 | 239 | } |
240 | 240 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | * @param string $name |
243 | 243 | * @return $this |
244 | 244 | */ |
245 | - public function setName (string $name) { |
|
245 | + public function setName(string $name) { |
|
246 | 246 | $clone = clone $this; |
247 | 247 | $clone->name = $name; |
248 | 248 | return $clone; |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * @param string $qualifier |
253 | 253 | * @return $this |
254 | 254 | */ |
255 | - public function setQualifier (string $qualifier) { |
|
255 | + public function setQualifier(string $qualifier) { |
|
256 | 256 | $clone = clone $this; |
257 | 257 | $clone->qualifier = $qualifier; |
258 | 258 | return $clone; |
@@ -7,6 +7,6 @@ |
||
7 | 7 | */ |
8 | 8 | interface ExpressionInterface { |
9 | 9 | |
10 | - public function __toString (); |
|
10 | + public function __toString(); |
|
11 | 11 | |
12 | 12 | } |
13 | 13 | \ No newline at end of file |
@@ -12,14 +12,14 @@ |
||
12 | 12 | /** |
13 | 13 | * @param string $string |
14 | 14 | */ |
15 | - public function __construct (string $string) { |
|
15 | + public function __construct(string $string) { |
|
16 | 16 | $this->string = $string; |
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @return string |
21 | 21 | */ |
22 | - public function __toString () { |
|
22 | + public function __toString() { |
|
23 | 23 | return $this->string; |
24 | 24 | } |
25 | 25 | } |
26 | 26 | \ No newline at end of file |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @param string[] $conditions |
18 | 18 | * @return string |
19 | 19 | */ |
20 | - public static function all (array $conditions): string { |
|
20 | + public static function all(array $conditions): string { |
|
21 | 21 | if (count($conditions) === 1) { |
22 | 22 | return reset($conditions); |
23 | 23 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param string[] $conditions |
31 | 31 | * @return string |
32 | 32 | */ |
33 | - public static function any (array $conditions): string { |
|
33 | + public static function any(array $conditions): string { |
|
34 | 34 | if (count($conditions) === 1) { |
35 | 35 | return reset($conditions); |
36 | 36 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param string $column |
44 | 44 | * @return ExpressionInterface |
45 | 45 | */ |
46 | - public static function avg (string $column): ExpressionInterface { |
|
46 | + public static function avg(string $column): ExpressionInterface { |
|
47 | 47 | return new Expression("AVG({$column})"); |
48 | 48 | } |
49 | 49 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param string $listOperator |
80 | 80 | * @return string|array |
81 | 81 | */ |
82 | - public static function compare ($a, $operator, $b = null, $subOperator = null, $listOperator = null) { |
|
82 | + public static function compare($a, $operator, $b = null, $subOperator = null, $listOperator = null) { |
|
83 | 83 | if (is_array($a)) { |
84 | 84 | $cmp = []; |
85 | 85 | foreach ($a as $k => $v) { |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @param string $column |
103 | 103 | * @return ExpressionInterface |
104 | 104 | */ |
105 | - public static function count (string $column): ExpressionInterface { |
|
105 | + public static function count(string $column): ExpressionInterface { |
|
106 | 106 | return new Expression("COUNT({$column})"); |
107 | 107 | } |
108 | 108 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @param array $columns |
114 | 114 | * @return string |
115 | 115 | */ |
116 | - public static function group (array $columns): string { |
|
116 | + public static function group(array $columns): string { |
|
117 | 117 | if ($columns) { |
118 | 118 | return ' GROUP BY ' . implode(',', $columns); |
119 | 119 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @param array $conditions |
128 | 128 | * @return string |
129 | 129 | */ |
130 | - public static function having (array $conditions): string { |
|
130 | + public static function having(array $conditions): string { |
|
131 | 131 | if ($conditions) { |
132 | 132 | return ' HAVING ' . static::all($conditions); |
133 | 133 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @param string|array|Select $b |
142 | 142 | * @return string|array |
143 | 143 | */ |
144 | - public static function isEqual ($a, $b = null) { |
|
144 | + public static function isEqual($a, $b = null) { |
|
145 | 145 | return static::compare($a, '=', $b, 'ANY', 'IN'); |
146 | 146 | } |
147 | 147 | |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * @param string|Select $b |
153 | 153 | * @return string|array |
154 | 154 | */ |
155 | - public static function isGreater ($a, $b = null) { |
|
155 | + public static function isGreater($a, $b = null) { |
|
156 | 156 | return static::compare($a, '>', $b, 'ALL'); |
157 | 157 | } |
158 | 158 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @param string|Select $b |
164 | 164 | * @return string|array |
165 | 165 | */ |
166 | - public static function isGreaterOrEqual ($a, $b = null) { |
|
166 | + public static function isGreaterOrEqual($a, $b = null) { |
|
167 | 167 | return static::compare($a, '>=', $b, 'ALL'); |
168 | 168 | } |
169 | 169 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @param string|Select $b |
175 | 175 | * @return string|array |
176 | 176 | */ |
177 | - public static function isLess ($a, $b = null) { |
|
177 | + public static function isLess($a, $b = null) { |
|
178 | 178 | return static::compare($a, '<', $b, 'ALL'); |
179 | 179 | } |
180 | 180 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * @param string|Select $b |
186 | 186 | * @return string|array |
187 | 187 | */ |
188 | - public static function isLessOrEqual ($a, $b = null) { |
|
188 | + public static function isLessOrEqual($a, $b = null) { |
|
189 | 189 | return static::compare($a, '<=', $b, 'ALL'); |
190 | 190 | } |
191 | 191 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * @param string $pattern |
197 | 197 | * @return string|array |
198 | 198 | */ |
199 | - public static function isLike ($x, string $pattern = null) { |
|
199 | + public static function isLike($x, string $pattern = null) { |
|
200 | 200 | return static::compare($x, 'LIKE', $pattern); |
201 | 201 | } |
202 | 202 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * @param null|bool $identity |
208 | 208 | * @return string|array |
209 | 209 | */ |
210 | - public static function isNot ($x, $identity) { |
|
210 | + public static function isNot($x, $identity) { |
|
211 | 211 | return static::compare($x, 'IS NOT', ['' => 'UNKNOWN', 1 => 'TRUE', 0 => 'FALSE'][$identity]); |
212 | 212 | } |
213 | 213 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * @param string|array|Select $b |
219 | 219 | * @return string|array |
220 | 220 | */ |
221 | - public static function isNotEqual ($a, $b = null) { |
|
221 | + public static function isNotEqual($a, $b = null) { |
|
222 | 222 | return static::compare($a, '<>', $b, 'ALL', 'NOT IN'); |
223 | 223 | } |
224 | 224 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @param string $pattern |
230 | 230 | * @return string|array |
231 | 231 | */ |
232 | - public static function isNotLike ($x, string $pattern = null) { |
|
232 | + public static function isNotLike($x, string $pattern = null) { |
|
233 | 233 | return static::compare($x, 'NOT LIKE', $pattern); |
234 | 234 | } |
235 | 235 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @param string|array $x |
240 | 240 | * @return string|array |
241 | 241 | */ |
242 | - public static function isNotNull ($x) { |
|
242 | + public static function isNotNull($x) { |
|
243 | 243 | if (is_array($x)) { |
244 | 244 | return array_map(__METHOD__, $x); |
245 | 245 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @param string $pattern |
254 | 254 | * @return string|array |
255 | 255 | */ |
256 | - public static function isNotRegExp ($x, string $pattern = null) { |
|
256 | + public static function isNotRegExp($x, string $pattern = null) { |
|
257 | 257 | return static::compare($x, 'NOT REGEXP', $pattern); |
258 | 258 | } |
259 | 259 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * @param string $pattern |
265 | 265 | * @return string|array |
266 | 266 | */ |
267 | - public static function isRegExp ($x, string $pattern = null) { |
|
267 | + public static function isRegExp($x, string $pattern = null) { |
|
268 | 268 | return static::compare($x, 'REGEXP', $pattern); |
269 | 269 | } |
270 | 270 | |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * @param int $offset |
277 | 277 | * @return string |
278 | 278 | */ |
279 | - public static function limit (int $limit, int $offset = 0): string { |
|
279 | + public static function limit(int $limit, int $offset = 0): string { |
|
280 | 280 | if ($limit) { |
281 | 281 | $limit = " LIMIT {$limit}"; |
282 | 282 | if ($offset) { |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | * @param int|array|Countable $count |
294 | 294 | * @return string[] |
295 | 295 | */ |
296 | - public static function marks ($count): array { |
|
296 | + public static function marks($count): array { |
|
297 | 297 | if (is_array($count) or $count instanceof Countable) { |
298 | 298 | $count = count($count); |
299 | 299 | } |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | * @param string $column |
307 | 307 | * @return ExpressionInterface |
308 | 308 | */ |
309 | - public static function max (string $column): ExpressionInterface { |
|
309 | + public static function max(string $column): ExpressionInterface { |
|
310 | 310 | return new Expression("MAX({$column}"); |
311 | 311 | } |
312 | 312 | |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @param string $column |
317 | 317 | * @return ExpressionInterface |
318 | 318 | */ |
319 | - public static function min (string $column): ExpressionInterface { |
|
319 | + public static function min(string $column): ExpressionInterface { |
|
320 | 320 | return new Expression("MIN({$column})"); |
321 | 321 | } |
322 | 322 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @param string|array $x |
327 | 327 | * @return string|array |
328 | 328 | */ |
329 | - public static function not ($x) { |
|
329 | + public static function not($x) { |
|
330 | 330 | if (is_array($x)) { |
331 | 331 | return array_map(__METHOD__, $x); |
332 | 332 | } |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | * @param string $order |
341 | 341 | * @return string |
342 | 342 | */ |
343 | - public static function order (string $order): string { |
|
343 | + public static function order(string $order): string { |
|
344 | 344 | if (strlen($order)) { |
345 | 345 | return ' ORDER BY ' . $order; |
346 | 346 | } |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | * @param array $columns String keys are used for aliasing. |
355 | 355 | * @return string |
356 | 356 | */ |
357 | - public static function select (string $table, array $columns): string { |
|
357 | + public static function select(string $table, array $columns): string { |
|
358 | 358 | $names = []; |
359 | 359 | foreach ($columns as $alias => $name) { |
360 | 360 | if (is_string($alias) and $alias !== $name) { |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | * @param string[] $columns |
376 | 376 | * @return string[] `[column => :column]` |
377 | 377 | */ |
378 | - public static function slots (array $columns): array { |
|
378 | + public static function slots(array $columns): array { |
|
379 | 379 | $slots = []; |
380 | 380 | foreach ($columns as $column) { |
381 | 381 | $slots[(string)$column] = ':' . str_replace('.', '__', $column); |
@@ -390,12 +390,12 @@ discard block |
||
390 | 390 | * @param array $conditions |
391 | 391 | * @return string |
392 | 392 | */ |
393 | - public static function where (array $conditions): string { |
|
393 | + public static function where(array $conditions): string { |
|
394 | 394 | if ($conditions) { |
395 | 395 | return ' WHERE ' . static::all($conditions); |
396 | 396 | } |
397 | 397 | return ''; |
398 | 398 | } |
399 | 399 | |
400 | - final private function __construct () { } |
|
400 | + final private function __construct() { } |
|
401 | 401 | } |
402 | 402 | \ No newline at end of file |
@@ -86,11 +86,9 @@ discard block |
||
86 | 86 | $cmp[$k] = static::compare($k, $operator, $v, $subOperator, $listOperator); |
87 | 87 | } |
88 | 88 | return $cmp; |
89 | - } |
|
90 | - elseif (is_array($b)) { |
|
89 | + } elseif (is_array($b)) { |
|
91 | 90 | return "{$a} {$listOperator} (" . implode(',', $b) . ")"; |
92 | - } |
|
93 | - elseif ($b instanceof Select) { |
|
91 | + } elseif ($b instanceof Select) { |
|
94 | 92 | return "{$a} {$operator} {$subOperator} ({$b->toSql()})"; |
95 | 93 | } |
96 | 94 | return "{$a} {$operator} {$b}"; |
@@ -359,8 +357,7 @@ discard block |
||
359 | 357 | foreach ($columns as $alias => $name) { |
360 | 358 | if (is_string($alias) and $alias !== $name) { |
361 | 359 | $names[] = $name . ' AS ' . $alias; |
362 | - } |
|
363 | - else { |
|
360 | + } else { |
|
364 | 361 | $names[] = $name; |
365 | 362 | } |
366 | 363 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @param string $passwd |
48 | 48 | * @param array $options |
49 | 49 | */ |
50 | - public function __construct ($dsn, $username = null, $passwd = null, $options = null) { |
|
50 | + public function __construct($dsn, $username = null, $passwd = null, $options = null) { |
|
51 | 51 | parent::__construct(...func_get_args()); |
52 | 52 | $this->setAttribute(self::ATTR_DEFAULT_FETCH_MODE, self::FETCH_ASSOC); |
53 | 53 | $this->setAttribute(self::ATTR_EMULATE_PREPARES, false); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param string $sql |
64 | 64 | * @return int |
65 | 65 | */ |
66 | - public function exec ($sql): int { |
|
66 | + public function exec($sql): int { |
|
67 | 67 | $this->logger->__invoke($sql); |
68 | 68 | return parent::exec($sql); |
69 | 69 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return string |
75 | 75 | */ |
76 | - final public function getDriver (): string { |
|
76 | + final public function getDriver(): string { |
|
77 | 77 | return $this->getAttribute(self::ATTR_DRIVER_NAME); |
78 | 78 | } |
79 | 79 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @param string $interface |
84 | 84 | * @return Junction |
85 | 85 | */ |
86 | - public function getJunction ($interface): Junction { |
|
86 | + public function getJunction($interface): Junction { |
|
87 | 87 | if (!isset($this->junctions[$interface])) { |
88 | 88 | $this->junctions[$interface] = new Junction($this, $interface); |
89 | 89 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | /** |
94 | 94 | * @return Closure |
95 | 95 | */ |
96 | - public function getLogger (): Closure { |
|
96 | + public function getLogger(): Closure { |
|
97 | 97 | return $this->logger; |
98 | 98 | } |
99 | 99 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @param string|EntityInterface $class |
104 | 104 | * @return Record |
105 | 105 | */ |
106 | - public function getRecord ($class): Record { |
|
106 | + public function getRecord($class): Record { |
|
107 | 107 | if (is_object($class)) { |
108 | 108 | $class = get_class($class); |
109 | 109 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @param string|array|Select|Closure $b |
136 | 136 | * @return string|string[] Same type as `$a`, keys are not preserved. |
137 | 137 | */ |
138 | - public function match ($a, $b = null) { |
|
138 | + public function match($a, $b = null) { |
|
139 | 139 | if (is_array($a)) { |
140 | 140 | return array_map([$this, __FUNCTION__], array_keys($a), $a); |
141 | 141 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * @param string $access Class or interface name. |
153 | 153 | * @return bool |
154 | 154 | */ |
155 | - public function offsetExists ($access): bool { |
|
155 | + public function offsetExists($access): bool { |
|
156 | 156 | return (bool)$this->offsetGet($access); |
157 | 157 | } |
158 | 158 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @param string $access Class or interface name. |
161 | 161 | * @return Record|Junction|null |
162 | 162 | */ |
163 | - public function offsetGet ($access) { |
|
163 | + public function offsetGet($access) { |
|
164 | 164 | if (class_exists($access)) { |
165 | 165 | return $this->getRecord($access); |
166 | 166 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @param void $value |
178 | 178 | * @throws Exception |
179 | 179 | */ |
180 | - final public function offsetSet ($access, $value): void { |
|
180 | + final public function offsetSet($access, $value): void { |
|
181 | 181 | throw new Exception('The schema is immutable.'); |
182 | 182 | } |
183 | 183 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @param void $access |
188 | 188 | * @throws Exception |
189 | 189 | */ |
190 | - final public function offsetUnset ($access): void { |
|
190 | + final public function offsetUnset($access): void { |
|
191 | 191 | $this->offsetSet($access, null); |
192 | 192 | } |
193 | 193 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @param array $options |
199 | 199 | * @return Statement |
200 | 200 | */ |
201 | - public function prepare ($sql, $options = null): Statement { |
|
201 | + public function prepare($sql, $options = null): Statement { |
|
202 | 202 | $this->logger->__invoke($sql); |
203 | 203 | /** @var Statement $statement */ |
204 | 204 | $statement = parent::prepare(...func_get_args()); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @param array $ctorargs |
215 | 215 | * @return Statement |
216 | 216 | */ |
217 | - public function query ($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []): Statement { |
|
217 | + public function query($sql, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, $arg3 = null, array $ctorargs = []): Statement { |
|
218 | 218 | $this->logger->__invoke($sql); |
219 | 219 | /** @var Statement $statement */ |
220 | 220 | $statement = parent::query(...func_get_args()); |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * @param int $type Ignored. |
235 | 235 | * @return mixed |
236 | 236 | */ |
237 | - public function quote ($value, $type = null) { |
|
237 | + public function quote($value, $type = null) { |
|
238 | 238 | if ($value instanceof ExpressionInterface) { |
239 | 239 | return $value; |
240 | 240 | } |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * @param EntityInterface $entity |
257 | 257 | * @return int ID |
258 | 258 | */ |
259 | - public function save (EntityInterface $entity): int { |
|
259 | + public function save(EntityInterface $entity): int { |
|
260 | 260 | return $this->getRecord($entity)->save($entity); |
261 | 261 | } |
262 | 262 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * @param Closure $logger |
265 | 265 | * @return $this |
266 | 266 | */ |
267 | - public function setLogger (Closure $logger) { |
|
267 | + public function setLogger(Closure $logger) { |
|
268 | 268 | $this->logger = $logger; |
269 | 269 | return $this; |
270 | 270 | } |