Returns the first child of node if exists.

@param  \BackBee\NestedNode\AbstractNestedNode $node
@return \BackBee\NestedNode\AbstractNestedNode|NULL
163712
public function getLastChild(AbstractNestedNode $node)
    {
        $children = $this->getDescendants($node, 1);
        if (0 < count($children)) {
            return $children[count($children) - 1];
        }

        return;
    }
535327
public function getFirstChild()
	{
		if ( ! $this->hasChildren()) {
			return null;
		}
		$left = $this->getLeftValue() + 1;

		$searchCondition = $this->repository->createSearchCondition();
		$searchCondition->leftEqualsTo($left);

		$firstChild = $this->repository->search($searchCondition);
		if ( ! isset($firstChild[0])) {
			$dump = static::dump($this);
			throw new Exception\InvalidStructure("Could not find the first child of {$dump} but it must exist");
		}
		$firstChild = $firstChild[0];
		
		return $firstChild;
	}
564205
public function getFirstChild(Branch $branch = null)
    {
        if (null === $branch) {
            return null;
        }

        //reset return first child or false if is not found
        $children = $branch->getChildren();
        $first = reset($children);

        return $first ? $first : null;
    }
534210
public function getAncestor(AbstractNestedNode $node, $level = 0)
    {
        if ($node->getLevel() < $level) {
            return;
        }

        if ($node->getLevel() == $level) {
            return $node;
        }

        try {
            return $this->createQueryBuilder('n')
                            ->andIsAncestorOf($node, false, $level)
                            ->getQuery()
                            ->getSingleResult();
        } catch (\Exception $e) {
            return;
        }
    }
1135783
public function getFirstChildNode(...$classNames) {
        foreach ($this::CHILD_NAMES as $name) {
            $val = $this->$name;
            foreach ($classNames as $className) {
                if (\is_array($val)) {
                    foreach ($val as $child) {
                        if ($child instanceof $className) {
                            return $child;
                        }
                    }
                    continue;
                } elseif ($val instanceof $className) {
                    return $val;
                }
            }
        }
        return null;
    }
776196
public function firstChild()
    {
        reset($this->children);
        $key = key($this->children);

        return $this->getChild($key);
    }
1227643
private function getFirstChild(\DOMDocument $document)
    {
        foreach ($document->childNodes as $child) {
            if ($child instanceof \DOMElement) {
                return $child;
                // @codeCoverageIgnoreStart
            }
        }

        return false;
        // @codeCoverageIgnoreEnd
    }
290111
protected function getDocBlock(AbstractNode $node): ?DocBlock
    {
        $comment = $node->getComment();

        if ($comment === null) {
            return null;
        }

        return $this->docBlockFactory->create($comment);
    }
301014
private function getPrimitiveValue(Node $node) {
		if ($this->isBool($node)) {
			return (bool) $this->getExpression($node);
		}
	
		if ($this->isNull($node)) {
			return null;
		}
	
		return $node->value;
	}
294086
public function getValueForNode(Node $node)
    {
        if ($node->isNamed()) {
            return $node->getUri();
        } elseif ($node->isLiteral()) {
            return $node->getValue();
        } elseif ($node->isBlank()) {
            return $node->getBlankId();
        } else {
            return null;
        }
    }
1077722
public static function getChildElements($node)
    {
        $ret = array();
        $nodes = $node->childNodes;
        foreach ($nodes as $node) {
            if ($node instanceof DOMElement) {
                array_push($ret, $node);
            }
        }
        return $ret;
    }
1057485
public function lastChild(): AbstractNode
    {
        if (count($this->children) == 0) {
            // no children
            throw new ChildNotFoundException("No children found in node.");
        }

        end($this->children);
        $key = key($this->children);

        return $this->getChild($key);
    }
782606
public function getParent(Node $node)
    {
        $this->init();
        if ($node->getParent() && array_key_exists(
                $node->getParent()->getId(),
                $this->allNodes
            )
        ) {
            return $this->allNodes[$node->getParent()->getId()];
        }

        return false;
    }
1229113
protected static function DOMNodeChildCount(DOMNode $node)
    {
        $count = 0;

        if ($node->hasChildNodes()) {
            foreach ($node->childNodes as $child) {
                if ($child->nodeType == XML_ELEMENT_NODE) {
                    $count++;
                }
            }
        }

        return $count;
    }
643118
private function getNodeValue( $domNode )
	{
		if( !( $domNode->nodeType == 1 && $domNode->childNodes->length > 0 ) )
			return NULL;
		return $domNode->childNodes->item(0)->nodeValue;
	}
1005676
public static function getFirstElementByTagName($node, $subnode_name)
    {
        $nodes = $node->getElementsByTagName($subnode_name);
        if ($nodes->length > 0)
        {
            return $nodes->item(0);
        }
        else
        {
            return null;
        }
    }
1029496
protected function refreshExistingNode(AbstractNestedNode $node)
    {
        if (true === $this->_em->contains($node)) {
            $this->_em->refresh($node);
        } elseif (null === $node = $this->find($node->getUid())) {
            $this->_em->persist($node);
        }

        return $this;
    }