Skip to content

Commit 17e8292

Browse files
committed
Refactored NestedSetsBehavior
1 parent 121ee14 commit 17e8292

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/NestedSetsBehavior.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class NestedSetsBehavior extends Behavior
2929
const OPERATION_INSERT_AFTER = 'insertAfter';
3030
const OPERATION_DELETE_WITH_CHILDREN = 'deleteWithChildren';
3131

32+
/**
33+
* @var string|false
34+
*/
35+
public $treeAttribute = false;
3236
/**
3337
* @var string
3438
*/
@@ -37,10 +41,6 @@ class NestedSetsBehavior extends Behavior
3741
* @var string
3842
*/
3943
public $rightAttribute = 'rgt';
40-
/**
41-
* @var string|false
42-
*/
43-
public $treeAttribute = false;
4444
/**
4545
* @var string
4646
*/
@@ -305,12 +305,11 @@ public function isRoot()
305305
*/
306306
public function isChildOf($node)
307307
{
308-
$result = ($this->owner->getAttribute($this->leftAttribute) > $node->getAttribute($this->leftAttribute))
309-
&& ($this->owner->getAttribute($this->rightAttribute) < $node->getAttribute($this->rightAttribute));
308+
$result = $this->owner->getAttribute($this->leftAttribute) > $node->getAttribute($this->leftAttribute)
309+
&& $this->owner->getAttribute($this->rightAttribute) < $node->getAttribute($this->rightAttribute);
310310

311-
if ($this->treeAttribute !== false) {
312-
$result = $result
313-
&& ($this->owner->getAttribute($this->treeAttribute) === $node->getAttribute($this->treeAttribute));
311+
if ($result && $this->treeAttribute !== false) {
312+
$result = $this->owner->getAttribute($this->treeAttribute) === $node->getAttribute($this->treeAttribute);
314313
}
315314

316315
return $result;
@@ -448,11 +447,11 @@ public function beforeUpdate()
448447
if ($this->node->getIsNewRecord()) {
449448
throw new Exception('Can not move a node when the target node is new record.');
450449
}
451-
450+
452451
if ($this->owner->equals($this->node)) {
453452
throw new Exception('Can not move a node when the target node is same.');
454453
}
455-
454+
456455
if ($this->node->isChildOf($this->owner)) {
457456
throw new Exception('Can not move a node when the target node is child.');
458457
}

0 commit comments

Comments
 (0)