private function fixParent(Tokens $tokens, $classStart, $classEnd)
    {
        // check calls to the parent constructor
        foreach ($tokens->findGivenKind(T_EXTENDS) as $index => $token) {
            $parentIndex = $tokens->getNextMeaningfulToken($index);
            $parentClass = $tokens[$parentIndex]->getContent();

            // using parent::ParentClassName() or ParentClassName::ParentClassName()
            $parentSeq = $tokens->findSequence([
                [T_STRING],
                [T_DOUBLE_COLON],
                [T_STRING, $parentClass],
                '(',
            ], $classStart, $classEnd, [2 => false]);

            if (null !== $parentSeq) {
                // we only need indexes
                $parentSeq = array_keys($parentSeq);

                // match either of the possibilities
                if ($tokens[$parentSeq[0]]->equalsAny([[T_STRING, 'parent'], [T_STRING, $parentClass]], false)) {
                    // replace with parent::__construct
                    $tokens[$parentSeq[0]] = new Token([T_STRING, 'parent']);
                    $tokens[$parentSeq[2]] = new Token([T_STRING, '__construct']);
                }
            }

            // using $this->ParentClassName()
            $parentSeq = $tokens->findSequence([
                [T_VARIABLE, '$this'],
                [T_OBJECT_OPERATOR],
                [T_STRING, $parentClass],
                '(',
            ], $classStart, $classEnd, [2 => false]);

            if (null !== $parentSeq) {
                // we only need indexes
                $parentSeq = array_keys($parentSeq);

                // replace call with parent::__construct()
                $tokens[$parentSeq[0]] = new Token([
                    T_STRING,
                    'parent',
                ]);
                $tokens[$parentSeq[1]] = new Token([
                    T_DOUBLE_COLON,
                    '::',
                ]);
                $tokens[$parentSeq[2]] = new Token([T_STRING, '__construct']);
            }
        }
    }
private function fixParent(Tokens $tokens, $classStart, $classEnd)
    {
        
        foreach ($tokens->findGivenKind(T_EXTENDS) as $index => $token) {
            $parentIndex = $tokens->getNextMeaningfulToken($index);
            $parentClass = $tokens[$parentIndex]->getContent();

            
            $parentSeq = $tokens->findSequence([
                [T_STRING],
                [T_DOUBLE_COLON],
                [T_STRING, $parentClass],
                '(',
            ], $classStart, $classEnd, [2 => false]);

            if (null !== $parentSeq) {
                
                $parentSeq = array_keys($parentSeq);

                
                if ($tokens[$parentSeq[0]]->equalsAny([[T_STRING, 'parent'], [T_STRING, $parentClass]], false)) {
                    
                    $tokens[$parentSeq[0]] = new Token([T_STRING, 'parent']);
                    $tokens[$parentSeq[2]] = new Token([T_STRING, '__construct']);
                }
            }

            
            $parentSeq = $tokens->findSequence([
                [T_VARIABLE, '$this'],
                [T_OBJECT_OPERATOR],
                [T_STRING, $parentClass],
                '(',
            ], $classStart, $classEnd, [2 => false]);

            if (null !== $parentSeq) {
                
                $parentSeq = array_keys($parentSeq);

                
                $tokens[$parentSeq[0]] = new Token([
                    T_STRING,
                    'parent',
                ]);
                $tokens[$parentSeq[1]] = new Token([
                    T_DOUBLE_COLON,
                    '::',
                ]);
                $tokens[$parentSeq[2]] = new Token([T_STRING, '__construct']);
            }
        }
    }
private function fixParent ( Tokens $ tokens , $ classStart , $ classEnd ) { // check calls to the parent constructor foreach ( $ tokens -> findGivenKind ( T_EXTENDS ) as $ index => $ token ) { $ parentIndex = $ tokens -> getNextMeaningfulToken ( $ index ) ; $ parentClass = $ tokens [ $ parentIndex ] -> getContent ( ) ; // using parent::ParentClassName() or ParentClassName::ParentClassName() $ parentSeq = $ tokens -> findSequence ( [ [ T_STRING ] , [ T_DOUBLE_COLON ] , [ T_STRING , $ parentClass ] , '(' , ] , $ classStart , $ classEnd , [ 2 => false ] ) ; if ( null !== $ parentSeq ) { // we only need indexes $ parentSeq = array_keys ( $ parentSeq ) ; // match either of the possibilities if ( $ tokens [ $ parentSeq [ 0 ] ] -> equalsAny ( [ [ T_STRING , 'parent' ] , [ T_STRING , $ parentClass ] ] , false ) ) { // replace with parent::__construct $ tokens [ $ parentSeq [ 0 ] ] = new Token ( [ T_STRING , 'parent' ] ) ; $ tokens [ $ parentSeq [ 2 ] ] = new Token ( [ T_STRING , '__construct' ] ) ; } } // using $this->ParentClassName() $ parentSeq = $ tokens -> findSequence ( [ [ T_VARIABLE , '$this' ] , [ T_OBJECT_OPERATOR ] , [ T_STRING , $ parentClass ] , '(' , ] , $ classStart , $ classEnd , [ 2 => false ] ) ; if ( null !== $ parentSeq ) { // we only need indexes $ parentSeq = array_keys ( $ parentSeq ) ; // replace call with parent::__construct() $ tokens [ $ parentSeq [ 0 ] ] = new Token ( [ T_STRING , 'parent' , ] ) ; $ tokens [ $ parentSeq [ 1 ] ] = new Token ( [ T_DOUBLE_COLON , '::' , ] ) ; $ tokens [ $ parentSeq [ 2 ] ] = new Token ( [ T_STRING , '__construct' ] ) ; } } }
Fix calls to the parent constructor within a class.

@param Tokens $tokens     the Tokens instance
@param int    $classStart the class start index
@param int    $classEnd   the class end index
Fix calls to the parent constructor within a class .