diff --git a/src/Models/Entity.php b/src/Models/Entity.php index df423c6..f0abb02 100644 --- a/src/Models/Entity.php +++ b/src/Models/Entity.php @@ -166,7 +166,7 @@ public function setParentIdAttribute($value) } $parentId = $this->getParentIdColumn(); - $this->previousParentId = isset($this->original[$parentId]) ? $this->original[$parentId] : null; + $this->previousParentId = $this->original[$parentId] ?? null; $this->attributes[$parentId] = $value; } @@ -212,7 +212,7 @@ public function setPositionAttribute($value) } $position = $this->getPositionColumn(); - $this->previousPosition = isset($this->original[$position]) ? $this->original[$position] : null; + $this->previousPosition = $this->original[$position] ?? null; $this->attributes[$position] = max(0, (int) $value); } @@ -298,7 +298,7 @@ public static function boot() $entity->previousPosition = null; $descendant = $entity->getKey(); - $ancestor = isset($entity->parent_id) ? $entity->parent_id : $descendant; + $ancestor = $entity->parent_id ?? $descendant; $entity->closure->insertNode($ancestor, $descendant); }); @@ -883,7 +883,7 @@ public function getChildrenRange($from, $to = null, array $columns = ['*']) public function addChild(EntityInterface $child, $position = null, $returnChild = false) { if ($this->exists) { - $position = $position !== null ? $position : $this->getLatestChildPosition(); + $position = $position ?? $this->getLatestChildPosition(); $child->moveTo($position, $this); } @@ -1596,7 +1596,7 @@ private function buildSiblingQuery(Builder $builder, $id, callable $positionCall public function addSibling(EntityInterface $sibling, $position = null, $returnSibling = false) { if ($this->exists) { - $position = $position === null ? static::getLatestPosition($this) : $position; + $position = $position ?? static::getLatestPosition($this); $sibling->moveTo($position, $this->parent_id); @@ -1623,7 +1623,7 @@ public function addSiblings(array $siblings, $from = null) return $this; } - $from = $from === null ? static::getLatestPosition($this) : $from; + $from = $from ?? static::getLatestPosition($this); $this->transactional(function () use ($siblings, &$from) { foreach ($siblings as $sibling) { @@ -1876,7 +1876,7 @@ public function deleteSubtree($withSelf = false, $forceDelete = false) * @param array $models * @return \Illuminate\Database\Eloquent\Collection */ - public function newCollection(array $models = array()) + public function newCollection(array $models = []) { return new Collection($models); }