public function addChild(self $node)
    {
        $cardinalityMap = $this->getCardinalityMap();
        $nodeType = $node->getNodeType();

        // if proposed child node is of an invalid type
        if (!isset($cardinalityMap[$nodeType])) {
            throw new OutOfBoundsException(sprintf(
                'QueryBuilder node "%s" of type "%s" cannot be appended to "%s". '.
                'Must be one type of "%s"',
                $node->getName(),
                $nodeType,
                $this->getName(),
                implode(', ', array_keys($cardinalityMap))
            ));
        }

        $currentCardinality = isset($this->children[$node->getName()]) ?
            count($this->children[$node->getName()]) : 0;

        list($min, $max) = $cardinalityMap[$nodeType];

        // if bounded and cardinality will exceed max
        if (null !== $max && $currentCardinality + 1 > $max) {
            throw new OutOfBoundsException(sprintf(
                'QueryBuilder node "%s" cannot be appended to "%s". '.
                'Number of "%s" nodes cannot exceed "%s"',
                $node->getName(),
                $this->getName(),
                $nodeType,
                $max
            ));
        }

        $this->children[$nodeType][] = $node;

        return $node->getNext();
    }
public function addChild(self $node)
    {
        $cardinalityMap = $this->getCardinalityMap();
        $nodeType = $node->getNodeType();

        // if proposed child node is of an invalid type
        if (!isset($cardinalityMap[$nodeType])) {
            throw new OutOfBoundsException(sprintf(
                'QueryBuilder node "%s" of type "%s" cannot be appended to "%s". '.
                'Must be one type of "%s"',
                $node->getName(),
                $nodeType,
                $this->getName(),
                implode(', ', array_keys($cardinalityMap))
            ));
        }

        $currentCardinality = isset($this->children[$node->getName()]) ?
            count($this->children[$node->getName()]) : 0;

        list($min, $max) = $cardinalityMap[$nodeType];

        // if bounded and cardinality will exceed max
        if (null !== $max && $currentCardinality + 1 > $max) {
            throw new OutOfBoundsException(sprintf(
                'QueryBuilder node "%s" cannot be appended to "%s". '.
                'Number of "%s" nodes cannot exceed "%s"',
                $node->getName(),
                $this->getName(),
                $nodeType,
                $max
            ));
        }

        $this->children[$nodeType][] = $node;

        return $node->getNext();
    }
public function addChild ( self $ node ) { $ cardinalityMap = $ this -> getCardinalityMap ( ) ; $ nodeType = $ node -> getNodeType ( ) ; // if proposed child node is of an invalid type if ( ! isset ( $ cardinalityMap [ $ nodeType ] ) ) { throw new OutOfBoundsException ( sprintf ( 'QueryBuilder node "%s" of type "%s" cannot be appended to "%s". ' . 'Must be one type of "%s"' , $ node -> getName ( ) , $ nodeType , $ this -> getName ( ) , implode ( ', ' , array_keys ( $ cardinalityMap ) ) ) ) ; } $ currentCardinality = isset ( $ this -> children [ $ node -> getName ( ) ] ) ? count ( $ this -> children [ $ node -> getName ( ) ] ) : 0 ; list ( $ min , $ max ) = $ cardinalityMap [ $ nodeType ] ; // if bounded and cardinality will exceed max if ( null !== $ max && $ currentCardinality + 1 > $ max ) { throw new OutOfBoundsException ( sprintf ( 'QueryBuilder node "%s" cannot be appended to "%s". ' . 'Number of "%s" nodes cannot exceed "%s"' , $ node -> getName ( ) , $ this -> getName ( ) , $ nodeType , $ max ) ) ; } $ this -> children [ $ nodeType ] [ ] = $ node ; return $ node -> getNext ( ) ; }
Add a child to this node.

Exception will be thrown if child node type is not
described in the cardinality map, or if the maxiumum
permitted number of nodes would be exceeded by adding
the given child node.

The given node will be returned EXCEPT when the current
node is a leaf node, in which case we return the parent.

@throws OutOfBoundsException

@return AbstractNode
Add a child to this node .