@@ -11,7 +11,7 @@ |
||
11 | 11 | $dict = $this->getDictionary(); |
12 | 12 | |
13 | 13 | // Enforce sorting by $orderColumn setting in Baum\Node instance |
14 | - uasort($dict, function ($a, $b) { |
|
14 | + uasort($dict, function($a, $b) { |
|
15 | 15 | return ($a->getOrder() >= $b->getOrder()) ? 1 : -1; |
16 | 16 | }); |
17 | 17 |
@@ -38,7 +38,7 @@ |
||
38 | 38 | { |
39 | 39 | $self = $this; |
40 | 40 | |
41 | - return $this->wrapInTransaction(function () use ($self, $nodeList) { |
|
41 | + return $this->wrapInTransaction(function() use ($self, $nodeList) { |
|
42 | 42 | forward_static_call([get_class($self->node), 'unguard']); |
43 | 43 | |
44 | 44 | $result = $self->mapTree($nodeList); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | |
127 | 127 | $columns = array_merge($this->node->getQualifiedScopedColumns(), [$column]); |
128 | 128 | |
129 | - $columnsForSelect = implode(', ', array_map(function ($col) use ($grammar) { |
|
129 | + $columnsForSelect = implode(', ', array_map(function($col) use ($grammar) { |
|
130 | 130 | return $grammar->wrap($col); |
131 | 131 | }, $columns)); |
132 | 132 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | */ |
226 | 226 | protected function keyForScope(Model $node): string |
227 | 227 | { |
228 | - return implode('-', array_map(function ($column) use ($node) { |
|
228 | + return implode('-', array_map(function($column) use ($node) { |
|
229 | 229 | $value = $node->getAttribute($column); |
230 | 230 | |
231 | 231 | if (is_null($value)) { |
@@ -105,30 +105,30 @@ discard block |
||
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | - * Get the parent column name. |
|
109 | - * |
|
110 | - * @return string |
|
111 | - */ |
|
108 | + * Get the parent column name. |
|
109 | + * |
|
110 | + * @return string |
|
111 | + */ |
|
112 | 112 | public function getParentColumnName(): string |
113 | 113 | { |
114 | 114 | return $this->parentColumn; |
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
118 | - * Get the table qualified parent column name. |
|
119 | - * |
|
120 | - * @return string |
|
121 | - */ |
|
118 | + * Get the table qualified parent column name. |
|
119 | + * |
|
120 | + * @return string |
|
121 | + */ |
|
122 | 122 | public function getQualifiedParentColumnName(): string |
123 | 123 | { |
124 | 124 | return $this->getTable().'.'.$this->getParentColumnName(); |
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get the value of the models "parent_id" field. |
|
129 | - * |
|
130 | - * @return int|string |
|
131 | - */ |
|
128 | + * Get the value of the models "parent_id" field. |
|
129 | + * |
|
130 | + * @return int|string |
|
131 | + */ |
|
132 | 132 | public function getParentId() |
133 | 133 | { |
134 | 134 | return $this->getAttribute($this->getparentColumnName()); |
@@ -294,20 +294,20 @@ discard block |
||
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | - * Parent relation (self-referential) 1-1. |
|
298 | - * |
|
299 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
300 | - */ |
|
297 | + * Parent relation (self-referential) 1-1. |
|
298 | + * |
|
299 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
300 | + */ |
|
301 | 301 | public function parent(): BelongsTo |
302 | 302 | { |
303 | 303 | return $this->belongsTo(get_class($this), $this->getParentColumnName()); |
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
307 | - * Children relation (self-referential) 1-N. |
|
308 | - * |
|
309 | - * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
310 | - */ |
|
307 | + * Children relation (self-referential) 1-N. |
|
308 | + * |
|
309 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
310 | + */ |
|
311 | 311 | public function children(): HasMany |
312 | 312 | { |
313 | 313 | return $this->hasMany(get_class($this), $this->getParentColumnName()) |
@@ -821,11 +821,11 @@ discard block |
||
821 | 821 | } |
822 | 822 | |
823 | 823 | /** |
824 | - * Returns the level of this node in the tree. |
|
825 | - * Root level is 0. |
|
826 | - * |
|
827 | - * @return int |
|
828 | - */ |
|
824 | + * Returns the level of this node in the tree. |
|
825 | + * Root level is 0. |
|
826 | + * |
|
827 | + * @return int |
|
828 | + */ |
|
829 | 829 | public function getLevel(): int |
830 | 830 | { |
831 | 831 | if (is_null($this->getParentId())) { |
@@ -844,7 +844,7 @@ discard block |
||
844 | 844 | public function isDescendantOf($other): bool |
845 | 845 | { |
846 | 846 | return ( |
847 | - $this->getLeft() > $other->getLeft() && |
|
847 | + $this->getLeft() > $other->getLeft() && |
|
848 | 848 | $this->getLeft() < $other->getRight() && |
849 | 849 | $this->inSameScope($other) |
850 | 850 | ); |
@@ -859,7 +859,7 @@ discard block |
||
859 | 859 | public function isSelfOrDescendantOf($other): bool |
860 | 860 | { |
861 | 861 | return ( |
862 | - $this->getLeft() >= $other->getLeft() && |
|
862 | + $this->getLeft() >= $other->getLeft() && |
|
863 | 863 | $this->getLeft() < $other->getRight() && |
864 | 864 | $this->inSameScope($other) |
865 | 865 | ); |
@@ -874,7 +874,7 @@ discard block |
||
874 | 874 | public function isAncestorOf($other): bool |
875 | 875 | { |
876 | 876 | return ( |
877 | - $this->getLeft() < $other->getLeft() && |
|
877 | + $this->getLeft() < $other->getLeft() && |
|
878 | 878 | $this->getRight() > $other->getLeft() && |
879 | 879 | $this->inSameScope($other) |
880 | 880 | ); |
@@ -889,7 +889,7 @@ discard block |
||
889 | 889 | public function isSelfOrAncestorOf($other): bool |
890 | 890 | { |
891 | 891 | return ( |
892 | - $this->getLeft() <= $other->getLeft() && |
|
892 | + $this->getLeft() <= $other->getLeft() && |
|
893 | 893 | $this->getRight() > $other->getLeft() && |
894 | 894 | $this->inSameScope($other) |
895 | 895 | ); |
@@ -1261,8 +1261,8 @@ discard block |
||
1261 | 1261 | ->where($self->getLeftColumnName(), '>', $self->getLeft()) |
1262 | 1262 | ->where($self->getRightColumnName(), '<', $self->getRight()) |
1263 | 1263 | ->update([ |
1264 | - $self->getDeletedAtColumn() => null, |
|
1265 | - $self->getUpdatedAtColumn() => $self->{$self->getUpdatedAtColumn()}, |
|
1264 | + $self->getDeletedAtColumn() => null, |
|
1265 | + $self->getUpdatedAtColumn() => $self->{$self->getUpdatedAtColumn()}, |
|
1266 | 1266 | ]); |
1267 | 1267 | }); |
1268 | 1268 | } |
@@ -1354,12 +1354,12 @@ discard block |
||
1354 | 1354 | } |
1355 | 1355 | |
1356 | 1356 | /** |
1357 | - * Reloads the model from the database. |
|
1358 | - * |
|
1359 | - * @return \Baum\Node |
|
1360 | - * |
|
1361 | - * @throws ModelNotFoundException |
|
1362 | - */ |
|
1357 | + * Reloads the model from the database. |
|
1358 | + * |
|
1359 | + * @return \Baum\Node |
|
1360 | + * |
|
1361 | + * @throws ModelNotFoundException |
|
1362 | + */ |
|
1363 | 1363 | public function reload(): Model |
1364 | 1364 | { |
1365 | 1365 | if ($this->exists || ($this->areSoftDeletesEnabled() && $this->trashed())) { |
@@ -76,29 +76,29 @@ discard block |
||
76 | 76 | */ |
77 | 77 | protected static function bootHasNestedSets(): void |
78 | 78 | { |
79 | - static::creating(function ($node) { |
|
79 | + static::creating(function($node) { |
|
80 | 80 | $node->setDefaultLeftAndRight(); |
81 | 81 | }); |
82 | 82 | |
83 | - static::saving(function ($node) { |
|
83 | + static::saving(function($node) { |
|
84 | 84 | $node->storeNewParent(); |
85 | 85 | }); |
86 | 86 | |
87 | - static::saved(function ($node) { |
|
87 | + static::saved(function($node) { |
|
88 | 88 | $node->moveToNewParent(); |
89 | 89 | $node->setDepth(); |
90 | 90 | }); |
91 | 91 | |
92 | - static::deleting(function ($node) { |
|
92 | + static::deleting(function($node) { |
|
93 | 93 | $node->destroyDescendants(); |
94 | 94 | }); |
95 | 95 | |
96 | 96 | if (static::softDeletesEnabled()) { |
97 | - static::restoring(function ($node) { |
|
97 | + static::restoring(function($node) { |
|
98 | 98 | $node->shiftSiblingsForRestore(); |
99 | 99 | }); |
100 | 100 | |
101 | - static::restored(function ($node) { |
|
101 | + static::restored(function($node) { |
|
102 | 102 | $node->restoreDescendants(); |
103 | 103 | }); |
104 | 104 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | |
278 | 278 | $prefix = $this->getTable().'.'; |
279 | 279 | |
280 | - return array_map(function ($c) use ($prefix) { |
|
280 | + return array_map(function($c) use ($prefix) { |
|
281 | 281 | return $prefix.$c; |
282 | 282 | }, $this->getScopedColumns()); |
283 | 283 | } |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | { |
1139 | 1139 | $self = $this; |
1140 | 1140 | |
1141 | - $this->getConnection()->transaction(function () use ($self) { |
|
1141 | + $this->getConnection()->transaction(function() use ($self) { |
|
1142 | 1142 | $self->reload(); |
1143 | 1143 | |
1144 | 1144 | $level = $self->getLevel(); |
@@ -1159,7 +1159,7 @@ discard block |
||
1159 | 1159 | { |
1160 | 1160 | $self = $this; |
1161 | 1161 | |
1162 | - $this->getConnection()->transaction(function () use ($self) { |
|
1162 | + $this->getConnection()->transaction(function() use ($self) { |
|
1163 | 1163 | $self->reload(); |
1164 | 1164 | |
1165 | 1165 | $self->descendantsAndSelf()->select($self->getKeyName())->lockForUpdate()->get(); |
@@ -1194,7 +1194,7 @@ discard block |
||
1194 | 1194 | |
1195 | 1195 | $self = $this; |
1196 | 1196 | |
1197 | - $this->getConnection()->transaction(function () use ($self) { |
|
1197 | + $this->getConnection()->transaction(function() use ($self) { |
|
1198 | 1198 | $self->reload(); |
1199 | 1199 | |
1200 | 1200 | $lftCol = $self->getLeftColumnName(); |
@@ -1229,7 +1229,7 @@ discard block |
||
1229 | 1229 | |
1230 | 1230 | $self = $this; |
1231 | 1231 | |
1232 | - $this->getConnection()->transaction(function () use ($self) { |
|
1232 | + $this->getConnection()->transaction(function() use ($self) { |
|
1233 | 1233 | $lftCol = $self->getLeftColumnName(); |
1234 | 1234 | $rgtCol = $self->getRightColumnName(); |
1235 | 1235 | $lft = $self->getLeft(); |
@@ -1255,7 +1255,7 @@ discard block |
||
1255 | 1255 | |
1256 | 1256 | $self = $this; |
1257 | 1257 | |
1258 | - $this->getConnection()->transaction(function () use ($self) { |
|
1258 | + $this->getConnection()->transaction(function() use ($self) { |
|
1259 | 1259 | $self->newNestedSetQuery() |
1260 | 1260 | ->withTrashed() |
1261 | 1261 | ->where($self->getLeftColumnName(), '>', $self->getLeft()) |
@@ -1281,9 +1281,9 @@ discard block |
||
1281 | 1281 | |
1282 | 1282 | $nodes = $instance->newNestedSetQuery()->get()->toArray(); |
1283 | 1283 | |
1284 | - return array_combine(array_map(function ($node) use ($key) { |
|
1284 | + return array_combine(array_map(function($node) use ($key) { |
|
1285 | 1285 | return $node[$key]; |
1286 | - }, $nodes), array_map(function ($node) use ($seperator, $depthColumn, $column) { |
|
1286 | + }, $nodes), array_map(function($node) use ($seperator, $depthColumn, $column) { |
|
1287 | 1287 | return str_repeat($seperator, $node[$depthColumn]).$node[$column]; |
1288 | 1288 | }, $nodes)); |
1289 | 1289 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | // setting the right indexes and saving the nodes... |
41 | 41 | $self = $this; |
42 | 42 | |
43 | - $this->node->getConnection()->transaction(function () use ($self) { |
|
43 | + $this->node->getConnection()->transaction(function() use ($self) { |
|
44 | 44 | foreach ($self->roots() as $root) { |
45 | 45 | $self->rebuildBounds($root, 0); |
46 | 46 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | return []; |
122 | 122 | } |
123 | 123 | |
124 | - $values = array_map(function ($column) use ($node) { |
|
124 | + $values = array_map(function($column) use ($node) { |
|
125 | 125 | return $node->getAttribute($column); |
126 | 126 | }, $keys); |
127 | 127 |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | ELSE ${wrappedParent} END"; |
136 | 136 | |
137 | 137 | $updateConditions = [ |
138 | - $leftColumn => $connection->raw($lftSql), |
|
139 | - $rightColumn => $connection->raw($rgtSql), |
|
140 | - $parentColumn => $connection->raw($parentSql), |
|
138 | + $leftColumn => $connection->raw($lftSql), |
|
139 | + $rightColumn => $connection->raw($rgtSql), |
|
140 | + $parentColumn => $connection->raw($parentSql), |
|
141 | 141 | ]; |
142 | 142 | |
143 | 143 | if ($this->node->timestamps) { |
@@ -220,22 +220,22 @@ discard block |
||
220 | 220 | } |
221 | 221 | |
222 | 222 | switch ($this->position) { |
223 | - case 'child': |
|
223 | + case 'child': |
|
224 | 224 | $this->_bound1 = $this->target->getRight(); |
225 | 225 | |
226 | 226 | break; |
227 | 227 | |
228 | - case 'left': |
|
228 | + case 'left': |
|
229 | 229 | $this->_bound1 = $this->target->getLeft(); |
230 | 230 | |
231 | 231 | break; |
232 | 232 | |
233 | - case 'right': |
|
233 | + case 'right': |
|
234 | 234 | $this->_bound1 = $this->target->getRight() + 1; |
235 | 235 | |
236 | 236 | break; |
237 | 237 | |
238 | - case 'root': |
|
238 | + case 'root': |
|
239 | 239 | $this->_bound1 = $this->node->newNestedSetQuery()->max($this->node->getRightColumnName()) + 1; |
240 | 240 | |
241 | 241 | break; |
@@ -277,10 +277,10 @@ discard block |
||
277 | 277 | // we have defined the boundaries of two non-overlapping intervals, |
278 | 278 | // so sorting puts both the intervals and their boundaries in order |
279 | 279 | $this->_boundaries = [ |
280 | - $this->node->getLeft(), |
|
281 | - $this->node->getRight(), |
|
282 | - $this->bound1(), |
|
283 | - $this->bound2(), |
|
280 | + $this->node->getLeft(), |
|
281 | + $this->node->getRight(), |
|
282 | + $this->bound1(), |
|
283 | + $this->bound2(), |
|
284 | 284 | ]; |
285 | 285 | sort($this->_boundaries); |
286 | 286 | |
@@ -295,13 +295,13 @@ discard block |
||
295 | 295 | protected function parentId() |
296 | 296 | { |
297 | 297 | switch ($this->position) { |
298 | - case 'root': |
|
298 | + case 'root': |
|
299 | 299 | return null; |
300 | 300 | |
301 | - case 'child': |
|
301 | + case 'child': |
|
302 | 302 | return $this->target->getKey(); |
303 | 303 | |
304 | - default: |
|
304 | + default: |
|
305 | 305 | return $this->target->getParentId(); |
306 | 306 | } |
307 | 307 | } |
@@ -399,10 +399,10 @@ discard block |
||
399 | 399 | protected function applyLockBetween(int $lft, int $rgt): void |
400 | 400 | { |
401 | 401 | $this->node->newQuery() |
402 | - ->where($this->node->getLeftColumnName(), '>=', $lft) |
|
403 | - ->where($this->node->getRightColumnName(), '<=', $rgt) |
|
404 | - ->select($this->node->getKeyName()) |
|
405 | - ->lockForUpdate() |
|
406 | - ->get(); |
|
402 | + ->where($this->node->getLeftColumnName(), '>=', $lft) |
|
403 | + ->where($this->node->getRightColumnName(), '<=', $rgt) |
|
404 | + ->select($this->node->getKeyName()) |
|
405 | + ->lockForUpdate() |
|
406 | + ->get(); |
|
407 | 407 | } |
408 | 408 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | if ($this->hasChange()) { |
79 | 79 | $self = $this; |
80 | 80 | |
81 | - $this->node->getConnection()->transaction(function () use ($self) { |
|
81 | + $this->node->getConnection()->transaction(function() use ($self) { |
|
82 | 82 | $self->updateStructure(); |
83 | 83 | }); |
84 | 84 | |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | return $this->node |
148 | 148 | ->newNestedSetQuery() |
149 | - ->where(function ($query) use ($leftColumn, $rightColumn, $a, $d) { |
|
149 | + ->where(function($query) use ($leftColumn, $rightColumn, $a, $d) { |
|
150 | 150 | $query->whereBetween($leftColumn, [$a, $d]) |
151 | 151 | ->orWhereBetween($rightColumn, [$a, $d]); |
152 | 152 | }) |