Baum\Move::guardAgainstImpossibleMove PHP Method

guardAgainstImpossibleMove() protected method

Check wether the current move is possible and if not, rais an exception.
protected guardAgainstImpossibleMove ( ) : void
return void
    protected function guardAgainstImpossibleMove()
    {
        if (!$this->node->exists) {
            throw new MoveNotPossibleException('A new node cannot be moved.');
        }
        if (array_search($this->position, ['child', 'left', 'right', 'root']) === false) {
            throw new MoveNotPossibleException("Position should be one of ['child', 'left', 'right'] but is {$this->position}.");
        }
        if (!$this->promotingToRoot()) {
            if (is_null($this->target)) {
                if ($this->position === 'left' || $this->position === 'right') {
                    throw new MoveNotPossibleException("Could not resolve target node. This node cannot move any further to the {$this->position}.");
                } else {
                    throw new MoveNotPossibleException('Could not resolve target node.');
                }
            }
            if ($this->node->equals($this->target)) {
                throw new MoveNotPossibleException('A node cannot be moved to itself.');
            }
            if ($this->target->insideSubtree($this->node)) {
                throw new MoveNotPossibleException('A node cannot be moved to a descendant of itself (inside moved tree).');
            }
            if (!$this->node->inSameScope($this->target)) {
                throw new MoveNotPossibleException('A node cannot be moved to a different scope.');
            }
        }
    }