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


PHP File::addError方法代码示例

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


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

示例1: processMemberVar

 /**
  * Processes the function tokens within the class.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
  * @param int                  $stackPtr  The position where the token was found.
  *
  * @return void
  */
 protected function processMemberVar(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     if ($tokens[$stackPtr]['content'][1] === '_') {
         $error = 'Property name "%s" should not be prefixed with an underscore to indicate visibility';
         $data = array($tokens[$stackPtr]['content']);
         $phpcsFile->addWarning($error, $stackPtr, 'Underscore', $data);
     }
     // Detect multiple properties defined at the same time. Throw an error
     // for this, but also only process the first property in the list so we don't
     // repeat errors.
     $find = Tokens::$scopeModifiers;
     $find = array_merge($find, array(T_VARIABLE, T_VAR, T_SEMICOLON));
     $prev = $phpcsFile->findPrevious($find, $stackPtr - 1);
     if ($tokens[$prev]['code'] === T_VARIABLE) {
         return;
     }
     if ($tokens[$prev]['code'] === T_VAR) {
         $error = 'The var keyword must not be used to declare a property';
         $phpcsFile->addError($error, $stackPtr, 'VarUsed');
     }
     $next = $phpcsFile->findNext(array(T_VARIABLE, T_SEMICOLON), $stackPtr + 1);
     if ($tokens[$next]['code'] === T_VARIABLE) {
         $error = 'There must not be more than one property declared per statement';
         $phpcsFile->addError($error, $stackPtr, 'Multiple');
     }
     $modifier = $phpcsFile->findPrevious(Tokens::$scopeModifiers, $stackPtr);
     if ($modifier === false || $tokens[$modifier]['line'] !== $tokens[$stackPtr]['line']) {
         $error = 'Visibility must be declared on property "%s"';
         $data = array($tokens[$stackPtr]['content']);
         $phpcsFile->addError($error, $stackPtr, 'ScopeMissing', $data);
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:41,代码来源:PropertyDeclarationSniff.php

示例2: 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(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $find = 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) {
         $phpcsFile->addError('Missing class doc comment', $stackPtr, 'Missing');
         $phpcsFile->recordMetric($stackPtr, 'Class has doc comment', 'no');
         return;
     }
     $phpcsFile->recordMetric($stackPtr, 'Class has doc comment', 'yes');
     if ($tokens[$commentEnd]['code'] === T_COMMENT) {
         $phpcsFile->addError('You must use "/**" style comments for a class comment', $stackPtr, 'WrongStyle');
         return;
     }
     if ($tokens[$commentEnd]['line'] !== $tokens[$stackPtr]['line'] - 1) {
         $error = 'There must be no blank lines after the class comment';
         $phpcsFile->addError($error, $commentEnd, 'SpacingAfter');
     }
     $commentStart = $tokens[$commentEnd]['comment_opener'];
     foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
         $error = '%s tag is not allowed in class comment';
         $data = array($tokens[$tag]['content']);
         $phpcsFile->addWarning($error, $tag, 'TagNotAllowed', $data);
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:36,代码来源:ClassCommentSniff.php

示例3: processMemberVar

 /**
  * Processes class member variables.
  *
  * @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
  */
 protected function processMemberVar(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $memberProps = $phpcsFile->getMemberProperties($stackPtr);
     if (empty($memberProps) === true) {
         return;
     }
     $memberName = ltrim($tokens[$stackPtr]['content'], '$');
     $scope = $memberProps['scope'];
     $scopeSpecified = $memberProps['scope_specified'];
     if ($memberProps['scope'] === 'private') {
         $isPublic = false;
     } else {
         $isPublic = true;
     }
     // If it's a private member, it must have an underscore on the front.
     if ($isPublic === false && $memberName[0] !== '_') {
         $error = 'Private member variable "%s" must be prefixed with an underscore';
         $data = array($memberName);
         $phpcsFile->addError($error, $stackPtr, 'PrivateNoUnderscore', $data);
         return;
     }
     // If it's not a private member, it must not have an underscore on the front.
     if ($isPublic === true && $scopeSpecified === true && $memberName[0] === '_') {
         $error = '%s member variable "%s" must not be prefixed with an underscore';
         $data = array(ucfirst($scope), $memberName);
         $phpcsFile->addError($error, $stackPtr, 'PublicUnderscore', $data);
         return;
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:39,代码来源:ValidVariableNameSniff.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(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     if ($tokens[$stackPtr]['content'] !== 'opacity') {
         return;
     }
     $next = $phpcsFile->findNext(array(T_COLON, T_WHITESPACE), $stackPtr + 1, null, true);
     if ($next === false || $tokens[$next]['code'] !== T_DNUMBER && $tokens[$next]['code'] !== T_LNUMBER) {
         return;
     }
     $value = $tokens[$next]['content'];
     if ($tokens[$next]['code'] === T_LNUMBER) {
         if ($value !== '0' && $value !== '1') {
             $error = 'Opacity values must be between 0 and 1';
             $phpcsFile->addError($error, $next, 'Invalid');
         }
     } else {
         if (strlen($value) > 3) {
             $error = 'Opacity values must have a single value after the decimal point';
             $phpcsFile->addError($error, $next, 'DecimalPrecision');
         } else {
             if ($value === '0.0' || $value === '1.0') {
                 $error = 'Opacity value does not require decimal point; use %s instead';
                 $data = array($value[0]);
                 $fix = $phpcsFile->addFixableError($error, $next, 'PointNotRequired', $data);
                 if ($fix === true) {
                     $phpcsFile->fixer->replaceToken($next, $value[0]);
                 }
             } else {
                 if ($value[0] === '.') {
                     $error = 'Opacity values must not start with a decimal point; use 0%s instead';
                     $data = array($value);
                     $fix = $phpcsFile->addFixableError($error, $next, 'StartWithPoint', $data);
                     if ($fix === true) {
                         $phpcsFile->fixer->replaceToken($next, '0' . $value);
                     }
                 } else {
                     if ($value[0] !== '0') {
                         $error = 'Opacity values must be between 0 and 1';
                         $phpcsFile->addError($error, $next, 'Invalid');
                     }
                 }
             }
         }
         //end if
     }
     //end if
 }
开发者ID:thekabal,项目名称:tki,代码行数:57,代码来源:OpacitySniff.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(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     // Ignore abstract methods.
     if (isset($tokens[$stackPtr]['scope_opener']) === false) {
         return;
     }
     // Detect start and end of this function definition.
     $start = $tokens[$stackPtr]['scope_opener'];
     $end = $tokens[$stackPtr]['scope_closer'];
     $nestingLevel = 0;
     // Find the maximum nesting level of any token in the function.
     for ($i = $start + 1; $i < $end; $i++) {
         $level = $tokens[$i]['level'];
         if ($nestingLevel < $level) {
             $nestingLevel = $level;
         }
     }
     // We subtract the nesting level of the function itself.
     $nestingLevel = $nestingLevel - $tokens[$stackPtr]['level'] - 1;
     if ($nestingLevel > $this->absoluteNestingLevel) {
         $error = 'Function\'s nesting level (%s) exceeds allowed maximum of %s';
         $data = array($nestingLevel, $this->absoluteNestingLevel);
         $phpcsFile->addError($error, $stackPtr, 'MaxExceeded', $data);
     } else {
         if ($nestingLevel > $this->nestingLevel) {
             $warning = 'Function\'s nesting level (%s) exceeds %s; consider refactoring the function';
             $data = array($nestingLevel, $this->nestingLevel);
             $phpcsFile->addWarning($warning, $stackPtr, 'TooHigh', $data);
         }
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:41,代码来源:NestingLevelSniff.php

示例6: process

 /**
  * Processes this sniff, 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(File $phpcsFile, $stackPtr)
 {
     $fileName = $phpcsFile->getFilename();
     $matches = array();
     if (preg_match('|/systems/(.*)/([^/]+)?actions.inc$|i', $fileName, $matches) === 0) {
         // Not an actions file.
         return;
     }
     $ownClass = $matches[2];
     $tokens = $phpcsFile->getTokens();
     $typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr + 2, null, false, true);
     $typeName = trim($tokens[$typeName]['content'], " '");
     switch (strtolower($tokens[$stackPtr + 1]['content'])) {
         case 'includesystem':
             $included = strtolower($typeName);
             break;
         case 'includeasset':
             $included = strtolower($typeName) . 'assettype';
             break;
         case 'includewidget':
             $included = strtolower($typeName) . 'widgettype';
             break;
         default:
             return;
     }
     if ($included === strtolower($ownClass)) {
         $error = "You do not need to include \"%s\" from within the system's own actions file";
         $data = array($ownClass);
         $phpcsFile->addError($error, $stackPtr, 'NotRequired', $data);
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:40,代码来源:IncludeOwnSystemSniff.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(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     // Find the content of each style definition name.
     $styleNames = array();
     $next = $stackPtr;
     $end = $tokens[$stackPtr]['bracket_closer'];
     do {
         $next = $phpcsFile->findNext(array(T_STYLE, T_OPEN_CURLY_BRACKET), $next + 1, $end);
         if ($next === false) {
             // Class definition is empty.
             break;
         }
         if ($tokens[$next]['code'] === T_OPEN_CURLY_BRACKET) {
             $next = $tokens[$next]['bracket_closer'];
             continue;
         }
         $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;
         }
     } while ($next !== false);
 }
开发者ID:thekabal,项目名称:tki,代码行数:37,代码来源:DuplicateStyleDefinitionSniff.php

示例8: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The current file being processed.
  * @param int                  $stackPtr  The position of the current token in the
  *                                        stack passed in $tokens.
  *
  * @return void
  */
 public function process(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     if (isset($tokens[$stackPtr]['scope_opener']) === false) {
         $error = 'Possible parse error: %s missing opening or closing brace';
         $data = array($tokens[$stackPtr]['content']);
         $phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $data);
         return;
     }
     // Determine the name of the class or interface. Note that we cannot
     // simply look for the first T_STRING because a class name
     // starting with the number will be multiple tokens.
     $opener = $tokens[$stackPtr]['scope_opener'];
     $nameStart = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, $opener, true);
     $nameEnd = $phpcsFile->findNext(T_WHITESPACE, $nameStart, $opener);
     if ($nameEnd === false) {
         $name = $tokens[$nameStart]['content'];
     } else {
         $name = trim($phpcsFile->getTokensAsString($nameStart, $nameEnd - $nameStart));
     }
     // Check for camel caps format.
     $valid = Common::isCamelCaps($name, true, true, false);
     if ($valid === false) {
         $type = ucfirst($tokens[$stackPtr]['content']);
         $error = '%s name "%s" is not in camel caps format';
         $data = array($type, $name);
         $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $data);
         $phpcsFile->recordMetric($stackPtr, 'CamelCase class name', 'no');
     } else {
         $phpcsFile->recordMetric($stackPtr, 'CamelCase class name', 'yes');
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:41,代码来源:ValidClassNameSniff.php

示例9: 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(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     // We are only interested in the first token in a multi-line string.
     if ($tokens[$stackPtr]['code'] === $tokens[$stackPtr - 1]['code']) {
         return;
     }
     $workingString = $tokens[$stackPtr]['content'];
     $lastStringToken = $stackPtr;
     $i = $stackPtr + 1;
     if (isset($tokens[$i]) === true) {
         while ($i < $phpcsFile->numTokens && $tokens[$i]['code'] === $tokens[$stackPtr]['code']) {
             $workingString .= $tokens[$i]['content'];
             $lastStringToken = $i;
             $i++;
         }
     }
     // Check if it's a double quoted string.
     if (strpos($workingString, '"') === false) {
         return;
     }
     // Make sure it's not a part of a string started in a previous line.
     // If it is, then we have already checked it.
     if ($workingString[0] !== '"') {
         return;
     }
     // The use of variables in double quoted strings is not allowed.
     if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING) {
         $stringTokens = token_get_all('<?php ' . $workingString);
         foreach ($stringTokens as $token) {
             if (is_array($token) === true && $token[0] === T_VARIABLE) {
                 $error = 'Variable "%s" not allowed in double quoted string; use concatenation instead';
                 $data = array($token[1]);
                 $phpcsFile->addError($error, $stackPtr, 'ContainsVar', $data);
             }
         }
         return;
     }
     //end if
     $allowedChars = array('\\0', '\\1', '\\2', '\\3', '\\4', '\\5', '\\6', '\\7', '\\n', '\\r', '\\f', '\\t', '\\v', '\\x', '\\b', '\\e', '\\u', '\'');
     foreach ($allowedChars as $testChar) {
         if (strpos($workingString, $testChar) !== false) {
             return;
         }
     }
     $error = 'String %s does not require double quotes; use single quotes instead';
     $data = array(str_replace("\n", '\\n', $workingString));
     $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotRequired', $data);
     if ($fix === true) {
         $phpcsFile->fixer->beginChangeset();
         $innerContent = substr($workingString, 1, -1);
         $innerContent = str_replace('\\"', '"', $innerContent);
         $phpcsFile->fixer->replaceToken($stackPtr, "'{$innerContent}'");
         while ($lastStringToken !== $stackPtr) {
             $phpcsFile->fixer->replaceToken($lastStringToken, '');
             $lastStringToken--;
         }
         $phpcsFile->fixer->endChangeset();
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:69,代码来源:DoubleQuoteUsageSniff.php

示例10: 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(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:thekabal,项目名称:tki,代码行数:39,代码来源:DisallowObjectStringIndexSniff.php

示例11: processTokenWithinScope

 /**
  * Processes the function tokens within the class.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
  * @param int                  $stackPtr  The position where the token was found.
  * @param int                  $currScope The current scope opener token.
  *
  * @return void
  */
 protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
 {
     $tokens = $phpcsFile->getTokens();
     $methodName = $phpcsFile->getDeclarationName($stackPtr);
     if ($methodName === null) {
         // Ignore closures.
         return;
     }
     if ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true) {
         // Ignore nested functions.
         return;
     }
     $modifier = null;
     for ($i = $stackPtr - 1; $i > 0; $i--) {
         if ($tokens[$i]['line'] < $tokens[$stackPtr]['line']) {
             break;
         } else {
             if (isset(Tokens::$scopeModifiers[$tokens[$i]['code']]) === true) {
                 $modifier = $i;
                 break;
             }
         }
     }
     if ($modifier === null) {
         $error = 'Visibility must be declared on method "%s"';
         $data = array($methodName);
         $phpcsFile->addError($error, $stackPtr, 'Missing', $data);
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:38,代码来源:MethodScopeSniff.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(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     if ($tokens[$stackPtr]['content'] === 'ob_end_flush') {
         $phpcsFile->addError('Use of ob_end_flush() is not allowed; use ob_get_contents() and ob_end_clean() instead', $stackPtr, 'Found');
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:16,代码来源:DisallowObEndFlushSniff.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(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     // Ignore this.something and other uses of "this" that are not
     // direct assignments.
     $next = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
     if ($tokens[$next]['code'] !== T_SEMICOLON) {
         if ($tokens[$next]['line'] === $tokens[$stackPtr]['line']) {
             return;
         }
     }
     // Something must be assigned to "this".
     $prev = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
     if ($tokens[$prev]['code'] !== T_EQUAL) {
         return;
     }
     // A variable needs to be assigned to "this".
     $prev = $phpcsFile->findPrevious(T_WHITESPACE, $prev - 1, null, true);
     if ($tokens[$prev]['code'] !== T_STRING) {
         return;
     }
     // We can only assign "this" to a var called "self".
     if ($tokens[$prev]['content'] !== 'self' && $tokens[$prev]['content'] !== '_self') {
         $error = 'Keyword "this" can only be assigned to a variable called "self" or "_self"';
         $phpcsFile->addError($error, $prev, 'NotSelf');
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:36,代码来源:AssignThisSniff.php

示例14: 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(File $phpcsFile, $stackPtr)
 {
     $this->currentFile = $phpcsFile;
     $tokens = $phpcsFile->getTokens();
     // Ignore abstract methods.
     if (isset($tokens[$stackPtr]['scope_opener']) === false) {
         return;
     }
     // Detect start and end of this function definition.
     $start = $tokens[$stackPtr]['scope_opener'];
     $end = $tokens[$stackPtr]['scope_closer'];
     // Predicate nodes for PHP.
     $find = array(T_CASE => true, T_DEFAULT => true, T_CATCH => true, T_IF => true, T_FOR => true, T_FOREACH => true, T_WHILE => true, T_DO => true, T_ELSEIF => true);
     $complexity = 1;
     // Iterate from start to end and count predicate nodes.
     for ($i = $start + 1; $i < $end; $i++) {
         if (isset($find[$tokens[$i]['code']]) === true) {
             $complexity++;
         }
     }
     if ($complexity > $this->absoluteComplexity) {
         $error = 'Function\'s cyclomatic complexity (%s) exceeds allowed maximum of %s';
         $data = array($complexity, $this->absoluteComplexity);
         $phpcsFile->addError($error, $stackPtr, 'MaxExceeded', $data);
     } else {
         if ($complexity > $this->complexity) {
             $warning = 'Function\'s cyclomatic complexity (%s) exceeds %s; consider refactoring the function';
             $data = array($complexity, $this->complexity);
             $phpcsFile->addWarning($warning, $stackPtr, 'TooHigh', $data);
         }
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:41,代码来源:CyclomaticComplexitySniff.php

示例15: 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(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $lastLine = $tokens[$stackPtr]['line'];
     $end = $tokens[$stackPtr]['bracket_closer'];
     $endLine = $tokens[$end]['line'];
     // Do not check nested style definitions as, for example, in @media style rules.
     $nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $stackPtr + 1, $end);
     if ($nested !== false) {
         return;
     }
     $foundColon = false;
     $foundString = false;
     for ($i = $stackPtr + 1; $i <= $end; $i++) {
         if ($tokens[$i]['line'] !== $lastLine) {
             // We changed lines.
             if ($foundColon === false && $foundString !== false) {
                 // We didn't find a colon on the previous line.
                 $error = 'No style definition found on line; check for missing colon';
                 $phpcsFile->addError($error, $foundString, 'Found');
             }
             $foundColon = false;
             $foundString = false;
             $lastLine = $tokens[$i]['line'];
         }
         if ($tokens[$i]['code'] === T_STRING) {
             $foundString = $i;
         } else {
             if ($tokens[$i]['code'] === T_COLON) {
                 $foundColon = $i;
             }
         }
     }
     //end for
 }
开发者ID:thekabal,项目名称:tki,代码行数:44,代码来源:MissingColonSniff.php


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