@@ -57,8 +57,7 @@ discard block |
||
57 | 57 | * Class EntityManager |
58 | 58 | * @package Platine\Orm |
59 | 59 | */ |
60 | -class EntityManager |
|
61 | -{ |
|
60 | +class EntityManager { |
|
62 | 61 | |
63 | 62 | /** |
64 | 63 | * The connection |
@@ -82,8 +81,7 @@ discard block |
||
82 | 81 | * Create new instance |
83 | 82 | * @param Connection $connection |
84 | 83 | */ |
85 | - public function __construct(Connection $connection) |
|
86 | - { |
|
84 | + public function __construct(Connection $connection) { |
|
87 | 85 | $this->connection = $connection; |
88 | 86 | $this->dateFormat = $connection->getDriver()->getDateFormat(); |
89 | 87 | } |
@@ -113,7 +113,7 @@ |
||
113 | 113 | $this->immediate = false; |
114 | 114 | |
115 | 115 | return $this->manager->query($this->entityClass) |
116 | - ->with($with, $immediate); |
|
116 | + ->with($with, $immediate); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | } |
229 | 229 | |
230 | 230 | $connection = $this->manager->getConnection(); |
231 | - $id = $connection->transaction(function (Connection $connection) use ($data, $mapper) { |
|
231 | + $id = $connection->transaction(function(Connection $connection) use ($data, $mapper) { |
|
232 | 232 | $columns = $data->getRawColumns(); |
233 | 233 | $pkGenerator = $mapper->getPrimaryKeyGenerator(); |
234 | 234 | if ($pkGenerator !== null) { |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | $modified = $data->getModifiedColumns(); |
299 | 299 | if (!empty($modified)) { |
300 | 300 | $connection = $this->manager->getConnection(); |
301 | - $result = $connection->transaction(function (Connection $connection) use ($data, $mapper, $modified) { |
|
301 | + $result = $connection->transaction(function(Connection $connection) use ($data, $mapper, $modified) { |
|
302 | 302 | $columns = array_intersect_key($data->getRawColumns(), array_flip($modified)); |
303 | 303 | |
304 | 304 | $updatedAt = null; |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | } |
336 | 336 | |
337 | 337 | $connection = $this->manager->getConnection(); |
338 | - return $connection->transaction(function (Connection $connection) use ($data) { |
|
338 | + return $connection->transaction(function(Connection $connection) use ($data) { |
|
339 | 339 | $data->executePendingLinkage(); |
340 | 340 | |
341 | 341 | return true; |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | $eventsHandlers = $mapper->getEventHandlers(); |
353 | 353 | $connection = $this->manager->getConnection(); |
354 | 354 | |
355 | - $result = $connection->transaction(function () use ($data, $mapper, $force) { |
|
355 | + $result = $connection->transaction(function() use ($data, $mapper, $force) { |
|
356 | 356 | if ($data->isDeleted()) { |
357 | 357 | throw new EntityStateException('The record was deleted'); |
358 | 358 | } |
@@ -62,8 +62,7 @@ discard block |
||
62 | 62 | * Class Repository |
63 | 63 | * @package Platine\Orm |
64 | 64 | */ |
65 | -class Repository implements RepositoryInterface |
|
66 | -{ |
|
65 | +class Repository implements RepositoryInterface { |
|
67 | 66 | |
68 | 67 | /** |
69 | 68 | * The entity class |
@@ -94,8 +93,7 @@ discard block |
||
94 | 93 | * @param EntityManager $manager |
95 | 94 | * @param class-string $entityClass |
96 | 95 | */ |
97 | - public function __construct(EntityManager $manager, string $entityClass) |
|
98 | - { |
|
96 | + public function __construct(EntityManager $manager, string $entityClass) { |
|
99 | 97 | $this->manager = $manager; |
100 | 98 | $this->entityClass = $entityClass; |
101 | 99 | } |
@@ -213,8 +211,7 @@ discard block |
||
213 | 211 | /** |
214 | 212 | * {@inheritedoc} |
215 | 213 | */ |
216 | - public function insert(Entity $entity) |
|
217 | - { |
|
214 | + public function insert(Entity $entity) { |
|
218 | 215 | $data = Proxy::instance()->getEntityDataMapper($entity); |
219 | 216 | $mapper = $data->getEntityMapper(); |
220 | 217 | $eventsHandlers = $mapper->getEventHandlers(); |
@@ -57,8 +57,7 @@ discard block |
||
57 | 57 | * Class Query |
58 | 58 | * @package Platine\Orm\Query |
59 | 59 | */ |
60 | -class Query extends BaseStatement |
|
61 | -{ |
|
60 | +class Query extends BaseStatement { |
|
62 | 61 | |
63 | 62 | /** |
64 | 63 | * |
@@ -95,8 +94,7 @@ discard block |
||
95 | 94 | * |
96 | 95 | * @param QueryStatement|null $queryStatement |
97 | 96 | */ |
98 | - public function __construct(QueryStatement $queryStatement = null) |
|
99 | - { |
|
97 | + public function __construct(QueryStatement $queryStatement = null) { |
|
100 | 98 | parent::__construct($queryStatement); |
101 | 99 | $this->havingStatement = new HavingStatement($this->queryStatement); |
102 | 100 | } |
@@ -104,8 +102,7 @@ discard block |
||
104 | 102 | /** |
105 | 103 | * Clone the object |
106 | 104 | */ |
107 | - public function __clone() |
|
108 | - { |
|
105 | + public function __clone() { |
|
109 | 106 | parent::__clone(); |
110 | 107 | $this->havingStatement = new HavingStatement($this->queryStatement); |
111 | 108 | } |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | public function get(array $columns = []): ?Entity |
140 | 140 | { |
141 | 141 | $result = $this->query($columns) |
142 | - ->fetchAssoc() |
|
143 | - ->get(); |
|
142 | + ->fetchAssoc() |
|
143 | + ->get(); |
|
144 | 144 | |
145 | 145 | if ($result === false) { |
146 | 146 | return null; |
@@ -289,11 +289,11 @@ discard block |
||
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
292 | - * Find entities record using primary key values |
|
293 | - * @param mixed ...$ids |
|
294 | - * |
|
295 | - * @return array<int, Entity> |
|
296 | - */ |
|
292 | + * Find entities record using primary key values |
|
293 | + * @param mixed ...$ids |
|
294 | + * |
|
295 | + * @return array<int, Entity> |
|
296 | + */ |
|
297 | 297 | public function findAll(...$ids): array |
298 | 298 | { |
299 | 299 | if (is_array($ids[0])) { |
@@ -525,6 +525,6 @@ discard block |
||
525 | 525 | protected function transaction(Closure $callback) |
526 | 526 | { |
527 | 527 | return $this->manager->getConnection() |
528 | - ->transaction($callback); |
|
528 | + ->transaction($callback); |
|
529 | 529 | } |
530 | 530 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | */ |
201 | 201 | public function delete(bool $force = false, array $tables = []): int |
202 | 202 | { |
203 | - return (int) $this->transaction(function (Connection $connection) use ($tables, $force) { |
|
203 | + return (int) $this->transaction(function(Connection $connection) use ($tables, $force) { |
|
204 | 204 | if (!$force && $this->mapper->hasSoftDelete()) { |
205 | 205 | return (new Update($connection, $this->mapper->getTable(), $this->queryStatement)) |
206 | 206 | ->set([ |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | */ |
219 | 219 | public function update(array $columns = []): int |
220 | 220 | { |
221 | - return (int) $this->transaction(function (Connection $connection) use ($columns) { |
|
221 | + return (int) $this->transaction(function(Connection $connection) use ($columns) { |
|
222 | 222 | if ($this->mapper->hasTimestamp()) { |
223 | 223 | list(, $updatedAtColumn) = $this->mapper->getTimestampColumns(); |
224 | 224 | $columns[$updatedAtColumn] = date($this->manager->getDateFormat()); |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public function increment($column, $value = 1): int |
238 | 238 | { |
239 | - return (int) $this->transaction(function (Connection $connection) use ($column, $value) { |
|
239 | + return (int) $this->transaction(function(Connection $connection) use ($column, $value) { |
|
240 | 240 | if ($this->mapper->hasTimestamp()) { |
241 | 241 | list(, $updatedAtColumn) = $this->mapper->getTimestampColumns(); |
242 | 242 | $this->queryStatement->addUpdateColumns([ |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | */ |
257 | 257 | public function decrement($column, $value = 1): int |
258 | 258 | { |
259 | - return (int) $this->transaction(function (Connection $connection) use ($column, $value) { |
|
259 | + return (int) $this->transaction(function(Connection $connection) use ($column, $value) { |
|
260 | 260 | if ($this->mapper->hasTimestamp()) { |
261 | 261 | list(, $updatedAtColumn) = $this->mapper->getTimestampColumns(); |
262 | 262 | $this->queryStatement->addUpdateColumns([ |
@@ -64,8 +64,7 @@ discard block |
||
64 | 64 | * Class EntityQuery |
65 | 65 | * @package Platine\Orm\Query |
66 | 66 | */ |
67 | -class EntityQuery extends Query |
|
68 | -{ |
|
67 | +class EntityQuery extends Query { |
|
69 | 68 | |
70 | 69 | /** |
71 | 70 | * |
@@ -322,8 +321,7 @@ discard block |
||
322 | 321 | * @param string|Expression|Closure $column |
323 | 322 | * @return mixed |
324 | 323 | */ |
325 | - public function column($column) |
|
326 | - { |
|
324 | + public function column($column) { |
|
327 | 325 | (new ColumnExpression($this->queryStatement))->column($column); |
328 | 326 | |
329 | 327 | return $this->executeAggregate(); |
@@ -335,8 +333,7 @@ discard block |
||
335 | 333 | * @param bool $distinct |
336 | 334 | * @return mixed |
337 | 335 | */ |
338 | - public function count($column = '*', bool $distinct = true) |
|
339 | - { |
|
336 | + public function count($column = '*', bool $distinct = true) { |
|
340 | 337 | (new ColumnExpression($this->queryStatement))->count($column, null, $distinct); |
341 | 338 | |
342 | 339 | return $this->executeAggregate(); |
@@ -348,8 +345,7 @@ discard block |
||
348 | 345 | * @param bool $distinct |
349 | 346 | * @return mixed |
350 | 347 | */ |
351 | - public function avg($column, bool $distinct = true) |
|
352 | - { |
|
348 | + public function avg($column, bool $distinct = true) { |
|
353 | 349 | (new ColumnExpression($this->queryStatement))->avg($column, null, $distinct); |
354 | 350 | |
355 | 351 | return $this->executeAggregate(); |
@@ -361,8 +357,7 @@ discard block |
||
361 | 357 | * @param bool $distinct |
362 | 358 | * @return mixed |
363 | 359 | */ |
364 | - public function sum($column, bool $distinct = true) |
|
365 | - { |
|
360 | + public function sum($column, bool $distinct = true) { |
|
366 | 361 | (new ColumnExpression($this->queryStatement))->sum($column, null, $distinct); |
367 | 362 | |
368 | 363 | return $this->executeAggregate(); |
@@ -374,8 +369,7 @@ discard block |
||
374 | 369 | * @param bool $distinct |
375 | 370 | * @return mixed |
376 | 371 | */ |
377 | - public function min($column, bool $distinct = true) |
|
378 | - { |
|
372 | + public function min($column, bool $distinct = true) { |
|
379 | 373 | (new ColumnExpression($this->queryStatement))->min($column, null, $distinct); |
380 | 374 | |
381 | 375 | return $this->executeAggregate(); |
@@ -387,8 +381,7 @@ discard block |
||
387 | 381 | * @param bool $distinct |
388 | 382 | * @return mixed |
389 | 383 | */ |
390 | - public function max($column, bool $distinct = true) |
|
391 | - { |
|
384 | + public function max($column, bool $distinct = true) { |
|
392 | 385 | (new ColumnExpression($this->queryStatement))->max($column, null, $distinct); |
393 | 386 | |
394 | 387 | return $this->executeAggregate(); |
@@ -397,8 +390,7 @@ discard block |
||
397 | 390 | /** |
398 | 391 | * Clone of object |
399 | 392 | */ |
400 | - public function __clone() |
|
401 | - { |
|
393 | + public function __clone() { |
|
402 | 394 | parent::__clone(); |
403 | 395 | $this->havingStatement = new HavingStatement($this->queryStatement); |
404 | 396 | } |
@@ -486,8 +478,7 @@ discard block |
||
486 | 478 | * Execute the aggregate |
487 | 479 | * @return mixed |
488 | 480 | */ |
489 | - protected function executeAggregate() |
|
490 | - { |
|
481 | + protected function executeAggregate() { |
|
491 | 482 | $this->queryStatement->addTables([$this->mapper->getTable()]); |
492 | 483 | |
493 | 484 | if ($this->mapper->hasSoftDelete()) { |
@@ -522,8 +513,7 @@ discard block |
||
522 | 513 | * |
523 | 514 | * @return mixed |
524 | 515 | */ |
525 | - protected function transaction(Closure $callback) |
|
526 | - { |
|
516 | + protected function transaction(Closure $callback) { |
|
527 | 517 | return $this->manager->getConnection() |
528 | 518 | ->transaction($callback); |
529 | 519 | } |
@@ -56,8 +56,7 @@ discard block |
||
56 | 56 | * Class Entity |
57 | 57 | * @package Platine\Orm |
58 | 58 | */ |
59 | -abstract class Entity |
|
60 | -{ |
|
59 | +abstract class Entity { |
|
61 | 60 | |
62 | 61 | /** |
63 | 62 | * The instance of data mapper |
@@ -103,8 +102,7 @@ discard block |
||
103 | 102 | * @param string $name |
104 | 103 | * @return mixed |
105 | 104 | */ |
106 | - public function __get(string $name) |
|
107 | - { |
|
105 | + public function __get(string $name) { |
|
108 | 106 | if ($this->mapper()->hasRelation($name)) { |
109 | 107 | return $this->mapper()->getRelated($name); |
110 | 108 | } |
@@ -125,8 +123,7 @@ discard block |
||
125 | 123 | * @param mixed $value |
126 | 124 | * @return void |
127 | 125 | */ |
128 | - public function __set(string $name, $value) |
|
129 | - { |
|
126 | + public function __set(string $name, $value) { |
|
130 | 127 | if ($this->mapper()->hasRelation($name)) { |
131 | 128 | $this->mapper()->setRelated($name, $value); |
132 | 129 | } else { |
@@ -139,8 +136,7 @@ discard block |
||
139 | 136 | * @param string $name |
140 | 137 | * @return bool |
141 | 138 | */ |
142 | - public function __isset(string $name) |
|
143 | - { |
|
139 | + public function __isset(string $name) { |
|
144 | 140 | return $this->mapper()->hasRelation($name) |
145 | 141 | || $this->mapper()->hasColumn($name); |
146 | 142 | } |
@@ -38,6 +38,5 @@ |
||
38 | 38 | * Class EntityStateException |
39 | 39 | * @package Platine\Orm\Exception |
40 | 40 | */ |
41 | -class EntityStateException extends RuntimeException |
|
42 | -{ |
|
41 | +class EntityStateException extends RuntimeException { |
|
43 | 42 | } |
@@ -38,6 +38,5 @@ |
||
38 | 38 | * Class RelationNotFoundException |
39 | 39 | * @package Platine\Orm\Exception |
40 | 40 | */ |
41 | -class RelationNotFoundException extends RuntimeException |
|
42 | -{ |
|
41 | +class RelationNotFoundException extends RuntimeException { |
|
43 | 42 | } |
@@ -38,6 +38,5 @@ |
||
38 | 38 | * Class PropertyNotFoundException |
39 | 39 | * @package Platine\Orm\Exception |
40 | 40 | */ |
41 | -class PropertyNotFoundException extends RuntimeException |
|
42 | -{ |
|
41 | +class PropertyNotFoundException extends RuntimeException { |
|
43 | 42 | } |
@@ -52,8 +52,7 @@ |
||
52 | 52 | * Class DataMapperInterface |
53 | 53 | * @package Platine\Orm\Mapper |
54 | 54 | */ |
55 | -interface DataMapperInterface |
|
56 | -{ |
|
55 | +interface DataMapperInterface { |
|
57 | 56 | |
58 | 57 | /** |
59 | 58 | * Whether the record is new |