src/Fixer/PhpUnit/PhpUnitOrderedCoversFixer.php
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
    {
        for ($index = $tokens->count() - 1; $index > 0; --$index) {
            if (!$tokens[$index]->isGivenKind(T_DOC_COMMENT) || 0 === Preg::match('/@covers\s.+@covers\s/s', $tokens[$index]->getContent())) {
                continue;
            }

            $docBlock = new DocBlock($tokens[$index]->getContent());
            $covers = $docBlock->getAnnotationsOfType('covers');

            $coversMap = [];
            foreach ($covers as $annotation) {
                $rawContent = $annotation->getContent();

                $comparableContent = Preg::replace('/\*\s*@covers\s+(.+)/', '\1', strtolower(trim($rawContent)));
                $coversMap[$comparableContent] = $rawContent;
            }
            $orderedCoversMap = $coversMap;
            ksort($orderedCoversMap, SORT_STRING);
            if ($orderedCoversMap === $coversMap) {
                continue;
            }

            $lines = $docBlock->getLines();
            foreach (array_reverse($covers) as $annotation) {
                array_splice(
                    $lines,
                    $annotation->getStart(),
                    $annotation->getEnd() - $annotation->getStart() + 1,
                    array_pop($orderedCoversMap)
                );
            }

            $tokens[$index] = new Token([T_DOC_COMMENT, implode('', $lines)]);
        }
    }
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
    {
        for ($index = $tokens->count() - 1; $index > 0; --$index) {
            if (!$tokens[$index]->isGivenKind(T_DOC_COMMENT) || 0 === Preg::match('/@covers\s.+@covers\s/s', $tokens[$index]->getContent())) {
                continue;
            }

            $docBlock = new DocBlock($tokens[$index]->getContent());
            $covers = $docBlock->getAnnotationsOfType('covers');

            $coversMap = [];
            foreach ($covers as $annotation) {
                $rawContent = $annotation->getContent();

                $comparableContent = Preg::replace('/\*\s*@covers\s+(.+)/', '\1', strtolower(trim($rawContent)));
                $coversMap[$comparableContent] = $rawContent;
            }
            $orderedCoversMap = $coversMap;
            ksort($orderedCoversMap, SORT_STRING);
            if ($orderedCoversMap === $coversMap) {
                continue;
            }

            $lines = $docBlock->getLines();
            foreach (array_reverse($covers) as $annotation) {
                array_splice(
                    $lines,
                    $annotation->getStart(),
                    $annotation->getEnd() - $annotation->getStart() + 1,
                    array_pop($orderedCoversMap)
                );
            }

            $tokens[$index] = new Token([T_DOC_COMMENT, implode('', $lines)]);
        }
    }
protected function applyFix ( \ SplFileInfo $ file , Tokens $ tokens ) { for ( $ index = $ tokens -> count ( ) - 1 ; $ index > 0 ; -- $ index ) { if ( ! $ tokens [ $ index ] -> isGivenKind ( T_DOC_COMMENT ) || 0 === Preg :: match ( '/@covers\s.+@covers\s/s' , $ tokens [ $ index ] -> getContent ( ) ) ) { continue ; } $ docBlock = new DocBlock ( $ tokens [ $ index ] -> getContent ( ) ) ; $ covers = $ docBlock -> getAnnotationsOfType ( 'covers' ) ; $ coversMap = [ ] ; foreach ( $ covers as $ annotation ) { $ rawContent = $ annotation -> getContent ( ) ; $ comparableContent = Preg :: replace ( '/\*\s*@covers\s+(.+)/' , '\1' , strtolower ( trim ( $ rawContent ) ) ) ; $ coversMap [ $ comparableContent ] = $ rawContent ; } $ orderedCoversMap = $ coversMap ; ksort ( $ orderedCoversMap , SORT_STRING ) ; if ( $ orderedCoversMap === $ coversMap ) { continue ; } $ lines = $ docBlock -> getLines ( ) ; foreach ( array_reverse ( $ covers ) as $ annotation ) { array_splice ( $ lines , $ annotation -> getStart ( ) , $ annotation -> getEnd ( ) - $ annotation -> getStart ( ) + 1 , array_pop ( $ orderedCoversMap ) ) ; } $ tokens [ $ index ] = new Token ( [ T_DOC_COMMENT , implode ( '' , $ lines ) ] ) ; } }
{@inheritdoc}
{