Make sure this Node is consistent

@throws NodalFlowException

@return $this
777576
protected function enforceIsATraversable()
    {
        if ($this->isFlow()) {
            if ($this->isATraversable) {
                throw new NodalFlowException('Cannot Traverse a Branch');
            }

            return $this;
        }

        if ($this->isATraversable) {
            if (!($this instanceof TraversableNodeInterface)) {
                throw new NodalFlowException('Cannot Traverse a Node that does not implement TraversableNodeInterface');
            }

            return $this;
        }

        if (!($this instanceof ExecNodeInterface)) {
            throw new NodalFlowException('Cannot Exec a Node that does not implement ExecNodeInterface');
        }

        return $this;
    }
879425
public function init($keepalive = false)
        {
            $this->handshake();
            $this->connect();

            if ($keepalive) {
                $this->keepAlive();
            } else {
                return $this;
            }
        }
727154
private function ensureCurrentElementState()
    {
        if ($this->reader->nodeType !== XMLReader::ELEMENT) {
            $this->moveToNextElementByName($this->name);
        } elseif ($this->name && $this->name !== $this->reader->name) {
            $this->moveToNextElementByName($this->name);
        }
    }
641614
protected function flowStart()
    {
        $this->flowMap->incrementFlow('num_exec')->flowStart();
        $this->listActiveEvent(!$this->hasParent())->triggerEvent(FlowEvent::FLOW_START);
        // flow started status kicks in after Event start to hint eventual children
        // this way, root flow is only running when a record hits a branch
        // and triggers a child flow flowStart() call
        $this->flowStatus = new FlowStatus(FlowStatus::FLOW_RUNNING);

        return $this;
    }
475465
public function commit()
    {
        if (!$this->nested || $this->depth == 1) {
            $this->db->connect()->getConnection()->commit();
        }

        $this->depth--;

        return $this;
    }
314563
public static function this()
    {
        if (is_object(static::$node)) {
            return static::$node;
        }
        //else...
        list($config) = array_merge(func_get_args(), [null]);
        return static::$node = new static($config);
    }
1271088
public function validate()
    {
        foreach ($this as $element) {

            if (
                $element instanceof ValidationAwareInterface ||
                $element instanceof ContainerInterface
            ) {
                $element->validate();
            }
        }
        return $this;
    }
478414
public function duplicate()
    {
        if (false === $this->is_duplicated) {
            $this->_duplicate();
            $this->is_duplicated = true;
            $this->node = parent::getNode();
        }
        return $this;
    }
574675
public function replace($nodeIdx, NodeInterface $node)
    {
        if (!isset($this->nodes[$nodeIdx])) {
            throw new NodalFlowException('Argument 1 should be a valid index in nodes', 1, null, [
                'nodeIdx' => $nodeIdx,
                'node'    => get_class($node),
            ]);
        }

        $node->setCarrier($this);
        $this->nodes[$nodeIdx] = $node;
        $this->flowMap->register($node, $nodeIdx, true);

        return $this;
    }
41684
private function makeFailStates(): self {
        $seeker   = new Seeker($this->check, $this->base, []);
        $this->traverseTreeForMakeFailCursor($this->tmp_tree, [], $seeker);
        return $this;
    }
6961
public function immutable()
    {
        $this->isImmutable = true;

        // Lock nested items.
        foreach ($this->getArrayCopy() as $item) {
            if ($item instanceof MultiValue) {
                $item->immutable();
            }
        }
        return $this;
    }
926831
public function beforeNodeCreate()
    {
        if (!$this->eventEmittingService->isEnabled()) {
            return;
        }

        /* @var $nodeEvent NodeEvent */
        $nodeEvent = $this->eventEmittingService->generate(self::NODE_ADDED, [], NodeEvent::class);
        $this->currentNodeAddEvents[] = $nodeEvent;
        $this->eventEmittingService->pushContext($nodeEvent);
    }
912185
public function commit()
    {
        if (!$this->nested || $this->depth <= 1) {
            parent::commit();
        } else {
            $this->depth--;
        }

        return $this;
    }
51250
public function refresh() : self {
      $newCode = $this->collection->assemble();
      $tokens = Helper::getTokensFromString($newCode);

      $this->collection->setItems($tokens);
      return $this;
    }
207887
public function sendTo($flowId, $nodeId = null, $param = null)
    {
        if (!($flow = $this->registry->getFlow($flowId))) {
            throw new NodalFlowException('Cannot sendTo without valid Flow target', 1, null, [
                'flowId' => $flowId,
                'nodeId' => $nodeId,
            ]);
        }

        return $flow->sendTo($nodeId, $param);
    }
835188
protected function processLastLogicalOperatorNode()
    {
        if (null !== $this->scope->getCurrentLeftNode()) {
            $this->addError('Logical operator must be followed by a valid operation.', self::ERROR_CODE_LOGICAL_OPERATOR_FOLLOWED);
        } elseif (null !== $this->scope->getLastOrNode()) {
            $node = new BooleanNode($this->scope->getLastOrNode(), $this->scope->getNode(), self::LOGICAL_OR);
            $this->scope->setNode($node);
        }

        return $this;
    }
1322595
protected function branchFlowCheck(FlowInterface $flow)
    {
        if (
            // this flow has parent already
            $flow->hasParent() ||
            // adding root flow in itself
            $this->getRootFlow($flow)->getId() === $this->getRootFlow($this)->getId()
        ) {
            throw new NodalFlowException('Cannot reuse Flow within Branches', 1, null, [
                'flowId'             => $this->getId(),
                'BranchFlowId'       => $flow->getId(),
                'BranchFlowParentId' => $flow->hasParent() ? $flow->getParent()->getId() : null,
            ]);
        }
    }