private function addNodeAfterProperties(Node $newNode)
    {
        $classNode = $this->getClassNode();

        // try to add after last property
        $targetNode = $this->findLastNode(function ($node) {
            return $node instanceof Node\Stmt\Property;
        }, [$classNode]);

        // otherwise, try to add after the last constant
        if (!$targetNode) {
            $targetNode = $this->findLastNode(function ($node) {
                return $node instanceof Node\Stmt\ClassConst;
            }, [$classNode]);
        }

        // add the new property after this node
        if ($targetNode) {
            $index = array_search($targetNode, $classNode->stmts);

            array_splice(
                $classNode->stmts,
                $index + 1,
                0,
                [$this->createBlankLineNode(self::CONTEXT_CLASS), $newNode]
            );

            $this->updateSourceCodeFromNewStmts();

            return;
        }

        // put right at the beginning of the class
        // add an empty line, unless the class is totally empty
        if (!empty($classNode->stmts)) {
            array_unshift($classNode->stmts, $this->createBlankLineNode(self::CONTEXT_CLASS));
        }
        array_unshift($classNode->stmts, $newNode);
        $this->updateSourceCodeFromNewStmts();
    }
private function addNodeAfterProperties(Node $newNode)
    {
        $classNode = $this->getClassNode();

        // try to add after last property
        $targetNode = $this->findLastNode(function ($node) {
            return $node instanceof Node\Stmt\Property;
        }, [$classNode]);

        // otherwise, try to add after the last constant
        if (!$targetNode) {
            $targetNode = $this->findLastNode(function ($node) {
                return $node instanceof Node\Stmt\ClassConst;
            }, [$classNode]);
        }

        // add the new property after this node
        if ($targetNode) {
            $index = array_search($targetNode, $classNode->stmts);

            array_splice(
                $classNode->stmts,
                $index + 1,
                0,
                [$this->createBlankLineNode(self::CONTEXT_CLASS), $newNode]
            );

            $this->updateSourceCodeFromNewStmts();

            return;
        }

        // put right at the beginning of the class
        // add an empty line, unless the class is totally empty
        if (!empty($classNode->stmts)) {
            array_unshift($classNode->stmts, $this->createBlankLineNode(self::CONTEXT_CLASS));
        }
        array_unshift($classNode->stmts, $newNode);
        $this->updateSourceCodeFromNewStmts();
    }
private function addNodeAfterProperties ( Node $ newNode ) { $ classNode = $ this -> getClassNode ( ) ; // try to add after last property $ targetNode = $ this -> findLastNode ( function ( $ node ) { return $ node instanceof Node \ Stmt \ Property ; } , [ $ classNode ] ) ; // otherwise, try to add after the last constant if ( ! $ targetNode ) { $ targetNode = $ this -> findLastNode ( function ( $ node ) { return $ node instanceof Node \ Stmt \ ClassConst ; } , [ $ classNode ] ) ; } // add the new property after this node if ( $ targetNode ) { $ index = array_search ( $ targetNode , $ classNode -> stmts ) ; array_splice ( $ classNode -> stmts , $ index + 1 , 0 , [ $ this -> createBlankLineNode ( self :: CONTEXT_CLASS ) , $ newNode ] ) ; $ this -> updateSourceCodeFromNewStmts ( ) ; return ; } // put right at the beginning of the class // add an empty line, unless the class is totally empty if ( ! empty ( $ classNode -> stmts ) ) { array_unshift ( $ classNode -> stmts , $ this -> createBlankLineNode ( self :: CONTEXT_CLASS ) ) ; } array_unshift ( $ classNode -> stmts , $ newNode ) ; $ this -> updateSourceCodeFromNewStmts ( ) ; }
Adds this new node where a new property should go.

Useful for adding properties, or adding a constructor.

@param Node $newNode
Adds this new node where a new property should go .