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


PHP PHP_CodeSniffer_File::addWarning方法代码示例

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


在下文中一共展示了PHP_CodeSniffer_File::addWarning方法的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 (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

示例2: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * Ensures that early returns are not followed by else.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param integer              $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();
     $nextToken = $phpcsFile->findNext(T_CLOSE_CURLY_BRACKET, $stackPtr + 1);
     if (!$nextToken) {
         return;
     }
     $tokenInfo = $tokens[$nextToken];
     if ($tokenInfo['bracket_opener'] >= $stackPtr) {
         return;
     }
     $nextToken = $phpcsFile->findNext(T_WHITESPACE, $nextToken + 1, null, true);
     if (!$nextToken) {
         return;
     }
     if ($tokens[$nextToken]['code'] === T_ELSEIF) {
         $warning = 'The ELSEIF after an early return is not always necessary and can probably be simplified.';
         $phpcsFile->addWarning($warning, $stackPtr, 'Warning');
     }
     if ($tokens[$nextToken]['code'] !== T_ELSE) {
         return;
     }
     $warning = 'The ELSE after an early return is not necessary and should be simplified.';
     $phpcsFile->addWarning($warning, $stackPtr, 'Warning');
 }
开发者ID:dereuromark,项目名称:codesniffer-standards,代码行数:35,代码来源:ReturnEarlySniff.php

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

示例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)
 {
     $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

示例5: 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();
     $varname = ltrim($tokens[$stackPtr]['content'], '$');
     // Ignore PHP vars
     $keywords = array('_SERVER', '_GET', '_POST', '_REQUEST', '_SESSION', '_ENV', '_COOKIE', '_FILES', '_MODULE', 'GLOBALS');
     if (in_array($varname, $keywords)) {
         return;
     }
     // Check if variable name is valid
     if (!in_array($varname, $this->exceptions) && !preg_match('#^[a-z][a-z0-9]*(_[a-z0-9]+)*$#', $varname)) {
         $error = 'Variable "%s" have not right syntax. Should be : "%s"';
         $phpcsFile->addWarning($error, $stackPtr, 'VariableNameNotValid', array('$' . $varname, '$' . $this->makeRealName($varname)));
     }
     // Now check if there is an object member after the variable
     $next = $phpcsFile->findNext(array(T_WHITESPACE), $stackPtr + 1, null, true);
     if ($tokens[$next]['code'] === T_OBJECT_OPERATOR) {
         $nextMember = $phpcsFile->findNext(array(T_WHITESPACE), $next + 1, null, true);
         if ($tokens[$nextMember]['code'] === T_STRING) {
             // Check if this is not a function
             $nextBracket = $objOperator = $phpcsFile->findNext(array(T_WHITESPACE), $nextMember + 1, null, true);
             if ($tokens[$nextBracket]['code'] !== T_OPEN_PARENTHESIS) {
                 $membername = $tokens[$nextMember]['content'];
                 if (!in_array($membername, $this->exceptions) && !preg_match('#^[_a-z][a-z0-9]*(_[a-z0-9]+)*$#', $membername)) {
                     $error = 'Variable "%s" have not right syntax. Should be: "%s"';
                     $phpcsFile->addWarning($error, $stackPtr, 'VariableNameNotValid', array('->' . $membername, '->' . $this->makeRealName($membername)));
                 }
             }
         }
     }
 }
开发者ID:shoppingflux,项目名称:prestashop-norm-validator,代码行数:40,代码来源:ValidVariableNameSniff.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 = 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

示例7: processFunctionCall

 /**
  * Processes this function call.
  *
  * @param PHP_CodeSniffer_File $phpcsFile
  *   The file being scanned.
  * @param int $stackPtr
  *   The position of the function call in the stack.
  * @param int $openBracket
  *   The position of the opening parenthesis in the stack.
  * @param int $closeBracket
  *   The position of the closing parenthesis in the stack.
  * @param Drupal_Sniffs_Semantics_FunctionCallSniff $sniff
  *   Can be used to retreive the function's arguments with the getArgument()
  *   method.
  *
  * @return void
  */
 public function processFunctionCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $closeBracket, Drupal_Sniffs_Semantics_FunctionCallSniff $sniff)
 {
     $tokens = $phpcsFile->getTokens();
     $argument = $sniff->getArgument(1);
     if ($argument === false) {
         $error = 'Empty calls to t() are not allowed';
         $phpcsFile->addError($error, $stackPtr, 'EmptyT');
         return;
     }
     if ($tokens[$argument['start']]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
         // Not a translatable string literal.
         return;
     }
     $concatFound = $phpcsFile->findNext(T_STRING_CONCAT, $argument['start'], $argument['end']);
     if ($concatFound !== false) {
         $error = 'Concatenating translatable strings is not allowed, use placeholders instead and only one string literal';
         $phpcsFile->addError($error, $concatFound, 'Concat');
     }
     $string = $tokens[$argument['start']]['content'];
     // Check if there is a backslash escaped single quote in the string and
     // if the string makes use of double quotes.
     if ($string[0] === "'" && strpos($string, "\\'") !== false && strpos($string, '"') === false) {
         $warn = 'Avoid backslash escaping in translatable strings when possible, use "" quotes instead';
         $phpcsFile->addWarning($warn, $argument['start'], 'BackslashSingleQuote');
         return;
     }
     if ($string[0] === '"' && strpos($string, '\\"') !== false && strpos($string, "'") === false) {
         $warn = "Avoid backslash escaping in translatable strings when possible, use '' quotes instead";
         $phpcsFile->addWarning($warn, $argument['start'], 'BackslashDoubleQuote');
     }
 }
开发者ID:ecs-hk,项目名称:Checkbook,代码行数:48,代码来源:FunctionTSniff.php

示例8: process

 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $error = 'Return statements should have a blank line prior to it.';
     $prevLineToken = null;
     for ($i = $stackPtr; $i > 0; $i--) {
         if (false === strpos($tokens[$i]['content'], "\n")) {
             continue;
         } else {
             $prevLineToken = $i;
             break;
         }
     }
     if (is_null($prevLineToken)) {
         $phpcsFile->addWarning($error, $stackPtr);
         return null;
     }
     $prevNonWhiteSpace = null;
     for ($i = $prevLineToken; $i > 0; $i--) {
         if (T_WHITESPACE === $tokens[$i]['code']) {
             continue;
         } else {
             $prevNonWhiteSpace = $i;
             break;
         }
     }
     if (!is_null($prevNonWhiteSpace)) {
         $prevLine = $tokens[$prevLineToken]['line'];
         $prevNonWhiteSpaceLine = $tokens[$prevNonWhiteSpace]['line'];
         if ($prevLine === $prevNonWhiteSpaceLine) {
             $phpcsFile->addWarning($error, $stackPtr);
         }
     }
 }
开发者ID:te-koyama,项目名称:openpne,代码行数:34,代码来源:ReturnSpacingSniff.php

示例9: processTokenWithinScope

 /**
  * Processes this test when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The current file being scanned.
  * @param int                  $stackPtr  The position of the current token
  *                                        in the stack passed in $tokens.
  * @param int                  $currScope A pointer to the start of the scope.
  *
  * @return void
  */
 protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
 {
     $className = $phpcsFile->getDeclarationName($currScope);
     $methodName = $phpcsFile->getDeclarationName($stackPtr);
     if (strcasecmp($methodName, $className) === 0) {
         $error = 'PHP4 style constructors are discouraged; use "__construct()" instead';
         $phpcsFile->addWarning($error, $stackPtr, 'OldStyle');
     } else {
         if (strcasecmp($methodName, '__construct') !== 0) {
             // Not a constructor.
             return;
         }
     }
     $tokens = $phpcsFile->getTokens();
     $parentClassName = $phpcsFile->findExtendedClassName($currScope);
     if ($parentClassName === false) {
         return;
     }
     $endFunctionIndex = $tokens[$stackPtr]['scope_closer'];
     $startIndex = $stackPtr;
     while ($doubleColonIndex = $phpcsFile->findNext(array(T_DOUBLE_COLON), $startIndex, $endFunctionIndex)) {
         if ($tokens[$doubleColonIndex + 1]['code'] === T_STRING && $tokens[$doubleColonIndex + 1]['content'] === $parentClassName) {
             $error = 'PHP4 style calls to parent constructors are discouraged; use "parent::__construct()" instead';
             $phpcsFile->addWarning($error, $doubleColonIndex + 1, 'OldStyleCall');
         }
         $startIndex = $doubleColonIndex + 1;
     }
 }
开发者ID:neosunchess,项目名称:dokuwiki,代码行数:38,代码来源:ConstructorNameSniff.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)
 {
     if ($stackPtr > 0) {
         return;
     }
     $dversion = '7';
     $fileName = $phpcsFile->getFileName();
     if (!preg_match('/\\.info$/', $fileName)) {
         return;
     }
     $utils = Security_Sniffs_UtilsFactory::getInstance('Drupal7');
     $tokens = $phpcsFile->getTokens();
     $info = $utils->drupal_parse_info_format(file_get_contents($fileName));
     if (isset($info) && count($info) && array_key_exists('project', $info) && array_key_exists($info['project'], $utils::$ContribAdvisories)) {
         if ($utils::$ContribAdvisories[$info['project']][0][0] == 'abandoned') {
             $phpcsFile->addError("Module " . $info['project'] . " is abandoned due to a security issue the maintainer never fixed. Details: " . $utils::$ContribAdvisories[$info['project']][0][1], $stackPtr, 'D7ErrAdvisoriesContribAbandonned');
             return;
         }
         if ($utils::$ContribAdvisories[$info['project']][0][0] == 'unsupported') {
             $phpcsFile->addError("Module " . $info['project'] . " is unsupported due to unfixed security issue. The Drupal Security Team recommends that this module be uninstalled immediately Details: " . $utils::$ContribAdvisories[$info['project']][0][1], $stackPtr, 'D7ErrAdvisoriesContribUnsupported');
             return;
         }
         if (array_key_exists('core', $info) && array_key_exists('version', $info)) {
             if (strpos($info['core'], $dversion) === 0) {
                 foreach ($utils::$ContribAdvisories[$info['project']] as $vcve) {
                     list($a, $CVEversion) = explode('-', $vcve[0]);
                     if ($a != $info['core']) {
                         echo "WARNING Drupal core version inconsistence!!";
                     }
                     list($a, $mversion) = explode('-', $info['version']);
                     $CVEversion = (double) $CVEversion;
                     if (preg_match('/dev/', $vcve[0])) {
                         $phpcsFile->addWarning("WARNING module " . $info['project'] . " does not have any release for the security fix, manual checking required. Details: " . $vcve[1], $stackPtr, 'D7WarnAdvisoriesContribDev');
                     }
                     if (preg_match('/rc|alpha|beta/', $vcve[0])) {
                         $phpcsFile->addWarning("WARNING module " . $info['project'] . " is using special version tagging around the security fix, manual checking recommanded. Details: " . $vcve[1], $stackPtr, 'D7WarnAdvisoriesContribrc');
                     }
                     $mversion = (double) $mversion;
                     $diff = $CVEversion - $mversion;
                     if ($diff > 0 && $diff < 1) {
                         $phpcsFile->addError("Module " . $info['project'] . " " . $info['version'] . " contains security issue and must be updated to at least {$vcve['0']}. Details: " . $vcve[1], $stackPtr, 'D7ErrAdvisoriesContribFoundMinor');
                     } elseif ($diff >= 1) {
                         $phpcsFile->addWarning("Module " . $info['project'] . " " . $info['version'] . " is out of date a major version and might contains security issue. " . $vcve[1], $stackPtr, 'D7WarnAdvisoriesContribFoundMajor');
                     } elseif ($diff <= 0) {
                         if (preg_match('/x$/', $vcve[0])) {
                             $phpcsFile->addError("Module " . $info['project'] . " " . $info['version'] . " contains security issue to all {$vcve['0']} versions. " . $vcve[1], $stackPtr, 'D7ErrAdvisoriesContribFoundMajor');
                         } else {
                             //echo "$fileName: SAFE! " . $info['version'] . "\n";
                         }
                     } else {
                         echo "MAJOR ERROR IN LOGIC!!!!!\n";
                     }
                 }
             }
         } else {
             $phpcsFile->addWarning("Module " . $info['project'] . " is listed in advisories but file doesn't provide version information. Please use packages from drupal.org", $stackPtr, 'D7WarnAdvisoriesContribNoInfo');
         }
     }
 }
开发者ID:valugi,项目名称:phpcs-security-audit,代码行数:68,代码来源:AdvisoriesContribSniff.php

示例11: 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_CONTINUE) {
         $phpcsFile->addWarning($this->getReqPrefix('WRN.PHP.2.5.4') . 'Использование ' . $tokens[$stackPtr]['content'] . ' не рекомендовано', $stackPtr);
     } elseif ($tokens[$stackPtr]['code'] == T_BREAK && T_SWITCH != end($tokens[$stackPtr]['conditions'])) {
         $phpcsFile->addWarning($this->getReqPrefix('WRN.PHP.2.5.4') . 'Использование ' . $tokens[$stackPtr]['content'] . ' не рекомендовано', $stackPtr);
     }
 }
开发者ID:kingsj,项目名称:core,代码行数:18,代码来源:ForbidControleOperatorsSniff.php

示例12: checkSize

 /**
  * Report coding standard violation if class/interface/trait/function is too big
  *
  * @param PHPParser_Node $node Current node
  *
  * {@internal 'maximum' is padded to compensate for opening/closing curly braces }}
  */
 private function checkSize($node)
 {
     $keyword = $this->metaData[$node->getType()]['keyword'];
     $maximum = $this->metaData[$node->getType()]['maximum'];
     $size = $node->getAttribute('endLine') - $node->getAttribute('startLine');
     if ($size <= $maximum + 2) {
         return;
     }
     $this->phpcsFile->addWarning(sprintf('Keep your %s small (no more than %d lines)', $keyword, $maximum), $this->findStackPointer($node));
 }
开发者ID:phpextra,项目名称:symfony2-coding-standard,代码行数:17,代码来源:NodeVisitor.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)
 {
     $tokens = $phpcsFile->getTokens();
     $find = PHP_CodeSniffer_Tokens::$methodPrefixes;
     $find[] = T_WHITESPACE;
     $commentEnd = $phpcsFile->findPrevious($find, $stackPtr - 1, null, true);
     if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT) {
         return;
     }
     if ($tokens[$commentEnd]['code'] === T_COMMENT) {
         return;
     }
     $commentStart = $tokens[$commentEnd]['comment_opener'];
     $empty = array(T_DOC_COMMENT_WHITESPACE, T_DOC_COMMENT_STAR);
     $short = $phpcsFile->findNext($empty, $commentStart + 1, $commentEnd, true);
     if ($short === false) {
         // No content at all.
         return;
     }
     // Account for the fact that a short description might cover
     // multiple lines.
     $shortContent = $tokens[$short]['content'];
     $shortEnd = $short;
     for ($i = $short + 1; $i < $commentEnd; $i++) {
         if ($tokens[$i]['code'] === T_DOC_COMMENT_STRING) {
             if ($tokens[$i]['line'] === $tokens[$shortEnd]['line'] + 1) {
                 $shortContent .= $tokens[$i]['content'];
                 $shortEnd = $i;
             } else {
                 break;
             }
         }
     }
     // Check if hook implementation doc is formated correctly.
     if (preg_match('/^[\\s]*Implement[^\\n]+?hook_[^\\n]+/i', $shortContent, $matches)) {
         if (!strstr($matches[0], 'Implements ') || strstr($matches[0], 'Implements of') || !preg_match('/ (drush_)?hook_[a-zA-Z0-9_]+\\(\\)( for [a-z0-9_-]+(\\(\\)|\\.tpl\\.php|\\.html.twig))?\\.$/', $matches[0])) {
             $phpcsFile->addWarning('Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar() for xyz-bar.html.twig.", or "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.".', $short);
         } else {
             // Check that a hook implementation does not duplicate @param and
             // @return documentation.
             foreach ($tokens[$commentStart]['comment_tags'] as $pos => $tag) {
                 if ($tokens[$tag]['content'] === '@param') {
                     $warn = 'Hook implementations should not duplicate @param documentation';
                     $phpcsFile->addWarning($warn, $tag, 'HookParamDoc');
                 }
                 if ($tokens[$tag]['content'] === '@return') {
                     $warn = 'Hook implementations should not duplicate @return documentation';
                     $phpcsFile->addWarning($warn, $tag, 'HookReturnDoc');
                 }
             }
         }
         //end if
     }
     //end if
 }
开发者ID:seshurajup,项目名称:brackets-php-code-quality-tools,代码行数:64,代码来源:HookCommentSniff.php

示例14: processFunctionCall

 /**
  * Processes this function call.
  *
  * @param PHP_CodeSniffer_File $phpcsFile
  *   The file being scanned.
  * @param int                  $stackPtr
  *   The position of the function call in the stack.
  * @param int                  $openBracket
  *   The position of the opening parenthesis in the stack.
  * @param int                  $closeBracket
  *   The position of the closing parenthesis in the stack.
  *
  * @return void
  */
 public function processFunctionCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $closeBracket)
 {
     $tokens = $phpcsFile->getTokens();
     $argument = $this->getArgument(1);
     if ($argument === false) {
         $error = 'Empty calls to t() are not allowed';
         $phpcsFile->addError($error, $stackPtr, 'EmptyT');
         return;
     }
     if ($tokens[$argument['start']]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
         // Not a translatable string literal.
         $warning = 'Only string literals should be passed to t() where possible';
         $phpcsFile->addWarning($warning, $argument['start'], 'NotLiteralString');
         return;
     }
     $string = $tokens[$argument['start']]['content'];
     if ($string === '""' || $string === "''") {
         $warning = 'Do not pass empty strings to t()';
         $phpcsFile->addWarning($warning, $argument['start'], 'EmptyString');
         return;
     }
     $concatAfter = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $closeBracket + 1, null, true, null, true);
     if ($concatAfter !== false && $tokens[$concatAfter]['code'] === T_STRING_CONCAT) {
         $stringAfter = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $concatAfter + 1, null, true, null, true);
         if ($stringAfter !== false && $tokens[$stringAfter]['code'] === T_CONSTANT_ENCAPSED_STRING && strpos($tokens[$stringAfter]['content'], '<') === false) {
             $warning = 'Do not concatenate strings to translatable strings, they should be part of the t() argument and you should use placeholders';
             $phpcsFile->addWarning($warning, $stringAfter, 'ConcatString');
         }
     }
     $lastChar = substr($string, -1);
     if ($lastChar === '"' || $lastChar === "'") {
         $message = substr($string, 1, -1);
         if ($message !== trim($message)) {
             $warning = 'Translatable strings must not begin or end with white spaces, use placeholders with t() for variables';
             $phpcsFile->addWarning($warning, $argument['start'], 'WhiteSpace');
         }
     }
     $concatFound = $phpcsFile->findNext(T_STRING_CONCAT, $argument['start'], $argument['end']);
     if ($concatFound !== false) {
         $error = 'Concatenating translatable strings is not allowed, use placeholders instead and only one string literal';
         $phpcsFile->addError($error, $concatFound, 'Concat');
     }
     // Check if there is a backslash escaped single quote in the string and
     // if the string makes use of double quotes.
     if ($string[0] === "'" && strpos($string, "\\'") !== false && strpos($string, '"') === false) {
         $warn = 'Avoid backslash escaping in translatable strings when possible, use "" quotes instead';
         $phpcsFile->addWarning($warn, $argument['start'], 'BackslashSingleQuote');
         return;
     }
     if ($string[0] === '"' && strpos($string, '\\"') !== false && strpos($string, "'") === false) {
         $warn = "Avoid backslash escaping in translatable strings when possible, use '' quotes instead";
         $phpcsFile->addWarning($warn, $argument['start'], 'BackslashDoubleQuote');
     }
 }
开发者ID:atif-shaikh,项目名称:DCX-Profile,代码行数:68,代码来源:FunctionTSniff.php

示例15: process

 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @name process
  * @access public
  * @see PHP_CodeSniffer_Sniff::process()
  * @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();
     if ($tokens[$stackPtr - 1]['type'] !== 'T_WHITESPACE') {
         $warning = 'Whitespace is expected before any concat operator "."';
         $phpcsFile->addWarning($warning, $stackPtr, 'Found');
     }
     if ($tokens[$stackPtr + 1]['type'] !== 'T_WHITESPACE') {
         $warning = 'Whitespace is expected after any concat operator "."';
         $phpcsFile->addWarning($warning, $stackPtr, 'Found');
     }
 }
开发者ID:pjiahao,项目名称:phpmyadmin,代码行数:23,代码来源:SpacesAroundConcatSniff.php


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