/**
  * Process the return comment of this function comment.
  *
  * @param PHP_CodeSniffer_File $phpcsFile    The file being scanned.
  * @param int                  $stackPtr     The position of the current token
  *                                           in the stack passed in $tokens.
  * @param int                  $commentStart The position in the stack where the comment started.
  *
  * @return void
  */
 protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart)
 {
     if ($this->isInheritDoc($phpcsFile, $stackPtr)) {
         return;
     }
     $tokens = $phpcsFile->getTokens();
     // Only check for a return comment if a non-void return statement exists
     if (isset($tokens[$stackPtr]['scope_opener'])) {
         // Start inside the function
         $start = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $stackPtr, $tokens[$stackPtr]['scope_closer']);
         for ($i = $start; $i < $tokens[$stackPtr]['scope_closer']; ++$i) {
             // Skip closures
             if ($tokens[$i]['code'] === T_CLOSURE) {
                 $i = $tokens[$i]['scope_closer'];
                 continue;
             }
             // Found a return not in a closure statement
             // Run the check on the first which is not only 'return;'
             if ($tokens[$i]['code'] === T_RETURN && $this->isMatchingReturn($tokens, $i)) {
                 parent::processReturn($phpcsFile, $stackPtr, $commentStart);
                 break;
             }
         }
     }
 }
 /**
  * Process the return comment of this function comment.
  *
  * @param int $commentStart The position in the stack where the comment started.
  * @param int $commentEnd   The position in the stack where the comment ended.
  *
  * @return void
  */
 protected function processReturn($commentStart, $commentEnd)
 {
     $tokens = $this->currentFile->getTokens();
     $funcPtr = $this->currentFile->findNext(T_FUNCTION, $commentEnd);
     // Only check for a return comment if a non-void return statement exists
     if (isset($tokens[$funcPtr]['scope_opener'])) {
         $start = $tokens[$funcPtr]['scope_opener'];
         // iterate over all return statements of this function,
         // run the check on the first which is not only 'return;'
         while ($returnToken = $this->currentFile->findNext(T_RETURN, $start, $tokens[$funcPtr]['scope_closer'])) {
             if ($this->isMatchingReturn($tokens, $returnToken)) {
                 parent::processReturn($commentStart, $commentEnd);
                 break;
             }
             $start = $returnToken + 1;
         }
     }
 }
 /**
  * Process the return comment of this function comment.
  *
  * @param PHP_CodeSniffer_File $phpcsFile    The file being scanned.
  * @param int                  $stackPtr     The position of the current token
  *                                           in the stack passed in $tokens.
  * @param int                  $commentStart The position in the stack where the comment started.
  *
  * @return void
  */
 protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart)
 {
     if ($this->isInheritDoc($phpcsFile, $stackPtr)) {
         return;
     }
     $tokens = $phpcsFile->getTokens();
     // Only check for a return comment if a non-void return statement exists
     if (isset($tokens[$stackPtr]['scope_opener'])) {
         $start = $tokens[$stackPtr]['scope_opener'];
         // iterate over all return statements of this function,
         // run the check on the first which is not only 'return;'
         while ($returnToken = $phpcsFile->findNext(T_RETURN, $start, $tokens[$stackPtr]['scope_closer'])) {
             if ($this->isMatchingReturn($tokens, $returnToken) && !in_array('PHPCS_T_CLOSURE', $tokens[$returnToken]['conditions'])) {
                 parent::processReturn($phpcsFile, $stackPtr, $commentStart);
                 break;
             }
             $start = $returnToken + 1;
         }
     }
 }
예제 #4
0
 /**
  * Process the return comment of this function comment.
  *
  * @param PHP_CodeSniffer_File $phpcsFile    The file being scanned.
  * @param int                  $stackPtr     The position of the current token
  *                                           in the stack passed in $tokens.
  * @param int                  $commentStart The position in the stack where the comment started.
  *
  * @return void
  */
 protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart)
 {
     // Ignore functions without return type
     if (!$this->hasReturn) {
         return;
     }
     parent::processReturn($phpcsFile, $stackPtr, $commentStart);
 }