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


PHP PHP_CodeSniffer::getConfigData方法代码示例

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


在下文中一共展示了PHP_CodeSniffer::getConfigData方法的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
  * @throws PHP_CodeSniffer_Exception If jshint.js could not be run
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $fileName = $phpcsFile->getFilename();
     $rhinoPath = PHP_CodeSniffer::getConfigData('rhino_path');
     $jshintPath = PHP_CodeSniffer::getConfigData('jshint_path');
     if ($rhinoPath === null || $jshintPath === null) {
         return;
     }
     $cmd = "{$rhinoPath} \"{$jshintPath}\" \"{$fileName}\"";
     $msg = exec($cmd, $output, $retval);
     if (is_array($output) === true) {
         foreach ($output as $finding) {
             $matches = array();
             $numMatches = preg_match('/^(.+)\\(.+:([0-9]+).*:[0-9]+\\)$/', $finding, $matches);
             if ($numMatches === 0) {
                 continue;
             }
             $line = (int) $matches[2];
             $message = 'jshint says: ' . trim($matches[1]);
             $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool');
         }
     }
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
开发者ID:kmiku7,项目名称:PHP_CodeSniffer-2.3.2-annotated,代码行数:35,代码来源:JSHintSniff.php

示例2: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param integer              $stackPtr  The position of the current token in
  *                                        the token stack.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     if ($this->_phpVersion === null) {
         $this->_phpVersion = PHP_CodeSniffer::getConfigData('php_version');
         if ($this->_phpVersion === null) {
             $this->_phpVersion = PHP_VERSION_ID;
         }
     }
     $tokens = $phpcsFile->getTokens();
     if (isset($tokens[$stackPtr]['scope_closer']) === false) {
         return;
     }
     $errorData = array(strtolower($tokens[$stackPtr]['content']));
     $nextClass = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE, T_TRAIT), $tokens[$stackPtr]['scope_closer'] + 1);
     if ($nextClass !== false) {
         $error = 'Each %s must be in a file by itself';
         $phpcsFile->addError($error, $nextClass, 'MultipleClasses', $errorData);
         $phpcsFile->recordMetric($stackPtr, 'One class per file', 'no');
     } else {
         $phpcsFile->recordMetric($stackPtr, 'One class per file', 'yes');
     }
     if ($this->_phpVersion >= 50300) {
         $namespace = $phpcsFile->findNext(array(T_NAMESPACE, T_CLASS, T_INTERFACE, T_TRAIT), 0);
         if ($tokens[$namespace]['code'] !== T_NAMESPACE) {
             $error = 'Each %s must be in a namespace of at least one level (a top-level vendor name)';
             $phpcsFile->addError($error, $stackPtr, 'MissingNamespace', $errorData);
             $phpcsFile->recordMetric($stackPtr, 'Class defined in namespace', 'no');
         } else {
             $phpcsFile->recordMetric($stackPtr, 'Class defined in namespace', 'yes');
         }
     }
 }
开发者ID:squizlabs,项目名称:php_codesniffer,代码行数:41,代码来源:ClassDeclarationSniff.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();
     $ignore = array(T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_FUNCTION, T_CONST);
     $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
     if (in_array($tokens[$prevToken]['code'], $ignore) === true) {
         // Not a call to a PHP function.
         return;
     }
     $function = strtolower($tokens[$stackPtr]['content']);
     if ($function != 'ini_get' && $function != 'ini_set') {
         return;
     }
     $iniToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr, null);
     $filteredToken = str_replace(array('"', "'"), array("", ""), $tokens[$iniToken]['content']);
     if (in_array($filteredToken, array_keys($this->newIniDirectives)) === false) {
         return;
     }
     $error = '';
     foreach ($this->newIniDirectives[$filteredToken] as $version => $present) {
         if (!is_null(PHP_CodeSniffer::getConfigData('testVersion')) && version_compare(PHP_CodeSniffer::getConfigData('testVersion'), $version) <= 0) {
             if ($present === true) {
                 $error .= " not available before version " . $version;
             }
         }
     }
     if (strlen($error) > 0) {
         $error = "INI directive '" . $filteredToken . "' is" . $error;
         $phpcsFile->addWarning($error, $stackPtr);
     }
 }
开发者ID:dariogs,项目名称:moosh,代码行数:40,代码来源:NewIniDirectivesSniff.php

示例4: 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)
 {
     $fileName = $phpcsFile->getFilename();
     $jslPath = PHP_CodeSniffer::getConfigData('jsl_path');
     if (is_null($jslPath) === true) {
         return;
     }
     $cmd = '"' . $jslPath . '" -nologo -nofilelisting -nocontext -nosummary -output-format __LINE__:__ERROR__ -process "' . $fileName . '"';
     $msg = exec($cmd, $output, $retval);
     // Variable $exitCode is the last line of $output if no error occurs, on
     // error it is numeric. Try to handle various error conditions and
     // provide useful error reporting.
     if ($retval === 2 || $retval === 4) {
         if (is_array($output) === true) {
             $msg = join('\\n', $output);
         }
         throw new PHP_CodeSniffer_Exception("Failed invoking JavaScript Lint, retval was [{$retval}], output was [{$msg}]");
     }
     if (is_array($output) === true) {
         foreach ($output as $finding) {
             $split = strpos($finding, ':');
             $line = substr($finding, 0, $split);
             $message = substr($finding, $split + 1);
             $phpcsFile->addWarningOnLine(trim($message), $line, 'ExternalTool');
         }
     }
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
开发者ID:genextwebs,项目名称:dropbox-sample,代码行数:38,代码来源:JavaScriptLintSniff.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();
     if ($this->forceParanoia >= 0) {
         $parano = $this->forceParanoia ? 1 : 0;
     } else {
         $parano = PHP_CodeSniffer::getConfigData('ParanoiaMode') ? 1 : 0;
     }
     $tokens = $phpcsFile->getTokens();
     $s = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr, null, true, null, true);
     if ($tokens[$stackPtr]['code'] == T_OPEN_TAG_WITH_ECHO) {
         $closer = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr);
     } elseif ($tokens[$s]['code'] == T_OPEN_PARENTHESIS) {
         $closer = $tokens[$s]['parenthesis_closer'];
     } else {
         $closer = $phpcsFile->findNext(array(T_SEMICOLON, T_CLOSE_TAG), $stackPtr);
         $s = $stackPtr;
     }
     $warn = false;
     while ($s) {
         $s = $phpcsFile->findNext(array_merge(PHP_CodeSniffer_Tokens::$emptyTokens, PHP_CodeSniffer_Tokens::$bracketTokens, Security_Sniffs_Utils::$staticTokens), $s + 1, $closer, true);
         if ($s && $utils::is_token_user_input($tokens[$s])) {
             $phpcsFile->addError('Easy XSS detected because of direct user input with ' . $tokens[$s]['content'] . ' on ' . $tokens[$stackPtr]['content'], $s, 'EasyXSSerr');
         } elseif ($s && $utils::is_XSS_mitigation($tokens[$s]['content'])) {
             $s = $tokens[$s + 1]['parenthesis_closer'];
         } elseif ($s && $parano && !$warn) {
             $warn = $s;
         }
     }
     if ($warn) {
         $phpcsFile->addWarning('Possible XSS detected with ' . $tokens[$warn]['content'] . ' on ' . $tokens[$stackPtr]['content'], $warn, 'EasyXSSwarn');
     }
 }
开发者ID:valugi,项目名称:phpcs-security-audit,代码行数:42,代码来源:EasyXSSSniff.php

示例6: 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 = new Security_Sniffs_Drupal7_Utils();
     $tokens = $phpcsFile->getTokens();
     $content = $tokens[$stackPtr]['content'];
     if ($content == 'cache_get' || $content == 'cache_set') {
         //$closer = $tokens[$stackPtr + 1]['parenthesis_closer'];
         // The first parameter is the one sensible
         $p1tokens = $utils::get_param_tokens($phpcsFile, $stackPtr, 1);
         if (!$p1tokens) {
             echo "empty {$content}?\n";
             return;
         }
         $closer = end($p1tokens)['stackPtr'] + 1;
         $s = $stackPtr + 1;
         while ($s < $closer) {
             $s = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $s + 1, $closer, true);
             if (!$s) {
                 break;
             }
             if ($utils::is_token_user_input($tokens[$s])) {
                 $phpcsFile->addError("Potential cache injection found in {$content}()", $s, 'D7Cachei');
             } elseif (PHP_CodeSniffer::getConfigData('ParanoiaMode') && in_array($tokens[$s]['code'], $utils::getVariableTokens())) {
                 $phpcsFile->addWarning("Direct variable usage in {$content}()", $s, 'D7CacheDirectVar');
             }
         }
     }
 }
开发者ID:valugi,项目名称:phpcs-security-audit,代码行数:37,代码来源:CacheiSniff.php

示例7: 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)
 {
     $fileName = $phpcsFile->getFilename();
     $csslintPath = PHP_CodeSniffer::getConfigData('csslint_path');
     if ($csslintPath === null) {
         return;
     }
     $cmd = $csslintPath . ' ' . escapeshellarg($fileName);
     exec($cmd, $output, $retval);
     if (is_array($output) === false) {
         return;
     }
     $count = count($output);
     for ($i = 0; $i < $count; $i++) {
         $matches = array();
         $numMatches = preg_match('/(error|warning) at line (\\d+)/', $output[$i], $matches);
         if ($numMatches === 0) {
             continue;
         }
         $line = (int) $matches[2];
         $message = 'csslint says: ' . $output[$i + 1];
         // First line is message with error line and error code.
         // Second is error message.
         // Third is wrong line in file.
         // Fourth is empty line.
         $i += 4;
         $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool');
     }
     //end for
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
开发者ID:kmiku7,项目名称:PHP_CodeSniffer-2.3.2-annotated,代码行数:41,代码来源:CSSLintSniff.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 (is_null(PHP_CodeSniffer::getConfigData('testVersion')) || !is_null(PHP_CodeSniffer::getConfigData('testVersion')) && version_compare(PHP_CodeSniffer::getConfigData('testVersion'), '5.4') >= 0) {
         $tokens = $phpcsFile->getTokens();
         if (in_array($tokens[$stackPtr]['content'], $this->algoFunctions) === true) {
             $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true);
             if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
                 return;
             }
             $firstParam = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $openBracket + 1, null, true);
             /**
              * Algorithm is a T_CONSTANT_ENCAPSED_STRING, so we need to remove the quotes
              */
             $algo = strtolower($tokens[$firstParam]['content']);
             $algo = substr($algo, 1, strlen($algo) - 2);
             switch ($algo) {
                 case 'salsa10':
                 case 'salsa20':
                     $error = 'The Salsa10 and Salsa20 hash algorithms have been removed since PHP 5.4';
                     $phpcsFile->addError($error, $stackPtr);
                     break;
             }
         }
     }
 }
开发者ID:dariogs,项目名称:moosh,代码行数:34,代码来源:RemovedHashAlgorithmsSniff.php

示例9: process

 /**
  * Processes the tokens that this sniff is interested in.
  */
 public function process(PHP_CodeSniffer_File $phpcs_file, $stack_ptr)
 {
     $file_name = $phpcs_file->getFilename();
     $jscs_path = PHP_CodeSniffer::getConfigData('jscs_path');
     if ($jscs_path === NULL) {
         return;
     }
     // JSCS options to generate an output that can be parsed by the script
     // below.
     // @see http://jscs.info/overview.
     $jscs_options = '--reporter=text';
     $cmd = '"' . $jscs_path . '/jscs' . '"' . ' ' . '"' . $file_name . '"' . ' ' . $jscs_options;
     exec($cmd, $output, $retval);
     if (is_array($output) === TRUE) {
         $tokens = $phpcs_file->getTokens();
         $messages = $this->parseMessages($output);
         foreach ($messages as $output) {
             $line_number = $this->parseLineNumber($output);
             $message = $this->parseMessage($output);
             // Find the token at the start of the line.
             $line_token = NULL;
             foreach ($tokens as $ptr => $info) {
                 if ($line_number == $info['line']) {
                     $line_token = $ptr;
                     break;
                 }
             }
             $phpcs_file->addWarning($message, $line_token, 'ExternalTool');
         }
     }
 }
开发者ID:alexdesignworks,项目名称:dcr,代码行数:34,代码来源:JSCSSniff.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 (preg_match('/<|>/', $tokens[$stackPtr]['content'])) {
         $end = $phpcsFile->findNext(T_SEMICOLON, $stackPtr + 1);
         $next = $stackPtr;
         while ($next && ($next = $phpcsFile->findNext(array_merge(array(T_STRING_CONCAT), PHP_CodeSniffer_Tokens::$emptyTokens), $next + 1, $end, true))) {
             // Next token will be checked with this sniff, no need to go further
             if (in_array($tokens[$next]['code'], $this->register())) {
                 return;
             }
             if ($next && !in_array($tokens[$next]['content'], $utils::getXSSMitigationFunctions())) {
                 if ($utils::is_direct_user_input($tokens[$next]['content'])) {
                     $phpcsFile->addError('HTML construction with direct user input ' . $tokens[$next]['content'] . ' detected.', $stackPtr, 'D7XSSHTMLConstructErr');
                 } elseif (PHP_CodeSniffer::getConfigData('ParanoiaMode') && !in_array($tokens[$next]['code'], array_merge(array(T_INLINE_ELSE, T_COMMA), PHP_CodeSniffer_Tokens::$booleanOperators))) {
                     if ($tokens[$next]['code'] == T_CLOSE_PARENTHESIS) {
                         $f = $phpcsFile->findPrevious(T_STRING, $next);
                         if ($f) {
                             $phpcsFile->addWarning('HTML construction with ' . $tokens[$f]['content'] . '() detected.', $stackPtr, 'D7XSSHTMLConstructWarnF');
                         }
                     } else {
                         $phpcsFile->addWarning('HTML construction with ' . $tokens[$next]['content'] . ' detected.', $stackPtr, 'D7XSSHTMLConstructWarn');
                     }
                 }
             }
             $next = $phpcsFile->findNext(T_STRING_CONCAT, $next + 1, $end);
         }
     }
 }
开发者ID:valugi,项目名称:phpcs-security-audit,代码行数:39,代码来源:XSSHTMLConstructSniff.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)
 {
     $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

示例12: 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 = new Security_Sniffs_Drupal7_Utils();
     $tokens = $phpcsFile->getTokens();
     if ($tokens[$stackPtr]['content'] == 'drupal_http_request') {
         $closer = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
         $s = $closer;
         $warn = 1;
         while ($s) {
             $s = $phpcsFile->findPrevious(array(T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_QUOTED_STRING), $s - 1);
             if ($tokens[$s]['content'] == "'verify_peer'" || $tokens[$s]['content'] == '"verify_peer"') {
                 $warn = 0;
             }
         }
         if ($warn) {
             $phpcsFile->addWarning('Verify that drupal_http_request uses HTTPS and is called with verify_peer in order to validate the certificate', $stackPtr, 'D7HttpRequestSSL');
         }
         $d = $utils::findDirtyParam($phpcsFile, $stackPtr);
         if ($d && $utils::is_token_user_input($tokens[$d])) {
             $phpcsFile->addError('drupal_http_request called with direct user input ' . $tokens[$d]['content'], $stackPtr, 'D7HttpRequestUserInputErr');
         } elseif ($d && PHP_CodeSniffer::getConfigData('ParanoiaMode')) {
             $phpcsFile->addWarning('drupal_http_request called with variable ' . $tokens[$d]['content'], $stackPtr, 'D7HttpRequestUserInputErr');
         }
     }
 }
开发者ID:valugi,项目名称:phpcs-security-audit,代码行数:34,代码来源:HttpRequestSniff.php

示例13: 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 (is_null(PHP_CodeSniffer::getConfigData('testVersion')) || !is_null(PHP_CodeSniffer::getConfigData('testVersion')) && version_compare(PHP_CodeSniffer::getConfigData('testVersion'), '5.4') >= 0) {
         $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:dariogs,项目名称:moosh,代码行数:39,代码来源:ForbiddenBreakContinueVariableArgumentsSniff.php

示例14: 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

示例15: getTestVersion

 private function getTestVersion()
 {
     /**
      * var $testVersion will hold an array containing min/max version of PHP
      *   that we are checking against (see above).  If only a single version
      *   number is specified, then this is used as both the min and max.
      */
     static $arrTestVersions;
     if (!isset($testVersion)) {
         $testVersion = PHP_CodeSniffer::getConfigData('testVersion');
         $testVersion = trim($testVersion);
         $arrTestVersions = array(null, null);
         if (preg_match('/^\\d+\\.\\d+$/', $testVersion)) {
             $arrTestVersions = array($testVersion, $testVersion);
         } elseif (preg_match('/^(\\d+\\.\\d+)\\s*-\\s*(\\d+\\.\\d+)$/', $testVersion, $matches)) {
             if (version_compare($matches[1], $matches[2], ">")) {
                 trigger_error("Invalid range in testVersion setting: '" . $testVersion . "'", E_USER_WARNING);
             } else {
                 $arrTestVersions = array($matches[1], $matches[2]);
             }
         } elseif (!$testVersion == "") {
             trigger_error("Invalid testVersion setting: '" . $testVersion . "'", E_USER_WARNING);
         }
     }
     return $arrTestVersions;
 }
开发者ID:christopheg,项目名称:PHPCompatibility,代码行数:26,代码来源:Sniff.php


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