src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
    {
        $namespaceUseAnalyzer = new NamespaceUsesAnalyzer();

        $shortNames = [];
        foreach ($namespaceUseAnalyzer->getDeclarationsFromTokens($tokens) as $namespaceUseAnalysis) {
            $shortNames[strtolower($namespaceUseAnalysis->getShortName())] = '\\'.strtolower($namespaceUseAnalysis->getFullName());
        }

        foreach ($tokens as $index => $token) {
            if (!$token->isGivenKind(T_DOC_COMMENT)) {
                continue;
            }

            $functionIndex = $this->findDocumentedFunction($tokens, $index);
            if (null === $functionIndex) {
                continue;
            }

            $docBlock = new DocBlock($token->getContent());

            $openingParenthesisIndex = $tokens->getNextTokenOfKind($functionIndex, ['(']);
            $closingParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openingParenthesisIndex);

            $argumentsInfo = $this->getArgumentsInfo(
                $tokens,
                $openingParenthesisIndex + 1,
                $closingParenthesisIndex - 1
            );

            foreach ($docBlock->getAnnotationsOfType('param') as $annotation) {
                if (0 === Preg::match('/@param(?:\s+[^\$]\S+)?\s+(\$\S+)/', $annotation->getContent(), $matches)) {
                    continue;
                }

                $argumentName = $matches[1];

                if (
                    !isset($argumentsInfo[$argumentName])
                    || $this->annotationIsSuperfluous($annotation, $argumentsInfo[$argumentName], $shortNames)
                ) {
                    $annotation->remove();
                }
            }

            $returnTypeInfo = $this->getReturnTypeInfo($tokens, $closingParenthesisIndex);

            foreach ($docBlock->getAnnotationsOfType('return') as $annotation) {
                if ($this->annotationIsSuperfluous($annotation, $returnTypeInfo, $shortNames)) {
                    $annotation->remove();
                }
            }

            $tokens[$index] = new Token([T_DOC_COMMENT, $docBlock->getContent()]);
        }
    }
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
    {
        $namespaceUseAnalyzer = new NamespaceUsesAnalyzer();

        $shortNames = [];
        foreach ($namespaceUseAnalyzer->getDeclarationsFromTokens($tokens) as $namespaceUseAnalysis) {
            $shortNames[strtolower($namespaceUseAnalysis->getShortName())] = '\\'.strtolower($namespaceUseAnalysis->getFullName());
        }

        foreach ($tokens as $index => $token) {
            if (!$token->isGivenKind(T_DOC_COMMENT)) {
                continue;
            }

            $functionIndex = $this->findDocumentedFunction($tokens, $index);
            if (null === $functionIndex) {
                continue;
            }

            $docBlock = new DocBlock($token->getContent());

            $openingParenthesisIndex = $tokens->getNextTokenOfKind($functionIndex, ['(']);
            $closingParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openingParenthesisIndex);

            $argumentsInfo = $this->getArgumentsInfo(
                $tokens,
                $openingParenthesisIndex + 1,
                $closingParenthesisIndex - 1
            );

            foreach ($docBlock->getAnnotationsOfType('param') as $annotation) {
                if (0 === Preg::match('/@param(?:\s+[^\$]\S+)?\s+(\$\S+)/', $annotation->getContent(), $matches)) {
                    continue;
                }

                $argumentName = $matches[1];

                if (
                    !isset($argumentsInfo[$argumentName])
                    || $this->annotationIsSuperfluous($annotation, $argumentsInfo[$argumentName], $shortNames)
                ) {
                    $annotation->remove();
                }
            }

            $returnTypeInfo = $this->getReturnTypeInfo($tokens, $closingParenthesisIndex);

            foreach ($docBlock->getAnnotationsOfType('return') as $annotation) {
                if ($this->annotationIsSuperfluous($annotation, $returnTypeInfo, $shortNames)) {
                    $annotation->remove();
                }
            }

            $tokens[$index] = new Token([T_DOC_COMMENT, $docBlock->getContent()]);
        }
    }
protected function applyFix ( \ SplFileInfo $ file , Tokens $ tokens ) { $ namespaceUseAnalyzer = new NamespaceUsesAnalyzer ( ) ; $ shortNames = [ ] ; foreach ( $ namespaceUseAnalyzer -> getDeclarationsFromTokens ( $ tokens ) as $ namespaceUseAnalysis ) { $ shortNames [ strtolower ( $ namespaceUseAnalysis -> getShortName ( ) ) ] = '\\' . strtolower ( $ namespaceUseAnalysis -> getFullName ( ) ) ; } foreach ( $ tokens as $ index => $ token ) { if ( ! $ token -> isGivenKind ( T_DOC_COMMENT ) ) { continue ; } $ functionIndex = $ this -> findDocumentedFunction ( $ tokens , $ index ) ; if ( null === $ functionIndex ) { continue ; } $ docBlock = new DocBlock ( $ token -> getContent ( ) ) ; $ openingParenthesisIndex = $ tokens -> getNextTokenOfKind ( $ functionIndex , [ '(' ] ) ; $ closingParenthesisIndex = $ tokens -> findBlockEnd ( Tokens :: BLOCK_TYPE_PARENTHESIS_BRACE , $ openingParenthesisIndex ) ; $ argumentsInfo = $ this -> getArgumentsInfo ( $ tokens , $ openingParenthesisIndex + 1 , $ closingParenthesisIndex - 1 ) ; foreach ( $ docBlock -> getAnnotationsOfType ( 'param' ) as $ annotation ) { if ( 0 === Preg :: match ( '/@param(?:\s+[^\$]\S+)?\s+(\$\S+)/' , $ annotation -> getContent ( ) , $ matches ) ) { continue ; } $ argumentName = $ matches [ 1 ] ; if ( ! isset ( $ argumentsInfo [ $ argumentName ] ) || $ this -> annotationIsSuperfluous ( $ annotation , $ argumentsInfo [ $ argumentName ] , $ shortNames ) ) { $ annotation -> remove ( ) ; } } $ returnTypeInfo = $ this -> getReturnTypeInfo ( $ tokens , $ closingParenthesisIndex ) ; foreach ( $ docBlock -> getAnnotationsOfType ( 'return' ) as $ annotation ) { if ( $ this -> annotationIsSuperfluous ( $ annotation , $ returnTypeInfo , $ shortNames ) ) { $ annotation -> remove ( ) ; } } $ tokens [ $ index ] = new Token ( [ T_DOC_COMMENT , $ docBlock -> getContent ( ) ] ) ; } }
{@inheritdoc}
{