Verifies that inline control statements are not present.
Author: Greg Sherwood (gsherwood@squiz.net)
Author: Marc McIntyre (mmcintyre@squiz.net)
Inheritance: implements PHP_CodeSniffer_Sniff
コード例 #1
0
 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param int $stackPtr The position of the current token in the
  *                                        stack passed in $tokens.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     if ($tokens[$stackPtr]['code'] === T_IF) {
         $openParenthesis = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr + 1, null);
         $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer'];
         $nextToken = $phpcsFile->findNext(T_WHITESPACE, $closeParenthesis + 1, null, true);
         if (in_array($tokens[$nextToken]['code'], array(T_RETURN, T_BREAK, T_CONTINUE, T_THROW, T_STRING, T_VARIABLE, T_UNSET), true)) {
             return;
         }
     }
     parent::process($phpcsFile, $stackPtr);
 }
コード例 #2
0
 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param int                  $stackPtr  The position of the current token in
  *                                        the stack passed in $tokens.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     // Check for the alternate syntax for control structures with colons (:).
     if (isset($tokens[$stackPtr]['parenthesis_closer'])) {
         $start = $tokens[$stackPtr]['parenthesis_closer'];
     } else {
         $start = $stackPtr;
     }
     $scopeOpener = $phpcsFile->findNext(T_WHITESPACE, $start + 1, null, true);
     if ($tokens[$scopeOpener]['code'] === T_COLON) {
         return;
     }
     parent::process($phpcsFile, $stackPtr);
 }
コード例 #3
0
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     // Lines which will be ignored (without whitespaces)
     $ignoreLines = array("if(!defined('sugarEntry'))define('sugarEntry',true);" => true);
     $tokens = $phpcsFile->getTokens();
     $codeStr = '';
     for ($i = $stackPtr; $i < $phpcsFile->numTokens; $i++) {
         if ($tokens[$i]['line'] == $tokens[$stackPtr]['line']) {
             if ($tokens[$i]['code'] !== T_WHITESPACE) {
                 $codeStr .= $tokens[$i]['content'];
             }
         } else {
             break;
         }
     }
     if (!isset($ignoreLines[$codeStr])) {
         parent::process($phpcsFile, $stackPtr);
     }
 }