Superbrave/Sniffs/Commenting/FunctionCommentSniff.php
protected function processReturnAboveThrows(File $phpcsFile, $stackPtr)
    {
        // Fetches the full function docblock
        $startToken = null;
        $endToken = null;
        $docblock = $this->getDocBlock($phpcsFile, $stackPtr, $startToken, $endToken);
        if ($this->hasInheritDoc($phpcsFile, $stackPtr, $docblock)) {
            return;
        }

        // Fetches tag locations
        $return_pos = strpos($docblock, '@return');
        $throws_pos = strpos($docblock, '@throws');

        // One of the elements doesn't exist
        if ($throws_pos === false || $return_pos === false) {
            return;
        }

        // Is the throws above return?
        if ($return_pos > $throws_pos) {
            $error = '@throws tags should be below the @return tag, not above the @return tag';
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'ReturnAboveThrows');

            // When the patcher is active, fix the issue
            if ($fix === true) {
                // Breaks up the docblock in three parts; original docblock, return and throws
                $parts = explode('* @', $docblock);
                $general = $return = $throws = array();
                foreach ($parts as $part) {
                    if (strtolower(substr($part, 0, 6)) == 'return') {
                        array_push($return, $part);
                    } else if (strtolower(substr($part, 0, 6)) == 'throws') {
                        array_push($throws, $part);
                    } else {
                        array_push($general, $part);
                    }
                }

                // Reglues the three parts in correct sequence
                $newDocblock = implode('* @', array_merge(
                    $general,
                    $return,
                    $throws
                ));

                // Patches the file
                $phpcsFile->fixer->beginChangeset();
                $phpcsFile->fixer->replaceToken($startToken, $newDocblock);
                for ($token = $startToken + 1; $token < $endToken; ++$token) {
                    $phpcsFile->fixer->replaceToken($token, "");
                }
                $phpcsFile->fixer->endChangeset();
            }
        }
    }
protected function processReturnAboveThrows(File $phpcsFile, $stackPtr)
    {
        // Fetches the full function docblock
        $startToken = null;
        $endToken = null;
        $docblock = $this->getDocBlock($phpcsFile, $stackPtr, $startToken, $endToken);
        if ($this->hasInheritDoc($phpcsFile, $stackPtr, $docblock)) {
            return;
        }

        // Fetches tag locations
        $return_pos = strpos($docblock, '@return');
        $throws_pos = strpos($docblock, '@throws');

        // One of the elements doesn't exist
        if ($throws_pos === false || $return_pos === false) {
            return;
        }

        // Is the throws above return?
        if ($return_pos > $throws_pos) {
            $error = '@throws tags should be below the @return tag, not above the @return tag';
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'ReturnAboveThrows');

            // When the patcher is active, fix the issue
            if ($fix === true) {
                // Breaks up the docblock in three parts; original docblock, return and throws
                $parts = explode('* @', $docblock);
                $general = $return = $throws = array();
                foreach ($parts as $part) {
                    if (strtolower(substr($part, 0, 6)) == 'return') {
                        array_push($return, $part);
                    } else if (strtolower(substr($part, 0, 6)) == 'throws') {
                        array_push($throws, $part);
                    } else {
                        array_push($general, $part);
                    }
                }

                // Reglues the three parts in correct sequence
                $newDocblock = implode('* @', array_merge(
                    $general,
                    $return,
                    $throws
                ));

                // Patches the file
                $phpcsFile->fixer->beginChangeset();
                $phpcsFile->fixer->replaceToken($startToken, $newDocblock);
                for ($token = $startToken + 1; $token < $endToken; ++$token) {
                    $phpcsFile->fixer->replaceToken($token, "");
                }
                $phpcsFile->fixer->endChangeset();
            }
        }
    }
protected function processReturnAboveThrows ( File $ phpcsFile , $ stackPtr ) { // Fetches the full function docblock $ startToken = null ; $ endToken = null ; $ docblock = $ this -> getDocBlock ( $ phpcsFile , $ stackPtr , $ startToken , $ endToken ) ; if ( $ this -> hasInheritDoc ( $ phpcsFile , $ stackPtr , $ docblock ) ) { return ; } // Fetches tag locations $ return_pos = strpos ( $ docblock , '@return' ) ; $ throws_pos = strpos ( $ docblock , '@throws' ) ; // One of the elements doesn't exist if ( $ throws_pos === false || $ return_pos === false ) { return ; } // Is the throws above return? if ( $ return_pos > $ throws_pos ) { $ error = '@throws tags should be below the @return tag, not above the @return tag' ; $ fix = $ phpcsFile -> addFixableError ( $ error , $ stackPtr , 'ReturnAboveThrows' ) ; // When the patcher is active, fix the issue if ( $ fix === true ) { // Breaks up the docblock in three parts; original docblock, return and throws $ parts = explode ( '* @' , $ docblock ) ; $ general = $ return = $ throws = array ( ) ; foreach ( $ parts as $ part ) { if ( strtolower ( substr ( $ part , 0 , 6 ) ) == 'return' ) { array_push ( $ return , $ part ) ; } else if ( strtolower ( substr ( $ part , 0 , 6 ) ) == 'throws' ) { array_push ( $ throws , $ part ) ; } else { array_push ( $ general , $ part ) ; } } // Reglues the three parts in correct sequence $ newDocblock = implode ( '* @' , array_merge ( $ general , $ return , $ throws ) ) ; // Patches the file $ phpcsFile -> fixer -> beginChangeset ( ) ; $ phpcsFile -> fixer -> replaceToken ( $ startToken , $ newDocblock ) ; for ( $ token = $ startToken + 1 ; $ token < $ endToken ; ++ $ token ) { $ phpcsFile -> fixer -> replaceToken ( $ token , "" ) ; } $ phpcsFile -> fixer -> endChangeset ( ) ; } } }
A throws call must be below the return call.

The Superbrave standards follows the "Symfony Way" in this sniff.

@param File $phpcsFile    The file being scanned.
@param int  $stackPtr     The position of the current token in the stack passed in $tokens.

@return void
A throws call must be below the return call .