当前位置: 首页>>代码示例>>PHP>>正文


PHP PHP_CodeSniffer_File::findNext方法代码示例

本文整理汇总了PHP中PHP_CodeSniffer_File::findNext方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer_File::findNext方法的具体用法?PHP PHP_CodeSniffer_File::findNext怎么用?PHP PHP_CodeSniffer_File::findNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHP_CodeSniffer_File的用法示例。


在下文中一共展示了PHP_CodeSniffer_File::findNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process

 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  * @param int                  $stackPtr  The position in the stack where
  *                                        the token was found.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $utils = Security_Sniffs_UtilsFactory::getInstance();
     $tokens = $phpcsFile->getTokens();
     if ($tokens[$stackPtr]['content'] == "'#value'" || $tokens[$stackPtr]['content'] == '"#value"') {
         $closer = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
         $next = $phpcsFile->findNext(array_merge(PHP_CodeSniffer_Tokens::$bracketTokens, PHP_CodeSniffer_Tokens::$emptyTokens, PHP_CodeSniffer_Tokens::$assignmentTokens), $stackPtr + 1, $closer + 1, true);
         if ($next == $closer && $tokens[$next]['code'] == T_SEMICOLON) {
             // Case of $label = $element['#value'];
             $next = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$assignmentTokens, $next);
             $next = $phpcsFile->findPrevious(T_VARIABLE, $next);
             $phpcsFile->addWarning('Potential XSS found with #value on ' . $tokens[$next]['content'], $next, 'D7XSSWarFormValue');
         } elseif ($next && $utils::is_token_user_input($tokens[$next])) {
             $phpcsFile->addError('XSS found with #value on ' . $tokens[$next]['content'], $next, 'D7XSSErrFormValue');
         } elseif ($next && PHP_CodeSniffer::getConfigData('ParanoiaMode')) {
             if (in_array($tokens[$next]['content'], $utils::getXSSMitigationFunctions())) {
                 $n = $phpcsFile->findNext($utils::getVariableTokens(), $next + 1, $closer);
                 if ($n) {
                     $phpcsFile->addWarning('Potential XSS found with #value on ' . $tokens[$n]['content'], $n, 'D7XSSWarFormValue');
                 }
             } else {
                 $phpcsFile->addWarning('Potential XSS found with #value on ' . $tokens[$next]['content'], $next, 'D7XSSWarFormValue');
             }
         }
     }
 }
开发者ID:valugi,项目名称:phpcs-security-audit,代码行数:35,代码来源:XSSFormValueSniff.php

示例2: process

 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  * @param int                  $stackPtr  The position in the stack where
  *                                        the token was found.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     // Find the content of each style definition name.
     $end = $tokens[$stackPtr]['bracket_closer'];
     $next = $phpcsFile->findNext(T_STYLE, $stackPtr + 1, $end);
     if ($next === false) {
         // Class definition is empty.
         return;
     }
     $styleNames = array();
     while ($next !== false) {
         $name = $tokens[$next]['content'];
         if (isset($styleNames[$name]) === true) {
             $first = $styleNames[$name];
             $error = 'Duplicate style definition found; first defined on line %s';
             $data = array($tokens[$first]['line']);
             $phpcsFile->addError($error, $next, 'Found', $data);
         } else {
             $styleNames[$name] = $next;
         }
         $next = $phpcsFile->findNext(T_STYLE, $next + 1, $end);
     }
     //end while
 }
开发者ID:eduardobenito10,项目名称:jenkins-php-quickstart,代码行数:34,代码来源:DuplicateStyleDefinitionSniff.php

示例3: process

 /**
  * 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 if the next non whitespace token is a string.
     $index = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
     if ($tokens[$index]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
         return;
     }
     // Make sure it is the only thing in the square brackets.
     $next = $phpcsFile->findNext(T_WHITESPACE, $index + 1, null, true);
     if ($tokens[$next]['code'] !== T_CLOSE_SQUARE_BRACKET) {
         return;
     }
     // Allow indexes that have dots in them because we can't write
     // them in dot notation.
     $content = trim($tokens[$index]['content'], '"\' ');
     if (strpos($content, '.') !== false) {
         return;
     }
     // Also ignore reserved words.
     if ($content === 'super') {
         return;
     }
     // Token before the opening square bracket cannot be a var name.
     $prev = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
     if ($tokens[$prev]['code'] === T_STRING) {
         $error = 'Object indexes must be written in dot notation';
         $phpcsFile->addError($error, $prev, 'Found');
     }
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:39,代码来源:DisallowObjectStringIndexSniff.php

示例4: process

 /**
  * 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 global input variable
     if (!in_array($tokens[$stackPtr]['content'], array('$_GET', '$_POST', '$_REQUEST'))) {
         return;
     }
     $varName = $tokens[$stackPtr]['content'];
     // If we're overriding a superglobal with an assignment, no need to test
     $semicolon_position = $phpcsFile->findNext(array(T_SEMICOLON), $stackPtr + 1, null, null, null, true);
     $assignment_position = $phpcsFile->findNext(array(T_EQUAL), $stackPtr + 1, null, null, null, true);
     if ($semicolon_position !== false && $assignment_position !== false && $assignment_position < $semicolon_position) {
         return;
     }
     // Check for whitelisting comment
     $currentLine = $tokens[$stackPtr]['line'];
     $nextPtr = $stackPtr;
     while (isset($tokens[$nextPtr + 1]['line']) && $tokens[$nextPtr + 1]['line'] == $currentLine) {
         $nextPtr++;
         // Do nothing, we just want the last token of the line
     }
     $is_whitelisted = $tokens[$nextPtr]['code'] === T_COMMENT && preg_match('#input var okay#i', $tokens[$nextPtr]['content']) > 0;
     if (!$is_whitelisted) {
         $phpcsFile->addWarning('Detected access of super global var %s, probably need manual inspection.', $stackPtr, null, array($varName));
     }
 }
开发者ID:chrux,项目名称:WordPress-Coding-Standards,代码行数:35,代码来源:SuperGlobalInputUsageSniff.php

示例5: process

 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  * @param int                  $stackPtr  The position in the stack where
  *                                        the token was found.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $utils = Security_Sniffs_UtilsFactory::getInstance();
     $tokens = $phpcsFile->getTokens();
     if ($tokens[$stackPtr]['content'] == 'preg_replace') {
         $s = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr);
         $closer = $tokens[$s]['parenthesis_closer'];
         $s = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $s + 1, $closer, true);
         if ($tokens[$s]['code'] == T_CONSTANT_ENCAPSED_STRING) {
             $pattern = $tokens[$s]['content'];
             if (substr($pattern, 1, 1) === '/') {
                 // $pattern is a regex
                 if (preg_match('/(\\/|\\))\\w*e\\w*"$/', $pattern)) {
                     $phpcsFile->addWarning("Usage of preg_replace with /e modifier is not recommended.", $stackPtr, 'PregReplaceE');
                     $s = $phpcsFile->findNext(array(T_COMMA, T_WHITESPACE, T_COMMENT, T_DOC_COMMENT), $s + 1, $closer, true);
                     if ($utils::is_token_user_input($tokens[$s])) {
                         $phpcsFile->addError("User input and /e modifier found in preg_replace, remote code execution possible.", $stackPtr, 'PregReplaceUserInputE');
                     }
                 }
             } else {
                 $phpcsFile->addWarning("Weird usage of preg_replace, please check manually for /e modifier.", $stackPtr, 'PregReplaceWeird');
             }
         } elseif ($tokens[$s]['code'] == T_VARIABLE && $utils::is_token_user_input($tokens[$s])) {
             $phpcsFile->addError("User input found in preg_replace, /e modifier could be used for malicious intent.", $stackPtr, 'PregReplaceUserInput');
         } else {
             $phpcsFile->addWarning("Dynamic usage of preg_replace, please check manually for /e modifier or user input.", $stackPtr, 'PregReplaceDyn');
         }
     }
 }
开发者ID:valugi,项目名称:phpcs-security-audit,代码行数:38,代码来源:PregReplaceSniff.php

示例6: isMultiLineCall

 /**
  * Processes single-line calls.
  *
  * @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                  $openBracket The position of the opening bracket
  *                                          in the stack passed in $tokens.
  * @param array                $tokens      The stack of tokens that make up
  *                                          the file.
  *
  * @return void
  */
 public function isMultiLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens)
 {
     // If the first argument is on a new line, this is a multi-line
     // function call, even if there is only one argument.
     $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $openBracket + 1, null, true);
     if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
         return true;
     }
     $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
     $end = $phpcsFile->findEndOfStatement($openBracket + 1);
     while ($tokens[$end]['code'] === T_COMMA) {
         // If the next bit of code is not on the same line, this is a
         // multi-line function call.
         $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $end + 1, $closeBracket, true);
         if ($next === false) {
             return false;
         }
         if ($tokens[$next]['line'] !== $tokens[$end]['line']) {
             return true;
         }
         $end = $phpcsFile->findEndOfStatement($next);
     }
     // We've reached the last argument, so see if the next content
     // (should be the close bracket) is also on the same line.
     $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $end + 1, $closeBracket, true);
     if ($next !== false && $tokens[$next]['line'] !== $tokens[$end]['line']) {
         return true;
     }
     return false;
 }
开发者ID:itliuchang,项目名称:test,代码行数:43,代码来源:FunctionCallSignatureSniff.php

示例7: process

 /**
  * 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_CASE && isset($tokens[$stackPtr]['scope_closer'])) {
         //			$internalCase = $phpcsFile->findNext(T_CASE, $stackPtr + 1, $tokens[$stackPtr]['scope_closer']);
         //			if ($internalCase !== false) {
         //				$comment = $phpcsFile->findNext(T_COMMENT, $stackPtr + 1, $internalCase - 1);
         //				if ($comment === false) {
         //					$phpcsFile->addError($this->getReqPrefix('REQ.PHP.2.5.12') . '"case" has not break and has not any comment', $stackPtr);
         //				}
         //			}
         $switch = $phpcsFile->findPrevious(T_SWITCH, $stackPtr - 1);
         if ($switch !== false) {
             $nextCase = $phpcsFile->findNext(array(T_CASE, T_DEFAULT), $stackPtr + 1, $tokens[$switch]['scope_closer']);
             if ($nextCase !== false) {
                 $prevBreak = $phpcsFile->findPrevious(T_BREAK, $nextCase - 1, $stackPtr);
                 if ($prevBreak !== false) {
                     $breakWS = $phpcsFile->findNext(T_WHITESPACE, $prevBreak + 1, $nextCase - 1);
                     if ($breakWS !== false) {
                         $str = $phpcsFile->getTokensAsString($breakWS, $nextCase - $breakWS - 1);
                         if (!preg_match("/^\n\n[ ]*\$/Ss", $str)) {
                             $breakWS = false;
                         }
                     }
                     if ($breakWS === false) {
                         $phpcsFile->addError($this->getReqPrefix('REQ.PHP.2.5.14') . '"case" must has empty line between current "case" and previous "break"', $stackPtr);
                     }
                 }
             }
         }
     } elseif ($tokens[$stackPtr]['code'] === T_DEFAULT) {
     }
 }
开发者ID:kingsj,项目名称:core,代码行数:42,代码来源:SwitchCaseControlStructureSniff.php

示例8: process

 /**
  * 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)
 {
     if ($this->supportsAbove('5.4')) {
         $tokens = $phpcsFile->getTokens();
         $nextSemicolonToken = $phpcsFile->findNext(T_SEMICOLON, $stackPtr, null, false);
         for ($curToken = $stackPtr + 1; $curToken < $nextSemicolonToken; $curToken++) {
             $gotError = false;
             if ($tokens[$curToken]['type'] == 'T_STRING') {
                 // If the next non-whitespace token after the string
                 // is an opening parenthesis then it's a function call.
                 $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $curToken + 1, null, true);
                 if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
                     continue;
                 } else {
                     $gotError = true;
                 }
             }
             switch ($tokens[$curToken]['type']) {
                 case 'T_VARIABLE':
                 case 'T_FUNCTION':
                     $gotError = true;
                     break;
             }
             if ($gotError === true) {
                 $error = 'Using a variable argument on break or continue is forbidden since PHP 5.4';
                 $phpcsFile->addError($error, $stackPtr);
             }
         }
     }
 }
开发者ID:christopheg,项目名称:PHPCompatibility,代码行数:39,代码来源:ForbiddenBreakContinueVariableArgumentsSniff.php

示例9: process

 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcs_file The file where the token was found.
  * @param int                  $stack_ptr  The position in the stack where the token was found.
  *
  * @return void
  */
 public function process(\PHP_CodeSniffer_File $phpcs_file, $stack_ptr)
 {
     // only check for use statements that are before the first class declaration
     // classes can have use statements for traits, for which we are not interested in this sniff
     $first_class_occurence = $phpcs_file->findPrevious([T_CLASS, T_TRAIT], $stack_ptr);
     if ($first_class_occurence > 0 && $stack_ptr > $first_class_occurence) {
         return;
     }
     $tokens = $phpcs_file->getTokens();
     // Reach the end of the current statement
     $stack_ptr = $phpcs_file->findNext([T_SEMICOLON], $stack_ptr + 1);
     $end_stmt = $stack_ptr;
     // if there is another 'use' statement, it should be at $stack_ptr + 1
     $next_use = $phpcs_file->findNext([T_USE], $stack_ptr + 1);
     $next_class = $phpcs_file->findNext([T_CLASS, T_TRAIT], $stack_ptr + 1);
     //There is a class and the next use statement is afte the class definition. skipp it
     if ($next_class && $next_use > $next_class) {
         return;
     }
     //Loop from the end of the use statement (;) untill the next use statement
     for ($i = $end_stmt + 1; $i <= $next_use; $i++) {
         //the current token ($i) contains an end of line
         //And it's on the next line than the end of the use satement
         if (stristr($tokens[$i]['content'], "\n") !== false && $tokens[$i]['line'] != $tokens[$end_stmt]['line']) {
             $this->checkForNewlineOrComments($phpcs_file, $i);
         }
     }
 }
开发者ID:hostnet,项目名称:phpcs-tool,代码行数:36,代码来源:NoVerticalWhitespaceBetweenUseStatementsSniff.php

示例10: process

 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  * @param int                  $stackPtr  The position in the stack where
  *                                        the token was found.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $utils = Security_Sniffs_UtilsFactory::getInstance();
     $tokens = $phpcsFile->getTokens();
     if (in_array($tokens[$stackPtr]['content'], $utils::getFilesystemFunctions())) {
         if ($tokens[$stackPtr]['content'] == 'symlink') {
             $phpcsFile->addWarning('Allowing symlink() while open_basedir is used is actually a security risk. Disabled by default in Suhosin >= 0.9.6', $stackPtr, 'WarnSymlink');
         }
         $s = $stackPtr + 1;
         $opener = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr, null, false, null, true);
         if (!$opener) {
             // No opener found, so it's probably not a function call
             if (PHP_CodeSniffer::getConfigData('ParanoiaMode')) {
                 $phpcsFile->addWarning('Filesystem function ' . $tokens[$stackPtr]['content'] . ' used but not as a function', $stackPtr, 'WarnWeirdFilesystem');
             }
             return;
         }
         $closer = $tokens[$opener]['parenthesis_closer'];
         $s = $phpcsFile->findNext(array_merge(PHP_CodeSniffer_Tokens::$emptyTokens, PHP_CodeSniffer_Tokens::$bracketTokens, Security_Sniffs_Utils::$staticTokens), $s, $closer, true);
         if ($s) {
             $msg = 'Filesystem function ' . $tokens[$stackPtr]['content'] . '() detected with dynamic parameter';
             if ($utils::is_token_user_input($tokens[$s])) {
                 $phpcsFile->addError($msg . ' directly from user input', $stackPtr, 'ErrFilesystem');
             } else {
                 $phpcsFile->addWarning($msg, $stackPtr, 'WarnFilesystem');
             }
         }
     }
 }
开发者ID:valugi,项目名称:phpcs-security-audit,代码行数:38,代码来源:FilesystemFunctionsSniff.php

示例11: process

 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  * @param int                  $stackPtr  The position in the stack where
  *                                        the token was found.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $next_var = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
     if ($next_var && $tokens[$next_var]["type"] == "T_STRING") {
         $name_var = $tokens[$next_var]["content"];
         $var_line = $tokens[$next_var]["line"];
         $next = $phpcsFile->findNext(T_WHITESPACE, $next_var + 1, null, true);
         $error = false;
         $only_one = "'Var' statement must contain only one variable";
         if ($tokens[$stackPtr]["line"] != $var_line) {
             $error = "'Var' statement must be on one line";
         } elseif ($tokens[$next]["type"] == "T_SEMICOLON") {
             $error = "Variable '{$name_var}' must be initialized";
         } elseif ($tokens[$next]["type"] == "T_COMMA") {
             $error = $only_one;
         }
         if ($error === false) {
             do {
                 $next_var = $phpcsFile->findNext(T_WHITESPACE, $next_var + 1, null, true);
                 $token = $tokens[$next_var];
             } while ($token["line"] == $var_line && !in_array($token["type"], array("T_COMMA", "T_SEMICOLON", "T_OPEN_SQUARE_BRACKET")));
             if ($token["type"] == "T_COMMA") {
                 $error = $only_one;
             }
         }
         if ($error !== false) {
             $phpcsFile->addError($this->getReqPrefix('REQ.JS.3.7') . $error, $stackPtr);
         }
     }
     return;
 }
开发者ID:kingsj,项目名称:core,代码行数:41,代码来源:VariableSniff.php

示例12: process

 /**
  * 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)
 {
     // If short open tags are off, then any short open tags will be converted
     // to inline_html tags so we can just ignore them.
     // If its on, then we want to ban the use of them.
     $option = ini_get('short_open_tag');
     // Ini_get returns a string "0" if short open tags is off.
     if ($option === '0') {
         return;
     }
     if (!isset($this->files_cache[$phpcsFile->getFilename()]) && !$phpcsFile->findNext(T_OPEN_TAG, $stackPtr + 1) && !$phpcsFile->findNext(T_OPEN_TAG_WITH_ECHO, $stackPtr + 1) && $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr)) {
         $error = 'Файл имеет только один открывающий PHP-тэг, но имеет закрывающий PHP-тэг.';
         $phpcsFile->addError($this->getReqPrefix('REQ.PHP.2.1.1') . $error, $stackPtr);
     }
     $this->files_cache[$phpcsFile->getFilename()] = true;
     $tokens = $phpcsFile->getTokens();
     $openTag = $tokens[$stackPtr];
     if ($openTag['content'] === '<?') {
         $error = 'Short PHP opening tag used. Found "' . $openTag['content'] . '" Expected "<?php".';
         $phpcsFile->addError($this->getReqPrefix('REQ.PHP.2.1.2') . $error, $stackPtr);
     }
     if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO) {
         $nextVar = $tokens[$phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true)];
         $error = 'Short PHP opening tag used with echo. Found "';
         $error .= $openTag['content'] . ' ' . $nextVar['content'] . ' ..." but expected "<?php echo ' . $nextVar['content'] . ' ...".';
         $phpcsFile->addError($this->getReqPrefix('REQ.PHP.2.1.2') . $error, $stackPtr);
     }
 }
开发者ID:kingsj,项目名称:core,代码行数:37,代码来源:DisallowShortOpenTagSniff.php

示例13: process

 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  * @param int                  $stackPtr  The position in the stack where
  *                                        the token was found.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $style = $tokens[$stackPtr]['content'];
     $start = $phpcsFile->findNext(T_COLON, $stackPtr);
     $end = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
     if (!$start || !$end) {
         return;
     }
     # Get the full description value
     $value = '';
     for ($i = $start + 1; $i < $end; $i++) {
         if ($tokens[$i]['code'] === T_LNUMBER) {
             # Next to number follows the dimension
             if ($tokens[$i + 1]['code'] === T_WHITESPACE || $tokens[$i + 1]['code'] === T_SEMICOLON) {
                 continue;
             }
             $dim = $tokens[$i + 1]['content'];
             if (!in_array($dim, $this->allowedDims)) {
                 $error = 'Запрещены к использованию размерности, кроме px, em, ex, %';
                 $phpcsFile->addError($this->getReqPrefix('REQ.CSS.3.0.1') . $error, $i);
             } elseif (in_array($style, $this->relativeDimsStyles) && !in_array($dim, array('em', 'ex', '%'))) {
                 /* TODO - research
                                   $error = 'Размерность шрифта требуется задавать в em/ex';
                                   $phpcsFile->addError($this->getReqPrefix('REQ.CSS.3.0.1') . $error, $i);
                 			*/
             }
         }
     }
 }
开发者ID:kingsj,项目名称:core,代码行数:39,代码来源:RequiredDimensionsSniff.php

示例14: process

 /**
  * @inheritdoc
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $classScopeStart = $tokens[$stackPtr]['scope_opener'];
     $classScopeEnd = $tokens[$stackPtr]['scope_closer'];
     $classPosition = $stackPtr;
     $stackPtr = $phpcsFile->findNext(T_STRING, $stackPtr + 1);
     $className = $tokens[$stackPtr]['content'];
     if (false === ($stackPtr = $phpcsFile->findNext(T_EXTENDS, $stackPtr + 1))) {
         // the currently tested class hasn't extended any class
         return;
     }
     $stackPtr = $phpcsFile->findNext(T_STRING, $stackPtr + 1);
     $parentClassName = $tokens[$stackPtr]['content'];
     if ($parentClassName == self::PARENT_CLASS_NAME) {
         while (false !== ($stackPtr = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $classScopeStart + 1, $classScopeEnd - 1, true, 'function'))) {
             $stackPtr = $phpcsFile->findNext(T_STRING, $stackPtr + 1);
             $methodName = $tokens[$stackPtr]['content'];
             $classScopeStart = $stackPtr;
             if ($methodName == self::REQUIRED_ACL_METHOD_NAME) {
                 // the currently tested class has implemented the required ACL method
                 return;
             }
         }
         $phpcsFile->addError('Missing the %s() ACL method in the %s class.', $classPosition, 'MissingAclMethod', array(self::REQUIRED_ACL_METHOD_NAME, $className));
     }
 }
开发者ID:ffuenf,项目名称:coding-standard,代码行数:30,代码来源:AclSniff.php

示例15: processFunction

 /**
  * Process this function definition.
  *
  * @param PHP_CodeSniffer_File $phpcsFile   The file being scanned.
  * @param int                  $stackPtr    The position of the function name in the stack.
  *                                           name in the stack.
  * @param int                  $functionPtr The position of the function keyword in the stack.
  *                                           keyword in the stack.
  *
  * @return void
  */
 public function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr)
 {
     $fileExtension = strtolower(substr($phpcsFile->getFilename(), -6));
     // Only check in *.module files.
     if ($fileExtension !== 'module') {
         return;
     }
     $fileName = substr(basename($phpcsFile->getFilename()), 0, -7);
     $tokens = $phpcsFile->getTokens();
     if ($tokens[$stackPtr]['content'] !== $fileName . '_menu') {
         return;
     }
     // Search in the function body for t() calls.
     $string = $phpcsFile->findNext(T_STRING, $tokens[$functionPtr]['scope_opener'], $tokens[$functionPtr]['scope_closer']);
     while ($string !== false) {
         if ($tokens[$string]['content'] === 't') {
             $opener = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $string + 1, null, true);
             if ($opener !== false && $tokens[$opener]['code'] === T_OPEN_PARENTHESIS) {
                 $error = 'Do not use t() in hook_menu()';
                 $phpcsFile->addError($error, $string, 'TFound');
             }
         }
         $string = $phpcsFile->findNext(T_STRING, $string + 1, $tokens[$functionPtr]['scope_closer']);
     }
     //end while
 }
开发者ID:atif-shaikh,项目名称:DCX-Profile,代码行数:37,代码来源:TInHookMenuSniff.php


注:本文中的PHP_CodeSniffer_File::findNext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。