@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | public function register($name, callable $func) |
11 | 11 | { |
12 | - if (! $name) { |
|
12 | + if (!$name) { |
|
13 | 13 | return; // ignore |
14 | 14 | } |
15 | 15 | $this->casts[$name] = $func; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | public function bool($value) |
38 | 38 | { |
39 | - return ! ! $value; |
|
39 | + return !!$value; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | public function int($value) |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | } |
99 | 99 | |
100 | 100 | $value = $this->castAttribute($attribute, $value); |
101 | - if (! isset($this->attributes[$attribute]) || $value != $this->attributes[$attribute]) { |
|
101 | + if (!isset($this->attributes[$attribute]) || $value != $this->attributes[$attribute]) { |
|
102 | 102 | $this->changed[$attribute] = true; |
103 | 103 | $this->state = StateEnum::CHANGED; |
104 | 104 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | public function get($attribute) |
111 | 111 | { |
112 | - if (! $attribute) { |
|
112 | + if (!$attribute) { |
|
113 | 113 | return null; |
114 | 114 | } |
115 | 115 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | |
121 | 121 | public function getPersistenceState() |
122 | 122 | { |
123 | - if (! empty($this->changed)) { |
|
123 | + if (!empty($this->changed)) { |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | return $this->state; |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | $changes = $this->changed; |
151 | 151 | foreach ($this->attributes as $name => $value) { |
152 | 152 | if (is_object($value) && method_exists($value, 'getChanges')) { |
153 | - if (! empty($value->getChanges())) { |
|
153 | + if (!empty($value->getChanges())) { |
|
154 | 154 | $changes[$name] = true; |
155 | 155 | } |
156 | 156 | } |
@@ -56,7 +56,7 @@ |
||
56 | 56 | ->newQuery(); |
57 | 57 | |
58 | 58 | $query = $this->joinWithThroughTable($query) |
59 | - ->where($this->options[RelationConfig::THROUGH_NATIVE_COLUMN], $nativePks); |
|
59 | + ->where($this->options[RelationConfig::THROUGH_NATIVE_COLUMN], $nativePks); |
|
60 | 60 | |
61 | 61 | if ($this->getOption(RelationConfig::QUERY_CALLBACK) && |
62 | 62 | is_callable($this->getOption(RelationConfig::QUERY_CALLBACK))) { |
@@ -19,28 +19,28 @@ discard block |
||
19 | 19 | $this->setOptionIfMissing(RelationConfig::THROUGH_COLUMNS_PREFIX, 'pivot_'); |
20 | 20 | |
21 | 21 | $foreignKey = $this->foreignMapper->getPrimaryKey(); |
22 | - if (! isset($this->options[RelationConfig::FOREIGN_KEY])) { |
|
22 | + if (!isset($this->options[RelationConfig::FOREIGN_KEY])) { |
|
23 | 23 | $this->options[RelationConfig::FOREIGN_KEY] = $foreignKey; |
24 | 24 | } |
25 | 25 | |
26 | 26 | $nativeKey = $this->foreignMapper->getPrimaryKey(); |
27 | - if (! isset($this->options[RelationConfig::NATIVE_KEY])) { |
|
27 | + if (!isset($this->options[RelationConfig::NATIVE_KEY])) { |
|
28 | 28 | $this->options[RelationConfig::NATIVE_KEY] = $nativeKey; |
29 | 29 | } |
30 | 30 | |
31 | - if (! isset($this->options[RelationConfig::THROUGH_TABLE])) { |
|
31 | + if (!isset($this->options[RelationConfig::THROUGH_TABLE])) { |
|
32 | 32 | $tables = [$this->foreignMapper->getTable(), $this->nativeMapper->getTable()]; |
33 | 33 | sort($tables); |
34 | 34 | $this->options[RelationConfig::THROUGH_TABLE] = implode('_', $tables); |
35 | 35 | } |
36 | 36 | |
37 | - if (! isset($this->options[RelationConfig::THROUGH_NATIVE_COLUMN])) { |
|
37 | + if (!isset($this->options[RelationConfig::THROUGH_NATIVE_COLUMN])) { |
|
38 | 38 | $prefix = Inflector::singularize($this->nativeMapper->getTableAlias(true)); |
39 | 39 | |
40 | 40 | $this->options[RelationConfig::THROUGH_NATIVE_COLUMN] = $this->getKeyColumn($prefix, $nativeKey); |
41 | 41 | } |
42 | 42 | |
43 | - if (! isset($this->options[RelationConfig::THROUGH_FOREIGN_COLUMN])) { |
|
43 | + if (!isset($this->options[RelationConfig::THROUGH_FOREIGN_COLUMN])) { |
|
44 | 44 | $prefix = Inflector::singularize($this->foreignMapper->getTableAlias(true)); |
45 | 45 | |
46 | 46 | $this->options[RelationConfig::THROUGH_FOREIGN_COLUMN] = $this->getKeyColumn($prefix, $foreignKey); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | $throughAlias = $this->getOption(RelationConfig::THROUGH_TABLE_ALIAS); |
101 | 101 | $throughName = $throughAlias ?? $through; |
102 | 102 | |
103 | - if (! empty($throughColumns)) { |
|
103 | + if (!empty($throughColumns)) { |
|
104 | 104 | $prefix = $this->getOption(RelationConfig::THROUGH_COLUMNS_PREFIX); |
105 | 105 | foreach ($throughColumns as $col) { |
106 | 106 | $query->columns("{$throughName}.{$col} AS {$prefix}{$col}"); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $remainingRelations = $this->getRemainingRelations($action->getOption('relations')); |
187 | 187 | |
188 | 188 | // no cascade delete? treat as save so we can process the changes |
189 | - if (! $this->isCascade()) { |
|
189 | + if (!$this->isCascade()) { |
|
190 | 190 | $this->addActionOnSave($action); |
191 | 191 | } else { |
192 | 192 | // retrieve them again from the DB since the related collection might not have everything |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | |
209 | 209 | /** @var Collection $foreignEntities */ |
210 | 210 | $foreignEntities = $this->nativeMapper->getEntityAttribute($action->getEntity(), $this->name); |
211 | - if (! $foreignEntities) { |
|
211 | + if (!$foreignEntities) { |
|
212 | 212 | return; |
213 | 213 | } |
214 | 214 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | |
217 | 217 | // save the entities still in the collection |
218 | 218 | foreach ($foreignEntities as $foreignEntity) { |
219 | - if (! empty($foreignEntity->getChanges())) { |
|
219 | + if (!empty($foreignEntity->getChanges())) { |
|
220 | 220 | $saveAction = $this->foreignMapper |
221 | 221 | ->newSaveAction($foreignEntity, [ |
222 | 222 | 'relations' => $remainingRelations |
@@ -14,11 +14,11 @@ discard block |
||
14 | 14 | parent::applyDefaults(); |
15 | 15 | |
16 | 16 | $foreignKey = $this->foreignMapper->getPrimaryKey(); |
17 | - if (! isset($this->options[RelationConfig::FOREIGN_KEY])) { |
|
17 | + if (!isset($this->options[RelationConfig::FOREIGN_KEY])) { |
|
18 | 18 | $this->options[RelationConfig::FOREIGN_KEY] = $foreignKey; |
19 | 19 | } |
20 | 20 | |
21 | - if (! isset($this->options[RelationConfig::NATIVE_KEY])) { |
|
21 | + if (!isset($this->options[RelationConfig::NATIVE_KEY])) { |
|
22 | 22 | $nativeKey = $this->getKeyColumn($this->name, $foreignKey); |
23 | 23 | $this->options[RelationConfig::NATIVE_KEY] = $nativeKey; |
24 | 24 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | protected function addActionOnDelete(BaseAction $action) |
91 | 91 | { |
92 | 92 | // no cascade delete? treat it as a save |
93 | - if (! $this->isCascade()) { |
|
93 | + if (!$this->isCascade()) { |
|
94 | 94 | $this->addActionOnSave($action); |
95 | 95 | } else { |
96 | 96 | $nativeEntity = $action->getEntity(); |
@@ -14,11 +14,11 @@ discard block |
||
14 | 14 | protected function applyDefaults(): void |
15 | 15 | { |
16 | 16 | $nativeKey = $this->nativeMapper->getPrimaryKey(); |
17 | - if (! isset($this->options[RelationConfig::NATIVE_KEY])) { |
|
17 | + if (!isset($this->options[RelationConfig::NATIVE_KEY])) { |
|
18 | 18 | $this->options[RelationConfig::NATIVE_KEY] = $nativeKey; |
19 | 19 | } |
20 | 20 | |
21 | - if (! isset($this->options[RelationConfig::FOREIGN_KEY])) { |
|
21 | + if (!isset($this->options[RelationConfig::FOREIGN_KEY])) { |
|
22 | 22 | $prefix = Inflector::singularize($this->nativeMapper->getTable()); |
23 | 23 | $this->options[RelationConfig::FOREIGN_KEY] = $this->getKeyColumn($prefix, $nativeKey); |
24 | 24 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | public function attachEntities(EntityInterface $nativeEntity, EntityInterface $foreignEntity) |
70 | 70 | { |
71 | 71 | foreach ($this->keyPairs as $nativeCol => $foreignCol) { |
72 | - $nativeKeyValue = $this->nativeMapper->getEntityAttribute($nativeEntity, $nativeCol); |
|
72 | + $nativeKeyValue = $this->nativeMapper->getEntityAttribute($nativeEntity, $nativeCol); |
|
73 | 73 | $this->foreignMapper->setEntityAttribute($foreignEntity, $foreignCol, $nativeKeyValue); |
74 | 74 | } |
75 | 75 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $remainingRelations = $this->getRemainingRelations($action->getOption('relations')); |
92 | 92 | |
93 | 93 | // no cascade delete? treat as save so we can process the changes |
94 | - if (! $this->isCascade()) { |
|
94 | + if (!$this->isCascade()) { |
|
95 | 95 | $this->addActionOnSave($action); |
96 | 96 | } else { |
97 | 97 | // retrieve them again from the DB since the related collection might not have everything |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | |
124 | 124 | // save the entities still in the collection |
125 | 125 | foreach ($foreignEntities as $foreignEntity) { |
126 | - if (! empty($foreignEntity->getChanges())) { |
|
126 | + if (!empty($foreignEntity->getChanges())) { |
|
127 | 127 | $saveAction = $this->foreignMapper |
128 | 128 | ->newSaveAction($foreignEntity, ['relations' => $remainingRelations]); |
129 | 129 | $saveAction->addColumns($this->getExtraColumnsForAction()); |
@@ -57,7 +57,7 @@ |
||
57 | 57 | |
58 | 58 | public function revert() |
59 | 59 | { |
60 | - if (! $this->hasRun) { |
|
60 | + if (!$this->hasRun) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | 63 | $this->entity->setPersistenceState($this->entityState); |
@@ -51,10 +51,10 @@ |
||
51 | 51 | $conn = $this->relation->getNativeMapper()->getWriteConnection(); |
52 | 52 | $throughTable = (string)$this->relation->getOption(RelationConfig::THROUGH_TABLE); |
53 | 53 | |
54 | - $throughNativeColumns = (array) $this->relation->getOption(RelationConfig::THROUGH_NATIVE_COLUMN); |
|
55 | - $throughForeignColumns = (array) $this->relation->getOption(RelationConfig::THROUGH_FOREIGN_COLUMN); |
|
56 | - $nativeKey = (array) $this->nativeEntity->getPk(); |
|
57 | - $foreignKey = (array) $this->foreignEntity->getPk(); |
|
54 | + $throughNativeColumns = (array)$this->relation->getOption(RelationConfig::THROUGH_NATIVE_COLUMN); |
|
55 | + $throughForeignColumns = (array)$this->relation->getOption(RelationConfig::THROUGH_FOREIGN_COLUMN); |
|
56 | + $nativeKey = (array)$this->nativeEntity->getPk(); |
|
57 | + $foreignKey = (array)$this->foreignEntity->getPk(); |
|
58 | 58 | |
59 | 59 | $delete = new \Sirius\Sql\Delete($conn); |
60 | 60 | $delete->from($throughTable); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | public function __construct(ConnectionLocator $connectionLocator, CastingManager $castingManager = null) |
30 | 30 | { |
31 | 31 | $this->connectionLocator = $connectionLocator; |
32 | - if (! $castingManager) { |
|
32 | + if (!$castingManager) { |
|
33 | 33 | $castingManager = new CastingManager(); |
34 | 34 | } |
35 | 35 | $this->castingManager = $castingManager; |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | unset($this->lazyMappers[$mapperName]); |
64 | 64 | } |
65 | 65 | |
66 | - if (! isset($this->mappers[$mapperName]) || ! $this->mappers[$mapperName]) { |
|
66 | + if (!isset($this->mappers[$mapperName]) || !$this->mappers[$mapperName]) { |
|
67 | 67 | throw new InvalidArgumentException(sprintf('Mapper named %s is not registered', $mapperName)); |
68 | 68 | } |
69 | 69 | |
@@ -94,14 +94,14 @@ discard block |
||
94 | 94 | { |
95 | 95 | $foreignMapper = $options[RelationConfig::FOREIGN_MAPPER]; |
96 | 96 | if ($this->has($foreignMapper)) { |
97 | - if (! $foreignMapper instanceof Mapper) { |
|
97 | + if (!$foreignMapper instanceof Mapper) { |
|
98 | 98 | $foreignMapper = $this->get($foreignMapper); |
99 | 99 | } |
100 | 100 | } |
101 | 101 | $type = $options[RelationConfig::TYPE]; |
102 | 102 | $relationClass = __NAMESPACE__ . '\\Relation\\' . Str::className($type); |
103 | 103 | |
104 | - if (! class_exists($relationClass)) { |
|
104 | + if (!class_exists($relationClass)) { |
|
105 | 105 | throw new InvalidArgumentException("{$relationClass} does not exist"); |
106 | 106 | } |
107 | 107 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | } |
116 | 116 | |
117 | 117 | $mapper = $mapperConfigOrFactory($this); |
118 | - if (! $mapper instanceof Mapper) { |
|
118 | + if (!$mapper instanceof Mapper) { |
|
119 | 119 | throw new InvalidArgumentException( |
120 | 120 | 'The mapper generated from the factory is not a valid `Mapper` instance' |
121 | 121 | ); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | $mapper->entityClass = $mapperConfig->entityClass; |
138 | 138 | } |
139 | 139 | |
140 | - if ($mapperConfig->behaviours && ! empty($mapperConfig->behaviours)) { |
|
140 | + if ($mapperConfig->behaviours && !empty($mapperConfig->behaviours)) { |
|
141 | 141 | $mapper->use(...$mapperConfig->behaviours); |
142 | 142 | } |
143 | 143 | |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | public function __construct(Orm $orm, HydratorInterface $entityHydrator = null, QueryBuilder $queryBuilder = null) |
148 | 148 | { |
149 | 149 | $this->orm = $orm; |
150 | - if (! $entityHydrator) { |
|
150 | + if (!$entityHydrator) { |
|
151 | 151 | $entityHydrator = new GenericEntityHydrator($orm, $this); |
152 | 152 | } |
153 | - if (! $queryBuilder) { |
|
153 | + if (!$queryBuilder) { |
|
154 | 154 | $this->queryBuilder = QueryBuilder::getInstance(); |
155 | 155 | } |
156 | 156 | $this->entityHydrator = $entityHydrator; |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | $mapper = $this; |
222 | 222 | |
223 | 223 | $singular = Inflector::singularize($this->getTableAlias(true)); |
224 | - $castingManager->register($singular, function ($value) use ($mapper, $castingManager) { |
|
224 | + $castingManager->register($singular, function($value) use ($mapper, $castingManager) { |
|
225 | 225 | if ($value instanceof $this->entityClass) { |
226 | 226 | return $value; |
227 | 227 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | }); |
231 | 231 | |
232 | 232 | $plural = $this->getTableAlias(true); |
233 | - $castingManager->register($plural, function ($values) use ($mapper, $castingManager) { |
|
233 | + $castingManager->register($plural, function($values) use ($mapper, $castingManager) { |
|
234 | 234 | if ($values instanceof Collection) { |
235 | 235 | return $values; |
236 | 236 | } |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | */ |
265 | 265 | public function getTableAlias($returnTableIfNull = false) |
266 | 266 | { |
267 | - return (! $this->tableAlias && $returnTableIfNull) ? $this->table : $this->tableAlias; |
|
267 | + return (!$this->tableAlias && $returnTableIfNull) ? $this->table : $this->tableAlias; |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | public function getTableReference() |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | return null; |
330 | 330 | } |
331 | 331 | |
332 | - $receivedTracker = ! ! $tracker; |
|
333 | - if (! $tracker) { |
|
332 | + $receivedTracker = !!$tracker; |
|
333 | + if (!$tracker) { |
|
334 | 334 | $receivedTracker = false; |
335 | 335 | $tracker = new Tracker($this, [$data]); |
336 | 336 | } |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | $this->injectRelations($entity, $tracker, $load); |
340 | 340 | $entity->setPersistenceState(StateEnum::SYNCHRONIZED); |
341 | 341 | |
342 | - if (! $receivedTracker) { |
|
342 | + if (!$receivedTracker) { |
|
343 | 343 | $tracker->replaceRows([$entity]); |
344 | 344 | if ($tracker->isDisposable()) { |
345 | 345 | unset($tracker); |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | $queryCallback = $eagerLoad[$name] ?? null; |
395 | 395 | $nextLoad = Arr::getChildren($eagerLoad, $name); |
396 | 396 | |
397 | - if (! $tracker->hasRelation($name)) { |
|
397 | + if (!$tracker->hasRelation($name)) { |
|
398 | 398 | $tracker->setRelation($name, $relation, $queryCallback); |
399 | 399 | } |
400 | 400 | |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | |
432 | 432 | public function getRelation($name): Relation |
433 | 433 | { |
434 | - if (! $this->hasRelation($name)) { |
|
434 | + if (!$this->hasRelation($name)) { |
|
435 | 435 | throw new \InvalidArgumentException("Relation named {$name} is not registered for this mapper"); |
436 | 436 | } |
437 | 437 | |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | $this->relations[$name] = $this->orm->createRelation($this, $name, $this->relations[$name]); |
440 | 440 | } |
441 | 441 | $relation = $this->relations[$name]; |
442 | - if (! $relation instanceof Relation) { |
|
442 | + if (!$relation instanceof Relation) { |
|
443 | 443 | throw new \InvalidArgumentException("Relation named {$name} is not a proper Relation instance"); |
444 | 444 | } |
445 | 445 | |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | |
493 | 493 | public function newSaveAction(EntityInterface $entity, $options): BaseAction |
494 | 494 | { |
495 | - if (! $entity->getPk()) { |
|
495 | + if (!$entity->getPk()) { |
|
496 | 496 | $action = new Insert($this, $entity, $options); |
497 | 497 | } else { |
498 | 498 | $action = new Update($this, $entity, $options); |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | |
530 | 530 | protected function assertCanPersistEntity($entity) |
531 | 531 | { |
532 | - if (! $entity || ! $entity instanceof $this->entityClass) { |
|
532 | + if (!$entity || !$entity instanceof $this->entityClass) { |
|
533 | 533 | throw new \InvalidArgumentException(sprintf( |
534 | 534 | 'Mapper %s can only persist entity of class %s. %s class provided', |
535 | 535 | __CLASS__, |