@@ -26,10 +26,10 @@ discard block |
||
26 | 26 | |
27 | 27 | protected function addActionOnDelete(BaseAction $action) |
28 | 28 | { |
29 | - $relations = $action->getOption('relations'); |
|
29 | + $relations = $action->getOption('relations'); |
|
30 | 30 | |
31 | 31 | // no cascade delete? treat it as a save |
32 | - if (! $this->isCascade()) { |
|
32 | + if (!$this->isCascade()) { |
|
33 | 33 | $this->addActionOnSave($action); |
34 | 34 | } elseif ($relations === true || in_array($this->name, (array)$relations)) { |
35 | 35 | $nativeEntity = $action->getEntity(); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | ->first(); |
42 | 42 | |
43 | 43 | if ($foreignEntity) { |
44 | - $deleteAction = $this->foreignMapper |
|
44 | + $deleteAction = $this->foreignMapper |
|
45 | 45 | ->newDeleteAction($foreignEntity, ['relations' => $remainingRelations]); |
46 | 46 | $action->prepend($deleteAction); |
47 | 47 | $action->append($this->newSyncAction($action->getEntity(), $foreignEntity, 'delete')); |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | |
62 | 62 | protected function addActionOnSave(BaseAction $action) |
63 | 63 | { |
64 | - if (! $this->relationWasChanged($action->getEntity())) { |
|
64 | + if (!$this->relationWasChanged($action->getEntity())) { |
|
65 | 65 | return; |
66 | 66 | } |
67 | 67 | |
68 | - if (! $action->includesRelation($this->name)) { |
|
68 | + if (!$action->includesRelation($this->name)) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | 71 |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | |
77 | 77 | protected function setOptionIfMissing($name, $value) |
78 | 78 | { |
79 | - if (! isset($this->options[$name])) { |
|
79 | + if (!isset($this->options[$name])) { |
|
80 | 80 | $this->options[$name] = $value; |
81 | 81 | } |
82 | 82 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | protected function getKeyColumn($name, $column) |
117 | 117 | { |
118 | - if (! is_array($column)) { |
|
118 | + if (!is_array($column)) { |
|
119 | 119 | return $name . '_' . $column; |
120 | 120 | } |
121 | 121 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | |
177 | 177 | foreach ($entities as $entity) { |
178 | 178 | $entityId = $this->getEntityId($this->foreignMapper, $entity, array_values($this->keyPairs)); |
179 | - if (! isset($result[$entityId])) { |
|
179 | + if (!isset($result[$entityId])) { |
|
180 | 180 | $result[$entityId] = []; |
181 | 181 | } |
182 | 182 | $result[$entityId][] = $entity; |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | protected function getRemainingRelations($relations) |
225 | 225 | { |
226 | - if (! is_array($relations)) { |
|
226 | + if (!is_array($relations)) { |
|
227 | 227 | return $relations; |
228 | 228 | } |
229 | 229 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | if (is_array($guards)) { |
245 | 245 | foreach ($guards as $col => $val) { |
246 | 246 | // guards that are strings (eg: 'deleted_at is null') can't be used as extra columns |
247 | - if (! is_int($col)) { |
|
247 | + if (!is_int($col)) { |
|
248 | 248 | $cols[$col] = $val; |
249 | 249 | } |
250 | 250 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | |
16 | 16 | $aggregates = []; |
17 | 17 | $aggregatesList = $this->getOption(RelationConfig::AGGREGATES); |
18 | - if (! is_array($aggregatesList) || empty($aggregatesList)) { |
|
18 | + if (!is_array($aggregatesList) || empty($aggregatesList)) { |
|
19 | 19 | $this->aggregates = $aggregates; |
20 | 20 | |
21 | 21 | return; |
@@ -39,27 +39,27 @@ |
||
39 | 39 | { |
40 | 40 | $errors = []; |
41 | 41 | |
42 | - if (! $this->entityNamespace) { |
|
42 | + if (!$this->entityNamespace) { |
|
43 | 43 | $errors[] = 'Missing entity namespace property'; |
44 | 44 | } |
45 | 45 | |
46 | - if (! $this->entityDestination) { |
|
46 | + if (!$this->entityDestination) { |
|
47 | 47 | $errors[] = 'Missing entity destination property'; |
48 | - } elseif (! is_dir($this->entityDestination)) { |
|
48 | + } elseif (!is_dir($this->entityDestination)) { |
|
49 | 49 | $errors[] = sprintf('%s is not a valid directory', $this->entityDestination); |
50 | - } elseif (! is_writable($this->entityDestination)) { |
|
50 | + } elseif (!is_writable($this->entityDestination)) { |
|
51 | 51 | $errors[] = sprintf('%s is not writable', $this->entityDestination); |
52 | 52 | } |
53 | 53 | |
54 | - if (! $this->mapperNamespace) { |
|
54 | + if (!$this->mapperNamespace) { |
|
55 | 55 | $errors[] = 'Missing mapper namespace property'; |
56 | 56 | } |
57 | 57 | |
58 | - if (! $this->mapperDestination) { |
|
58 | + if (!$this->mapperDestination) { |
|
59 | 59 | $errors[] = 'Missing entity destination property'; |
60 | - } elseif (! is_dir($this->mapperDestination)) { |
|
60 | + } elseif (!is_dir($this->mapperDestination)) { |
|
61 | 61 | $errors[] = sprintf('%s is not a valid directory', $this->mapperDestination); |
62 | - } elseif (! is_writable($this->mapperDestination)) { |
|
62 | + } elseif (!is_writable($this->mapperDestination)) { |
|
63 | 63 | $errors[] = sprintf('%s is not writable', $this->mapperDestination); |
64 | 64 | } |
65 | 65 |
@@ -49,28 +49,28 @@ discard block |
||
49 | 49 | { |
50 | 50 | $errors = []; |
51 | 51 | |
52 | - if (! $this->name) { |
|
52 | + if (!$this->name) { |
|
53 | 53 | $errors[] = "Unknown relation name"; |
54 | 54 | } |
55 | 55 | |
56 | - if (! $this->type) { |
|
56 | + if (!$this->type) { |
|
57 | 57 | $errors[] = "Unknown relation type"; |
58 | 58 | } |
59 | 59 | |
60 | - if (! $this->nativeKey) { |
|
60 | + if (!$this->nativeKey) { |
|
61 | 61 | $errors[] = "Missing native key column"; |
62 | 62 | } |
63 | 63 | |
64 | - if (! $this->foreignMapper) { |
|
64 | + if (!$this->foreignMapper) { |
|
65 | 65 | $errors[] = "Missing foreign mapper name"; |
66 | 66 | } |
67 | 67 | |
68 | - if (! $this->foreignKey) { |
|
68 | + if (!$this->foreignKey) { |
|
69 | 69 | $errors[] = "Missing foreign key"; |
70 | 70 | } |
71 | 71 | |
72 | 72 | $strategies = [RelationConfig::LOAD_LAZY, RelationConfig::LOAD_EAGER, RelationConfig::LOAD_NONE]; |
73 | - if (! in_array($this->loadStrategy, $strategies)) { |
|
73 | + if (!in_array($this->loadStrategy, $strategies)) { |
|
74 | 74 | $errors[] = sprintf("Relation loading strategy is not valid (allowed values: %s)", implode(', ', $strategies)); |
75 | 75 | } |
76 | 76 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | $value !== 0 && |
206 | 206 | $value !== '' && |
207 | 207 | $value !== [] && |
208 | - ! is_object($value)) { |
|
208 | + !is_object($value)) { |
|
209 | 209 | $result[Str::underscore($prop)] = $value; |
210 | 210 | } |
211 | 211 | if (is_object($value) && is_callable($value)) { |
@@ -32,11 +32,11 @@ |
||
32 | 32 | { |
33 | 33 | $errors = []; |
34 | 34 | |
35 | - if (! $this->name) { |
|
35 | + if (!$this->name) { |
|
36 | 36 | $errors[] = 'Method requires a name'; |
37 | 37 | } |
38 | 38 | |
39 | - if (! in_array($this->visibility, [ClassType::VISIBILITY_PUBLIC, ClassType::VISIBILITY_PROTECTED])) { |
|
39 | + if (!in_array($this->visibility, [ClassType::VISIBILITY_PUBLIC, ClassType::VISIBILITY_PROTECTED])) { |
|
40 | 40 | $errors[] = 'Wrong method visilibity type. Only `public` and `protected` are allowed.'; |
41 | 41 | } |
42 | 42 |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | |
59 | 59 | protected function maybeSetAdditionalProperties() |
60 | 60 | { |
61 | - if (! $this->mapper || ! $this->foreignMapper) { |
|
61 | + if (!$this->mapper || !$this->foreignMapper) { |
|
62 | 62 | return; |
63 | 63 | } |
64 | 64 | |
65 | - if (! $this->throughTable) { |
|
65 | + if (!$this->throughTable) { |
|
66 | 66 | $tablePrefix = $this->mapper->getTableAlias() ? |
67 | 67 | str_replace($this->mapper->getTable(), '', $this->mapper->getTableAlias()) |
68 | 68 | : ''; |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | - if (! $this->throughNativeColumn) { |
|
80 | + if (!$this->throughNativeColumn) { |
|
81 | 81 | $this->throughNativeColumn = Inflector::singularize($this->mapper->getName()) . '_id'; |
82 | 82 | } |
83 | 83 | |
84 | - if (! $this->throughForeignColumn) { |
|
84 | + if (!$this->throughForeignColumn) { |
|
85 | 85 | $this->throughForeignColumn = Inflector::singularize($this->foreignMapper) . '_id'; |
86 | 86 | } |
87 | 87 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | return $this; |
139 | 139 | } |
140 | 140 | |
141 | - if (! $this->mapper->hasRelation($name)) { |
|
141 | + if (!$this->mapper->hasRelation($name)) { |
|
142 | 142 | throw new \InvalidArgumentException( |
143 | 143 | sprintf("Relation %s, not defined for %s", $name, $this->mapper->getConfig()->getTable()) |
144 | 144 | ); |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | return null; |
201 | 201 | } |
202 | 202 | |
203 | - $receivedTracker = ! ! $tracker; |
|
204 | - if (! $tracker) { |
|
203 | + $receivedTracker = !!$tracker; |
|
204 | + if (!$tracker) { |
|
205 | 205 | $receivedTracker = false; |
206 | 206 | $tracker = new Tracker([$data]); |
207 | 207 | } |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | $this->injectAggregates($entity, $tracker, $load); |
212 | 212 | $entity->setState(StateEnum::SYNCHRONIZED); |
213 | 213 | |
214 | - if (! $receivedTracker) { |
|
214 | + if (!$receivedTracker) { |
|
215 | 215 | $tracker->replaceRows([$entity]); |
216 | 216 | } |
217 | 217 | |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | $queryCallback = $eagerLoad[$name] ?? null; |
263 | 263 | $nextLoad = Arr::getChildren($eagerLoad, $name); |
264 | 264 | |
265 | - if (! $tracker->hasRelation($name)) { |
|
265 | + if (!$tracker->hasRelation($name)) { |
|
266 | 266 | $tracker->setRelation($name, $relation, $queryCallback, $nextLoad); |
267 | 267 | } |
268 | 268 | |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | { |
279 | 279 | foreach ($this->mapper->getRelations() as $name) { |
280 | 280 | $relation = $this->mapper->getRelation($name); |
281 | - if (! method_exists($relation, 'getAggregates')) { |
|
281 | + if (!method_exists($relation, 'getAggregates')) { |
|
282 | 282 | continue; |
283 | 283 | } |
284 | 284 | $aggregates = $relation->getAggregates(); |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | */ |
308 | 308 | public function chunk(int $size, callable $callback, int $limit = 100000) |
309 | 309 | { |
310 | - if (! $this->orderBy->build()) { |
|
310 | + if (!$this->orderBy->build()) { |
|
311 | 311 | $this->orderBy(...(array)$this->mapper->getConfig()->getPrimaryKey()); |
312 | 312 | } |
313 | 313 |
@@ -22,28 +22,28 @@ discard block |
||
22 | 22 | parent::applyDefaults(); |
23 | 23 | |
24 | 24 | $foreignKey = $this->foreignMapper->getConfig()->getPrimaryKey(); |
25 | - if (! isset($this->options[RelationConfig::FOREIGN_KEY])) { |
|
25 | + if (!isset($this->options[RelationConfig::FOREIGN_KEY])) { |
|
26 | 26 | $this->options[RelationConfig::FOREIGN_KEY] = $foreignKey; |
27 | 27 | } |
28 | 28 | |
29 | 29 | $nativeKey = $this->foreignMapper->getConfig()->getPrimaryKey(); |
30 | - if (! isset($this->options[RelationConfig::NATIVE_KEY])) { |
|
30 | + if (!isset($this->options[RelationConfig::NATIVE_KEY])) { |
|
31 | 31 | $this->options[RelationConfig::NATIVE_KEY] = $nativeKey; |
32 | 32 | } |
33 | 33 | |
34 | - if (! isset($this->options[RelationConfig::THROUGH_TABLE])) { |
|
34 | + if (!isset($this->options[RelationConfig::THROUGH_TABLE])) { |
|
35 | 35 | $tables = [$this->foreignMapper->getConfig()->getTable(), $this->nativeMapper->getConfig()->getTable()]; |
36 | 36 | sort($tables); |
37 | 37 | $this->options[RelationConfig::THROUGH_TABLE] = implode('_', $tables); |
38 | 38 | } |
39 | 39 | |
40 | - if (! isset($this->options[RelationConfig::THROUGH_NATIVE_COLUMN])) { |
|
40 | + if (!isset($this->options[RelationConfig::THROUGH_NATIVE_COLUMN])) { |
|
41 | 41 | $prefix = Inflector::singularize($this->nativeMapper->getConfig()->getTableAlias(true)); |
42 | 42 | |
43 | 43 | $this->options[RelationConfig::THROUGH_NATIVE_COLUMN] = $this->getKeyColumn($prefix, $nativeKey); |
44 | 44 | } |
45 | 45 | |
46 | - if (! isset($this->options[RelationConfig::THROUGH_FOREIGN_COLUMN])) { |
|
46 | + if (!isset($this->options[RelationConfig::THROUGH_FOREIGN_COLUMN])) { |
|
47 | 47 | $prefix = Inflector::singularize($this->foreignMapper->getConfig()->getTableAlias(true)); |
48 | 48 | |
49 | 49 | $this->options[RelationConfig::THROUGH_FOREIGN_COLUMN] = $this->getKeyColumn($prefix, $foreignKey); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | $throughAlias = $this->getOption(RelationConfig::THROUGH_TABLE_ALIAS); |
97 | 97 | $throughName = $throughAlias ?? $through; |
98 | 98 | |
99 | - if (! empty($throughColumns)) { |
|
99 | + if (!empty($throughColumns)) { |
|
100 | 100 | foreach ($throughColumns as $col => $alias) { |
101 | 101 | $query->columns("{$throughName}.{$col} AS {$alias}"); |
102 | 102 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | |
178 | 178 | protected function addActionOnDelete(BaseAction $action) |
179 | 179 | { |
180 | - $nativeEntity = $action->getEntity(); |
|
180 | + $nativeEntity = $action->getEntity(); |
|
181 | 181 | |
182 | 182 | // retrieve them again from the DB since the related collection might not have everything |
183 | 183 | // for example due to a relation query callback |
@@ -192,11 +192,11 @@ discard block |
||
192 | 192 | |
193 | 193 | protected function addActionOnSave(BaseAction $action) |
194 | 194 | { |
195 | - if (! $this->relationWasChanged($action->getEntity())) { |
|
195 | + if (!$this->relationWasChanged($action->getEntity())) { |
|
196 | 196 | return; |
197 | 197 | } |
198 | 198 | |
199 | - if (! $action->includesRelation($this->name)) { |
|
199 | + if (!$action->includesRelation($this->name)) { |
|
200 | 200 | return; |
201 | 201 | } |
202 | 202 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | |
205 | 205 | /** @var Collection $foreignEntities */ |
206 | 206 | $foreignEntities = $this->nativeEntityHydrator->get($action->getEntity(), $this->name); |
207 | - if (! $foreignEntities || !$foreignEntities instanceof Collection || $foreignEntities->isEmpty()) { |
|
207 | + if (!$foreignEntities || !$foreignEntities instanceof Collection || $foreignEntities->isEmpty()) { |
|
208 | 208 | return; |
209 | 209 | } |
210 | 210 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | |
213 | 213 | // save the entities still in the collection |
214 | 214 | foreach ($foreignEntities as $foreignEntity) { |
215 | - if (! empty($foreignEntity->getChanges())) { |
|
215 | + if (!empty($foreignEntity->getChanges())) { |
|
216 | 216 | $saveAction = $this->foreignMapper |
217 | 217 | ->newSaveAction($foreignEntity, [ |
218 | 218 | 'relations' => $remainingRelations |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $query = $this->foreignMapper->newQuery(); |
63 | 63 | |
64 | 64 | $query = $this->joinWithThroughTable($query) |
65 | - ->where($this->options[RelationConfig::THROUGH_NATIVE_COLUMN], $nativePks); |
|
65 | + ->where($this->options[RelationConfig::THROUGH_NATIVE_COLUMN], $nativePks); |
|
66 | 66 | |
67 | 67 | $query = $this->applyQueryCallback($query); |
68 | 68 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | { |
117 | 117 | $subselect = $this->foreignMapper->newQuery(); |
118 | 118 | $subselect = $query->subSelectForJoinWith($this->foreignMapper) |
119 | - ->as($reference); |
|
119 | + ->as($reference); |
|
120 | 120 | #$subselect->resetGuards(); |
121 | 121 | #$subselect->setGuards($this->foreignMapper->getConfig()->getGuards()); |
122 | 122 |