src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
private function compareTokensForSorting(array $leftToken, array $rightToken, array $tagCounts): int
    {
        $leftTagName = $leftToken['content'];
        $rightTagName = $rightToken['content'];
        $realLeftTagName = $this->getRealtagName($leftTagName);
        $realRightTagName = $this->getRealtagName($rightTagName);

        // If they have the same content, leave them, where they where ...
        $return = $leftToken['line'] > $rightToken['line'] ? 1 : -1;

        // But if they are different.
        if ($realLeftTagName !== $realRightTagName) {
            $leftTagCount = $tagCounts[$leftTagName];
            $rightTagCount = $tagCounts[$rightTagName];

            switch (true) {
                // Move return to bottom everytime ...
                case ($realLeftTagName === '@return'):
                    $return = 1;
                    break;

                // ... yes, everytime
                case ($realRightTagName === '@return'):
                    $return = -1;
                    break;

                // Move single items to the top.
                case ($leftTagCount !== $rightTagCount):
                    $return = $leftTagCount > $rightTagCount ? +1 : -1;
                    break;

                // Compare tag name
                default:
                    $return = strcasecmp($realLeftTagName, $realRightTagName) > 1 ? 1 : -1;
            }
        }

        return $return;
    }
private function compareTokensForSorting(array $leftToken, array $rightToken, array $tagCounts): int
    {
        $leftTagName = $leftToken['content'];
        $rightTagName = $rightToken['content'];
        $realLeftTagName = $this->getRealtagName($leftTagName);
        $realRightTagName = $this->getRealtagName($rightTagName);

        // If they have the same content, leave them, where they where ...
        $return = $leftToken['line'] > $rightToken['line'] ? 1 : -1;

        // But if they are different.
        if ($realLeftTagName !== $realRightTagName) {
            $leftTagCount = $tagCounts[$leftTagName];
            $rightTagCount = $tagCounts[$rightTagName];

            switch (true) {
                // Move return to bottom everytime ...
                case ($realLeftTagName === '@return'):
                    $return = 1;
                    break;

                // ... yes, everytime
                case ($realRightTagName === '@return'):
                    $return = -1;
                    break;

                // Move single items to the top.
                case ($leftTagCount !== $rightTagCount):
                    $return = $leftTagCount > $rightTagCount ? +1 : -1;
                    break;

                // Compare tag name
                default:
                    $return = strcasecmp($realLeftTagName, $realRightTagName) > 1 ? 1 : -1;
            }
        }

        return $return;
    }
private function compareTokensForSorting ( array $ leftToken , array $ rightToken , array $ tagCounts ) : int { $ leftTagName = $ leftToken [ 'content' ] ; $ rightTagName = $ rightToken [ 'content' ] ; $ realLeftTagName = $ this -> getRealtagName ( $ leftTagName ) ; $ realRightTagName = $ this -> getRealtagName ( $ rightTagName ) ; // If they have the same content, leave them, where they where ... $ return = $ leftToken [ 'line' ] > $ rightToken [ 'line' ] ? 1 : - 1 ; // But if they are different. if ( $ realLeftTagName !== $ realRightTagName ) { $ leftTagCount = $ tagCounts [ $ leftTagName ] ; $ rightTagCount = $ tagCounts [ $ rightTagName ] ; switch ( true ) { // Move return to bottom everytime ... case ( $ realLeftTagName === '@return' ) : $ return = 1 ; break ; // ... yes, everytime case ( $ realRightTagName === '@return' ) : $ return = - 1 ; break ; // Move single items to the top. case ( $ leftTagCount !== $ rightTagCount ) : $ return = $ leftTagCount > $ rightTagCount ? + 1 : - 1 ; break ; // Compare tag name default : $ return = strcasecmp ( $ realLeftTagName , $ realRightTagName ) > 1 ? 1 : - 1 ; } } return $ return ; }
The callback to sort tokens.

1. @return goes to the bottom
2. Single tags are group alphabetically in the top group.
3. Groups are sorted then by occurrence, that the largest group is the last one before the return.
4. Same annotations are kept in the order of their code.

@param array $leftToken Provided by usort.
@param array $rightToken Provided by usort.
@param array $tagCounts Saves the occurence count for every tag.

@return int
The callback to sort tokens .