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


PHP PHP_CodeSniffer_File::addError方法代码示例

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


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

示例1: 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();
     // Make sure this is the first PHP open tag so we don't process
     // the same file twice.
     $prevOpenTag = $phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1);
     if ($prevOpenTag !== false) {
         return;
     }
     $fileName = $phpcsFile->getFileName();
     $extension = substr($fileName, strrpos($fileName, '.'));
     $nextClass = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE), $stackPtr);
     if ($extension === '.php') {
         if ($nextClass !== false) {
             $error = '%s found in ".php" file; use ".inc" extension instead';
             $data = array(ucfirst($tokens[$nextClass]['content']));
             $phpcsFile->addError($error, $stackPtr, 'ClassFound', $data);
         }
     } else {
         if ($extension === '.inc') {
             if ($nextClass === false) {
                 $error = 'No interface or class found in ".inc" file; use ".php" extension instead';
                 $phpcsFile->addError($error, $stackPtr, 'NoClass');
             }
         }
     }
 }
开发者ID:CobaltBlueDW,项目名称:oddsandends,代码行数:36,代码来源:FileExtensionSniff.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
  *                                        stack passed in $tokens.
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     // Process !! casts
     if ($tokens[$stackPtr]['code'] == T_BOOLEAN_NOT) {
         $nextToken = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
         if (!$nextToken) {
             return;
         }
         if ($tokens[$nextToken]['code'] != T_BOOLEAN_NOT) {
             return;
         }
         $error = 'Usage of !! cast is not allowed. Please use (bool) to cast.';
         $phpcsFile->addError($error, $stackPtr, 'NotAllowed');
         return;
     }
     // Only allow short forms if both short and long forms are possible
     $matching = array('(boolean)' => '(bool)', '(integer)' => '(int)');
     $content = $tokens[$stackPtr]['content'];
     $key = strtolower($content);
     if (isset($matching[$key])) {
         $error = 'Please use ' . $matching[$key] . ' instead of ' . $content . '.';
         $phpcsFile->addError($error, $stackPtr, 'NotAllowed');
         return;
     }
     if ($content !== $key) {
         $error = 'Please use ' . $key . ' instead of ' . $content . '.';
         $phpcsFile->addError($error, $stackPtr, 'NotAllowed');
         return;
     }
 }
开发者ID:gjcamacho,项目名称:blog_test,代码行数:39,代码来源:TypeCastingSniff.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)
 {
     $tokens = $phpcsFile->getTokens();
     if ($tokens[$stackPtr - 1]['code'] !== T_WHITESPACE) {
         $error = 'Expected 1 space before opening brace of class definition; 0 found';
         $phpcsFile->addError($error, $stackPtr);
     } else {
         $content = $tokens[$stackPtr - 1]['content'];
         if ($content !== ' ') {
             $length = strlen($content);
             if ($length === 1) {
                 $length = 'tab';
             }
             $error = "Expected 1 space before opening brace of class definition; {$length} found";
             $phpcsFile->addError($error, $stackPtr);
         }
     }
     //end if
     $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true);
     if ($next !== false && $tokens[$next]['line'] !== $tokens[$stackPtr]['line'] + 1) {
         $num = $tokens[$next]['line'] - $tokens[$stackPtr]['line'] - 1;
         $error = "Expected 0 blank lines after opening brace of class definition; {$num} found";
         $phpcsFile->addError($error, $stackPtr);
     }
 }
开发者ID:Rud5G,项目名称:CodeStandards,代码行数:34,代码来源:ClassDefinitionOpeningBraceSpaceSniff.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)
 {
     // Only run this sniff once per info file.
     $end = count($phpcsFile->getTokens()) + 1;
     $fileExtension = strtolower(substr($phpcsFile->getFilename(), -4));
     if ($fileExtension !== 'info') {
         return $end;
     }
     $tokens = $phpcsFile->getTokens();
     $contents = file_get_contents($phpcsFile->getFilename());
     $info = Drupal_Sniffs_InfoFiles_ClassFilesSniff::drupalParseInfoFormat($contents);
     if (isset($info['name']) === false) {
         $error = '"name" property is missing in the info file';
         $phpcsFile->addError($error, $stackPtr, 'Name');
     }
     if (isset($info['description']) === false) {
         $error = '"description" property is missing in the info file';
         $phpcsFile->addError($error, $stackPtr, 'Description');
     }
     if (isset($info['core']) === false) {
         $error = '"core" property is missing in the info file';
         $phpcsFile->addError($error, $stackPtr, 'Core');
     } else {
         if ($info['core'] === '7.x' && isset($info['php']) === true && $info['php'] <= '5.2') {
             $error = 'Drupal 7 core already requires PHP 5.2';
             $ptr = Drupal_Sniffs_InfoFiles_ClassFilesSniff::getPtr('php', $info['php'], $phpcsFile);
             $phpcsFile->addError($error, $ptr, 'D7PHPVersion');
         }
     }
     return $end;
 }
开发者ID:atif-shaikh,项目名称:DCX-Profile,代码行数:40,代码来源:RequiredSniff.php

示例5: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $path = $phpcsFile->getFileName();
     if (!preg_match("/(views)/i", $path)) {
         return;
     }
     $tokens = $phpcsFile->getTokens();
     $classname = $tokens[$phpcsFile->findNext(T_STRING, $stackPtr)]['content'];
     if (preg_match("/(helpers)/i", $path)) {
         $final_classname = $this->classname_without_type($classname, "Helper");
         $msg_on_error = "Cake convention expects the helper class name to end with 'Helper'";
     } else {
         $final_classname = $this->classname_with_type($classname, "View");
         $msg_on_error = "Cake convention expects the view class name to end with 'View'";
     }
     if (is_null($final_classname)) {
         $phpcsFile->addError($msg_on_error, $stackPtr);
         return;
     }
     $expected_file_name = preg_replace('/([A-Z])/', '_${1}', $final_classname);
     if (strpos($expected_file_name, "_") === 0) {
         $expected_file_name = substr($expected_file_name, 1, strlen($expected_file_name));
     }
     $expected_file_name = strtolower($expected_file_name) . ".php";
     if (!preg_match("/" . $expected_file_name . "/", $path)) {
         $error = "File name is expected to be, '" . $expected_file_name . "' for Class with name, '" . $classname . "'";
         $phpcsFile->addError($error, $stackPtr);
     }
 }
开发者ID:venkatrs,项目名称:Cake_PHP_CodeSniffer,代码行数:38,代码来源:ViewsFileNameSniff.php

示例6: 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 not allowed; use "__construct()" instead';
         $phpcsFile->addError($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 not allowed; use "parent::__construct()" instead';
             $phpcsFile->addError($error, $doubleColonIndex + 1, 'OldStyleCall');
         }
         $startIndex = $doubleColonIndex + 1;
     }
 }
开发者ID:sunnystone85,项目名称:CsPCHookSugar,代码行数:38,代码来源:ConstructorNameSniff.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)
 {
     $tokens = $phpcsFile->getTokens();
     $next = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
     if ($next === false) {
         return;
     }
     if ($tokens[$next]['code'] !== T_CLOSE_TAG) {
         $found = $tokens[$next]['line'] - $tokens[$stackPtr]['line'] - 1;
         if ($found !== 1) {
             $error = 'Expected one blank line after closing brace of class definition; %s found';
             $data = array($found);
             $phpcsFile->addError($error, $stackPtr, 'SpacingAfterClose', $data);
         }
     }
     // Ignore nested style definitions from here on. The spacing before the closing brace
     // (a single blank line) will be enforced by the above check, which ensures there is a
     // blank line after the last nested class.
     $found = $phpcsFile->findPrevious(T_CLOSE_CURLY_BRACKET, $stackPtr - 1, $tokens[$stackPtr]['bracket_opener']);
     if ($found !== false) {
         return;
     }
     $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr - 1, null, true);
     if ($prev !== false && $tokens[$prev]['line'] !== $tokens[$stackPtr]['line'] - 1) {
         $num = $tokens[$stackPtr]['line'] - $tokens[$prev]['line'] - 1;
         $error = 'Expected 0 blank lines before closing brace of class definition; %s found';
         $data = array($num);
         $phpcsFile->addError($error, $stackPtr, 'SpacingBeforeClose', $data);
     }
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:39,代码来源:ClassDefinitionClosingBraceSpaceSniff.php

示例8: process

 /**
  * Processes this sniff, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The current file being checked.
  * @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();
     // No bracket can have space before them.
     $prevType = $tokens[$stackPtr - 1]['code'];
     if (in_array($prevType, PHP_CodeSniffer_Tokens::$emptyTokens) === true) {
         $nonSpace = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr - 2, null, true);
         $expected = $tokens[$nonSpace]['content'] . $tokens[$stackPtr]['content'];
         $found = $phpcsFile->getTokensAsString($nonSpace, $stackPtr - $nonSpace) . $tokens[$stackPtr]['content'];
         $error = 'Space found before square bracket; expected "%s" but found "%s"';
         $data = array($expected, $found);
         $phpcsFile->addError($error, $stackPtr, 'SpaceBeforeBracket', $data);
     }
     if ($tokens[$stackPtr]['type'] === 'T_OPEN_SQUARE_BRACKET') {
         // Open brackets can't have spaces on after them either.
         $nextType = $tokens[$stackPtr + 1]['code'];
         if (in_array($nextType, PHP_CodeSniffer_Tokens::$emptyTokens) === true) {
             $nonSpace = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 2, null, true);
             $expected = $tokens[$stackPtr]['content'] . $tokens[$nonSpace]['content'];
             $found = $phpcsFile->getTokensAsString($stackPtr, $nonSpace - $stackPtr + 1);
             $error = 'Space found after square bracket; expected "%s" but found "%s"';
             $data = array($expected, $found);
             $phpcsFile->addError($error, $stackPtr, 'SpaceAfterBracket', $data);
         }
     }
 }
开发者ID:master3395,项目名称:CBPPlatform,代码行数:35,代码来源:ArrayBracketSpacingSniff.php

示例9: 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(PHP_CodeSniffer_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 = PHP_CodeSniffer_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(PHP_CodeSniffer_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:EngrHaiderAli,项目名称:movein-servie,代码行数:41,代码来源:PropertyDeclarationSniff.php

示例10: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $keyword = $tokens[$stackPtr]['content'];
     $tokenCode = $tokens[$stackPtr]['type'];
     switch ($tokenCode) {
         case 'T_INCLUDE_ONCE':
             // Here we are looking if the found include_once keyword is
             // part of an XClass declaration where this is allowed.
             if ($tokens[$stackPtr + 7]['content'] === "'XCLASS'") {
                 return;
             }
             $error = 'Including files with "' . $keyword . '" is not allowed; ';
             $error .= 'use "require_once" instead';
             $phpcsFile->addError($error, $stackPtr);
             break;
         case 'T_REQUIRE':
             $error = 'Including files with "' . $keyword . '" is not allowed; ';
             $error .= 'use "require_once" instead';
             $phpcsFile->addError($error, $stackPtr);
             break;
         case 'T_INCLUDE':
             $error = 'Including files with "' . $keyword . '" is not allowed; ';
             $error .= 'use "require_once" instead';
             $phpcsFile->addError($error, $stackPtr);
             break;
         default:
     }
     //end switch
 }
开发者ID:typo3-ci,项目名称:typo3sniffpool,代码行数:39,代码来源:IncludingFileSniff.php

示例11: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $trait = $phpcsFile->findNext(T_STRING, $stackPtr);
     $name = $tokens[$trait]['content'];
     if (preg_match('|^[A-Z]|', $name) === 0) {
         $error = 'Each %s name must begin with a capital letter';
         $errorData = array($tokens[$stackPtr]['content']);
         $phpcsFile->addError($error, $stackPtr, 'StartWithCapital', $errorData);
     }
     if ($this->allowUnderscore === true) {
         if (preg_match('|_[a-z]|', $name)) {
             $error = 'Trait "%s" is not in camel caps with underscores format';
             $phpcsFile->addError($error, $stackPtr, 'CamelCapsWithUnderscore', array($name));
         }
         $name = lcfirst(str_replace('_', '', $name));
     } else {
         if (strpos($name, '_') !== FALSE) {
             $error = 'Underscores are not allowed in trait "%s"';
             $phpcsFile->addError($error, $stackPtr, 'NoUnderscore', array($name));
         }
         $name = array(lcfirst($name));
     }
     if (PHP_CodeSniffer::isCamelCaps($name, false, true, true) === false) {
         $error = 'Trait "%s" is not in camel caps format';
         $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', array($name));
     }
 }
开发者ID:iuliann,项目名称:spartan-cs,代码行数:37,代码来源:ValidTraitNameSniff.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)
 {
     $this->requiredSpacesAfterOpen = (int) $this->requiredSpacesAfterOpen;
     $this->requiredSpacesBeforeClose = (int) $this->requiredSpacesBeforeClose;
     $tokens = $phpcsFile->getTokens();
     if (isset($tokens[$stackPtr]['parenthesis_opener']) === true && isset($tokens[$stackPtr]['parenthesis_closer']) === true) {
         $parenOpener = $tokens[$stackPtr]['parenthesis_opener'];
         $parenCloser = $tokens[$stackPtr]['parenthesis_closer'];
         $spaceAfterOpen = 0;
         if ($tokens[$parenOpener + 1]['code'] === T_WHITESPACE) {
             $spaceAfterOpen = strlen(rtrim($tokens[$parenOpener + 1]['content'], $phpcsFile->eolChar));
         }
         if ($spaceAfterOpen !== $this->requiredSpacesAfterOpen) {
             $error = 'Expected %s spaces after opening bracket; %s found';
             $data = array($this->requiredSpacesAfterOpen, $spaceAfterOpen);
             $phpcsFile->addError($error, $parenOpener + 1, 'SpacingAfterOpenBrace', $data);
         }
         if ($tokens[$parenOpener]['line'] === $tokens[$parenCloser]['line']) {
             $spaceBeforeClose = 0;
             if ($tokens[$parenCloser - 1]['code'] === T_WHITESPACE) {
                 $spaceBeforeClose = strlen(ltrim($tokens[$parenCloser - 1]['content'], $phpcsFile->eolChar));
             }
             if ($spaceBeforeClose !== $this->requiredSpacesBeforeClose) {
                 $error = 'Expected %s spaces before closing bracket; %s found';
                 $data = array($this->requiredSpacesBeforeClose, $spaceBeforeClose);
                 $phpcsFile->addError($error, $parenCloser - 1, 'SpaceBeforeCloseBrace', $data);
             }
         }
     }
     //end if
 }
开发者ID:SebFav,项目名称:ApplicationInternet2,代码行数:40,代码来源:ControlStructureSpacingSniff.php

示例13: processTokenWithinScope

 /**
  * Processes the tokens within the scope.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being processed.
  * @param int                  $stackPtr  The position where this token was
  *                                        found.
  * @param int                  $currScope The position of the current scope.
  *
  * @return void
  */
 protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
 {
     $methodName = $phpcsFile->getDeclarationName($stackPtr);
     if ($methodName === null) {
         // Ignore closures.
         return;
     }
     $className = $phpcsFile->getDeclarationName($currScope);
     $errorData = array($className . '::' . $methodName);
     // Is this a magic method. IE. is prefixed with "__".
     if (preg_match('|^__|', $methodName) !== 0) {
         $magicPart = substr($methodName, 2);
         if (in_array($magicPart, $this->magicMethods) === false) {
             $error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
             $phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData);
         }
         return;
     }
     $methodProps = $phpcsFile->getMethodProperties($stackPtr);
     $scope = $methodProps['scope'];
     $scopeSpecified = $methodProps['scope_specified'];
     // Methods should not contain underscores.
     if (strpos($methodName, '_') !== false) {
         if ($scopeSpecified === true) {
             $error = '%s method name "%s" is not in lowerCamel format, it must not contain underscores';
             $data = array(ucfirst($scope), $errorData[0]);
             $phpcsFile->addError($error, $stackPtr, 'ScopeNotLowerCamel', $data);
         } else {
             $error = 'Method name "%s" is not in lowerCamel format, it must not contain underscores';
             $phpcsFile->addError($error, $stackPtr, 'NotLowerCamel', $errorData);
         }
     }
 }
开发者ID:ecs-hk,项目名称:Checkbook,代码行数:43,代码来源:ValidFunctionNameSniff.php

示例14: 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 stack passed in $tokens.
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     if (isset($tokens[$stackPtr]['scope_closer']) === false) {
         // Probably an interface method.
         return;
     }
     $closeBrace = $tokens[$stackPtr]['scope_closer'];
     $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, $closeBrace - 1, null, true);
     $braceLine = $tokens[$closeBrace]['line'];
     $prevLine = $tokens[$prevContent]['line'];
     $found = $braceLine - $prevLine - 1;
     if ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true || isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
         // Nested function.
         if ($found < 0) {
             $error = 'Closing brace of nested function must be on a new line';
             $phpcsFile->addError($error, $closeBrace, 'ContentBeforeClose');
         } elseif ($found > 0) {
             $error = 'Expected 0 blank lines before closing brace of nested function; %s found';
             $data = array($found);
             $phpcsFile->addError($error, $closeBrace, 'SpacingBeforeNestedClose', $data);
         }
     } else {
         if ($found !== 0) {
             $error = 'Expected 0 blank lines before closing function brace; %s found';
             $data = array($found);
             $phpcsFile->addError($error, $closeBrace, 'SpacingBeforeClose', $data);
         }
     }
 }
开发者ID:ciricihq,项目名称:cirici-codesniffer,代码行数:38,代码来源:FunctionClosingBraceSpaceSniff.php

示例15: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * Operations to check for:
  * $i = 1 + 1;
  * $i = $i + 1;
  * $i = (1 + 1) - 1;
  *
  * Operations to ignore:
  * array($i => -1);
  * $i = -1;
  * range(-10, -1);
  *
  * @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();
     $has_equality_token = in_array($tokens[$stackPtr - 2]['code'], PHP_CodeSniffer_Tokens::$equalityTokens);
     // Ensure this is a construct to check.
     $lastSyntaxItem = $phpcsFile->findPrevious(array(T_WHITESPACE), $stackPtr - 1, $tokens[$stackPtr]['column'] * -1, true, NULL, true);
     $needs_operator_suffix = in_array($tokens[$lastSyntaxItem]['code'], array(T_LNUMBER, T_DNUMBER, T_CLOSE_PARENTHESIS, T_CLOSE_SQUARE_BRACKET, T_CLOSE_CURLY_BRACKET, T_VARIABLE, T_STRING, T_CONSTANT_ENCAPSED_STRING));
     $needs_operator_prefix = !in_array($tokens[$lastSyntaxItem]['code'], array(T_OPEN_PARENTHESIS, T_EQUAL));
     if ($needs_operator_suffix && ($tokens[$stackPtr - 2]['code'] !== T_EQUAL && $tokens[$stackPtr - 2]['code'] !== T_DOUBLE_ARROW && !$has_equality_token && !($tokens[$stackPtr]['code'] === T_EQUAL && $tokens[$stackPtr + 1]['code'] === T_BITWISE_AND) && ($tokens[$stackPtr + 1]['code'] !== T_WHITESPACE || $tokens[$stackPtr + 1]['content'] != ' '))) {
         $error = 'An operator statement must be followed by a single space';
         $phpcsFile->addError($error, $stackPtr);
     }
     if ($needs_operator_prefix) {
         $error = false;
         if ($tokens[$stackPtr - 1]['code'] !== T_WHITESPACE) {
             $error = true;
         } else {
             if ($tokens[$stackPtr - 1]['content'] !== ' ' && $tokens[$stackPtr]['code'] !== T_EQUAL) {
                 $nonWhiteSpace = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr - 1, null, true);
                 // Make sure that the previous operand is on the same line before
                 // throwing an error.
                 if ($tokens[$nonWhiteSpace]['line'] === $tokens[$stackPtr]['line']) {
                     $error = true;
                 }
             }
         }
         if ($error === true) {
             $error = 'There must be a single space before an operator statement';
             $phpcsFile->addError($error, $stackPtr);
         }
     }
     //end if
 }
开发者ID:CobaltBlueDW,项目名称:oddsandends,代码行数:52,代码来源:SpaceOperatorSniff.php


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