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


PHP File::recordMetric方法代码示例

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


在下文中一共展示了File::recordMetric方法的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(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $firstContent = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
     // If the first non-whitespace token is not an opening parenthesis, then we are not concerned.
     if ($tokens[$firstContent]['code'] !== T_OPEN_PARENTHESIS) {
         $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
         return;
     }
     $end = $phpcsFile->findNext(array(T_SEMICOLON, T_CLOSE_TAG), $stackPtr, null, false);
     // If the token before the semi-colon is not a closing parenthesis, then we are not concerned.
     $prev = $phpcsFile->findPrevious(T_WHITESPACE, $end - 1, null, true);
     if ($tokens[$prev]['code'] !== T_CLOSE_PARENTHESIS) {
         $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
         return;
     }
     // If the parenthesis don't match, then we are not concerned.
     if ($tokens[$firstContent]['parenthesis_closer'] !== $prev) {
         $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
         return;
     }
     $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'yes');
     if ($phpcsFile->findNext(Tokens::$operators, $stackPtr, $end, false) === false) {
         // There are no arithmetic operators in this.
         $error = 'Echoed strings should not be bracketed';
         $fix = $phpcsFile->addFixableError($error, $stackPtr, 'HasBracket');
         if ($fix === true) {
             $phpcsFile->fixer->beginChangeset();
             $phpcsFile->fixer->replaceToken($firstContent, '');
             $phpcsFile->fixer->replaceToken($end - 1, '');
             $phpcsFile->fixer->endChangeset();
         }
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:43,代码来源:EchoedStringsSniff.php

示例2: 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)
 {
     $tokens = $phpcsFile->getTokens();
     // Make sure this file only contains PHP code.
     for ($i = 0; $i < $phpcsFile->numTokens; $i++) {
         if ($tokens[$i]['code'] === T_INLINE_HTML && trim($tokens[$i]['content']) !== '') {
             return $phpcsFile->numTokens;
         }
     }
     // Find the last non-empty token.
     for ($last = $phpcsFile->numTokens - 1; $last > 0; $last--) {
         if (trim($tokens[$last]['content']) !== '') {
             break;
         }
     }
     if ($tokens[$last]['code'] === T_CLOSE_TAG) {
         $error = 'A closing tag is not permitted at the end of a PHP file';
         $fix = $phpcsFile->addFixableError($error, $last, 'NotAllowed');
         if ($fix === true) {
             $phpcsFile->fixer->beginChangeset();
             $phpcsFile->fixer->replaceToken($last, $phpcsFile->eolChar);
             $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, $last - 1, null, true);
             if ($tokens[$prev]['code'] !== T_SEMICOLON && $tokens[$prev]['code'] !== T_CLOSE_CURLY_BRACKET) {
                 $phpcsFile->fixer->addContent($prev, ';');
             }
             $phpcsFile->fixer->endChangeset();
         }
         $phpcsFile->recordMetric($stackPtr, 'PHP closing tag at end of PHP-only file', 'yes');
     } else {
         $phpcsFile->recordMetric($stackPtr, 'PHP closing tag at end of PHP-only file', 'no');
     }
     // Ignore the rest of the file.
     return $phpcsFile->numTokens;
 }
开发者ID:thekabal,项目名称:tki,代码行数:43,代码来源:ClosingTagSniff.php

示例3: 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(File $phpcsFile, $stackPtr, $currScope)
 {
     $methodName = $phpcsFile->getDeclarationName($stackPtr);
     if ($methodName === null) {
         // Ignore closures.
         return;
     }
     // Ignore magic methods.
     if (preg_match('|^__|', $methodName) !== 0) {
         $magicPart = strtolower(substr($methodName, 2));
         if (isset($this->magicMethods[$magicPart]) === true || isset($this->methodsDoubleUnderscore[$magicPart]) === true) {
             return;
         }
     }
     $testName = ltrim($methodName, '_');
     if ($testName !== '' && Common::isCamelCaps($testName, false, true, false) === false) {
         $error = 'Method name "%s" is not in camel caps format';
         $className = $phpcsFile->getDeclarationName($currScope);
         $errorData = array($className . '::' . $methodName);
         $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
         $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no');
     } else {
         $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:35,代码来源:CamelCapsMethodNameSniff.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(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

示例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();
     $openTag = $tokens[$stackPtr];
     if ($openTag['content'] === '<?') {
         $error = 'Short PHP opening tag used; expected "<?php" but found "%s"';
         $data = array($openTag['content']);
         $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data);
         if ($fix === true) {
             $phpcsFile->fixer->replaceToken($stackPtr, '<?php');
         }
         $phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'yes');
     } else {
         $phpcsFile->recordMetric($stackPtr, 'PHP short open tag used', 'no');
     }
     if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO) {
         $nextVar = $tokens[$phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true)];
         $error = 'Short PHP opening tag used with echo; expected "<?php echo %s ..." but found "%s %s ..."';
         $data = array($nextVar['content'], $openTag['content'], $nextVar['content']);
         $fix = $phpcsFile->addFixableError($error, $stackPtr, 'EchoFound', $data);
         if ($fix === true) {
             if ($tokens[$stackPtr + 1]['code'] !== T_WHITESPACE) {
                 $phpcsFile->fixer->replaceToken($stackPtr, '<?php echo ');
             } else {
                 $phpcsFile->fixer->replaceToken($stackPtr, '<?php echo');
             }
         }
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:38,代码来源:DisallowShortOpenTagSniff.php

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

示例7: 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 int
  */
 public function process(File $phpcsFile, $stackPtr)
 {
     $found = $phpcsFile->eolChar;
     $found = str_replace("\n", '\\n', $found);
     $found = str_replace("\r", '\\r', $found);
     $phpcsFile->recordMetric($stackPtr, 'EOL char', $found);
     if ($found === $this->eolChar) {
         // Ignore the rest of the file.
         return $phpcsFile->numTokens + 1;
     }
     // Check for single line files without an EOL. This is a very special
     // case and the EOL char is set to \n when this happens.
     if ($found === '\\n') {
         $tokens = $phpcsFile->getTokens();
         $lastToken = $phpcsFile->numTokens - 1;
         if ($tokens[$lastToken]['line'] === 1 && $tokens[$lastToken]['content'] !== "\n") {
             return;
         }
     }
     $error = 'End of line character is invalid; expected "%s" but found "%s"';
     $expected = $this->eolChar;
     $expected = str_replace("\n", '\\n', $expected);
     $expected = str_replace("\r", '\\r', $expected);
     $data = array($expected, $found);
     // Errors are always reported on line 1, no matter where the first PHP tag is.
     $fix = $phpcsFile->addFixableError($error, 0, 'InvalidEOLChar', $data);
     if ($fix === true) {
         $tokens = $phpcsFile->getTokens();
         switch ($this->eolChar) {
             case '\\n':
                 $eolChar = "\n";
                 break;
             case '\\r':
                 $eolChar = "\r";
                 break;
             case '\\r\\n':
                 $eolChar = "\r\n";
                 break;
             default:
                 $eolChar = $this->eolChar;
                 break;
         }
         for ($i = 0; $i < $phpcsFile->numTokens; $i++) {
             if (isset($tokens[$i + 1]) === false || $tokens[$i + 1]['line'] > $tokens[$i]['line']) {
                 // Token is the last on a line.
                 if (isset($tokens[$i]['orig_content']) === true) {
                     $tokenContent = $tokens[$i]['orig_content'];
                 } else {
                     $tokenContent = $tokens[$i]['content'];
                 }
                 $newContent = rtrim($tokenContent, "\r\n");
                 $newContent .= $eolChar;
                 $phpcsFile->fixer->replaceToken($i, $newContent);
             }
         }
     }
     //end if
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
开发者ID:thekabal,项目名称:tki,代码行数:69,代码来源:LineEndingsSniff.php

示例8: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
  * @param int                  $stackPtr  The position of the current token in
  *                                        the stack passed in $tokens.
  *
  * @return void
  */
 public function process(File $phpcsFile, $stackPtr)
 {
     if ($this->tabWidth === null) {
         if (isset($phpcsFile->config->tabWidth) === false || $phpcsFile->config->tabWidth === 0) {
             // We have no idea how wide tabs are, so assume 4 spaces for fixing.
             // It shouldn't really matter because indent checks elsewhere in the
             // standard should fix things up.
             $this->tabWidth = 4;
         } else {
             $this->tabWidth = $phpcsFile->config->tabWidth;
         }
     }
     $checkTokens = array(T_WHITESPACE => true, T_INLINE_HTML => true, T_DOC_COMMENT_WHITESPACE => true);
     $tokens = $phpcsFile->getTokens();
     for ($i = $stackPtr + 1; $i < $phpcsFile->numTokens; $i++) {
         if ($tokens[$i]['column'] !== 1 || isset($checkTokens[$tokens[$i]['code']]) === false) {
             continue;
         }
         // If tabs are being converted to spaces, the original content
         // should be used instead of the converted content.
         if (isset($tokens[$i]['orig_content']) === true) {
             $content = $tokens[$i]['orig_content'];
         } else {
             $content = $tokens[$i]['content'];
         }
         if ($content[0] === ' ') {
             if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE && $content === ' ') {
                 // Ignore file/class-level DocBlock.
                 continue;
             }
             // Space are considered ok if they are proceeded by tabs and not followed
             // by tabs, as is the case with standard docblock comments.
             $phpcsFile->recordMetric($i, 'Line indent', 'spaces');
             $error = 'Tabs must be used to indent lines; spaces are not allowed';
             $fix = $phpcsFile->addFixableError($error, $i, 'SpacesUsed');
             if ($fix === true) {
                 $trimmed = ltrim($content, ' ');
                 $numSpaces = strlen($content) - strlen($trimmed);
                 if ($numSpaces < $this->tabWidth) {
                     $numTabs = 1;
                     $padding = "\t";
                 } else {
                     $numTabs = floor($numSpaces / $this->tabWidth);
                     $remaining = $numSpaces - $numTabs * $this->tabWidth;
                     $padding = str_repeat("\t", $numTabs) . ($padding = str_repeat(' ', $remaining));
                 }
                 $phpcsFile->fixer->replaceToken($i, $padding . $trimmed);
             }
         } else {
             if ($content[0] === "\t") {
                 $phpcsFile->recordMetric($i, 'Line indent', 'tabs');
             }
         }
         //end if
     }
     //end for
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
开发者ID:thekabal,项目名称:tki,代码行数:68,代码来源:DisallowSpaceIndentSniff.php

示例9: 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)
 {
     if ($phpcsFile->findNext(T_INLINE_HTML, $stackPtr + 1) !== false) {
         return $phpcsFile->numTokens + 1;
     }
     // Skip to the end of the file.
     $tokens = $phpcsFile->getTokens();
     $lastToken = $phpcsFile->numTokens - 1;
     // Hard-coding the expected \n in this sniff as it is PSR-2 specific and
     // PSR-2 enforces the use of unix style newlines.
     if (substr($tokens[$lastToken]['content'], -1) !== "\n") {
         $error = 'Expected 1 newline at end of file; 0 found';
         $fix = $phpcsFile->addFixableError($error, $lastToken, 'NoneFound');
         if ($fix === true) {
             $phpcsFile->fixer->addNewline($lastToken);
         }
         $phpcsFile->recordMetric($stackPtr, 'Number of newlines at EOF', '0');
         return $phpcsFile->numTokens + 1;
     }
     // Go looking for the last non-empty line.
     $lastLine = $tokens[$lastToken]['line'];
     if ($tokens[$lastToken]['code'] === T_WHITESPACE) {
         $lastCode = $phpcsFile->findPrevious(T_WHITESPACE, $lastToken - 1, null, true);
     } else {
         $lastCode = $lastToken;
     }
     $lastCodeLine = $tokens[$lastCode]['line'];
     $blankLines = $lastLine - $lastCodeLine + 1;
     $phpcsFile->recordMetric($stackPtr, 'Number of newlines at EOF', $blankLines);
     if ($blankLines > 1) {
         $error = 'Expected 1 blank line at end of file; %s found';
         $data = array($blankLines);
         $fix = $phpcsFile->addFixableError($error, $lastCode, 'TooMany', $data);
         if ($fix === true) {
             $phpcsFile->fixer->beginChangeset();
             $phpcsFile->fixer->replaceToken($lastCode, rtrim($tokens[$lastCode]['content']));
             for ($i = $lastCode + 1; $i < $lastToken; $i++) {
                 $phpcsFile->fixer->replaceToken($i, '');
             }
             $phpcsFile->fixer->replaceToken($lastToken, $phpcsFile->eolChar);
             $phpcsFile->fixer->endChangeset();
         }
     }
     // Skip the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
开发者ID:thekabal,项目名称:tki,代码行数:55,代码来源:EndFileNewlineSniff.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();
     $find = Tokens::$methodPrefixes;
     $find[] = T_WHITESPACE;
     $commentEnd = $phpcsFile->findPrevious($find, $stackPtr - 1, null, true);
     if ($tokens[$commentEnd]['code'] === T_COMMENT) {
         // Inline comments might just be closing comments for
         // control structures or functions instead of function comments
         // using the wrong comment type. If there is other code on the line,
         // assume they relate to that code.
         $prev = $phpcsFile->findPrevious($find, $commentEnd - 1, null, true);
         if ($prev !== false && $tokens[$prev]['line'] === $tokens[$commentEnd]['line']) {
             $commentEnd = $prev;
         }
     }
     if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT) {
         $phpcsFile->addError('Missing function doc comment', $stackPtr, 'Missing');
         $phpcsFile->recordMetric($stackPtr, 'Function has doc comment', 'no');
         return;
     } else {
         $phpcsFile->recordMetric($stackPtr, 'Function has doc comment', 'yes');
     }
     if ($tokens[$commentEnd]['code'] === T_COMMENT) {
         $phpcsFile->addError('You must use "/**" style comments for a function comment', $stackPtr, 'WrongStyle');
         return;
     }
     if ($tokens[$commentEnd]['line'] !== $tokens[$stackPtr]['line'] - 1) {
         $error = 'There must be no blank lines after the function comment';
         $phpcsFile->addError($error, $commentEnd, 'SpacingAfter');
     }
     $commentStart = $tokens[$commentEnd]['comment_opener'];
     foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
         if ($tokens[$tag]['content'] === '@see') {
             // Make sure the tag isn't empty.
             $string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $tag, $commentEnd);
             if ($string === false || $tokens[$string]['line'] !== $tokens[$tag]['line']) {
                 $error = 'Content missing for @see tag in function comment';
                 $phpcsFile->addError($error, $tag, 'EmptySees');
             }
         }
     }
     $this->processReturn($phpcsFile, $stackPtr, $commentStart);
     $this->processThrows($phpcsFile, $stackPtr, $commentStart);
     $this->processParams($phpcsFile, $stackPtr, $commentStart);
 }
开发者ID:thekabal,项目名称:tki,代码行数:55,代码来源:FunctionCommentSniff.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(File $phpcsFile, $stackPtr)
 {
     $this->requiredSpacesAfterOpen = (int) $this->requiredSpacesAfterOpen;
     $this->requiredSpacesBeforeClose = (int) $this->requiredSpacesBeforeClose;
     $tokens = $phpcsFile->getTokens();
     if (isset($tokens[$stackPtr]['parenthesis_opener']) === false || isset($tokens[$stackPtr]['parenthesis_closer']) === false) {
         return;
     }
     $parenOpener = $tokens[$stackPtr]['parenthesis_opener'];
     $parenCloser = $tokens[$stackPtr]['parenthesis_closer'];
     $spaceAfterOpen = 0;
     if ($tokens[$parenOpener + 1]['code'] === T_WHITESPACE) {
         if (strpos($tokens[$parenOpener + 1]['content'], $phpcsFile->eolChar) !== false) {
             $spaceAfterOpen = 'newline';
         } else {
             $spaceAfterOpen = strlen($tokens[$parenOpener + 1]['content']);
         }
     }
     $phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', $spaceAfterOpen);
     if ($spaceAfterOpen !== $this->requiredSpacesAfterOpen) {
         $error = 'Expected %s spaces after opening bracket; %s found';
         $data = array($this->requiredSpacesAfterOpen, $spaceAfterOpen);
         $fix = $phpcsFile->addFixableError($error, $parenOpener + 1, 'SpacingAfterOpenBrace', $data);
         if ($fix === true) {
             $padding = str_repeat(' ', $this->requiredSpacesAfterOpen);
             if ($spaceAfterOpen === 0) {
                 $phpcsFile->fixer->addContent($parenOpener, $padding);
             } else {
                 if ($spaceAfterOpen === 'newline') {
                     $phpcsFile->fixer->replaceToken($parenOpener + 1, '');
                 } else {
                     $phpcsFile->fixer->replaceToken($parenOpener + 1, $padding);
                 }
             }
         }
     }
     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));
         }
         $phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', $spaceBeforeClose);
         if ($spaceBeforeClose !== $this->requiredSpacesBeforeClose) {
             $error = 'Expected %s spaces before closing bracket; %s found';
             $data = array($this->requiredSpacesBeforeClose, $spaceBeforeClose);
             $fix = $phpcsFile->addFixableError($error, $parenCloser - 1, 'SpaceBeforeCloseBrace', $data);
             if ($fix === true) {
                 $padding = str_repeat(' ', $this->requiredSpacesBeforeClose);
                 if ($spaceBeforeClose === 0) {
                     $phpcsFile->fixer->addContentBefore($parenCloser, $padding);
                 } else {
                     $phpcsFile->fixer->replaceToken($parenCloser - 1, $padding);
                 }
             }
         }
     }
     //end if
 }
开发者ID:thekabal,项目名称:tki,代码行数:67,代码来源:ControlStructureSpacingSniff.php

示例12: 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 int
  */
 public function process(File $phpcsFile, $stackPtr)
 {
     $filename = $phpcsFile->getFilename();
     if ($filename === 'STDIN') {
         return;
     }
     $filename = basename($filename);
     $lowercaseFilename = strtolower($filename);
     if ($filename !== $lowercaseFilename) {
         $data = array($filename, $lowercaseFilename);
         $error = 'Filename "%s" doesn\'t match the expected filename "%s"';
         $phpcsFile->addError($error, $stackPtr, 'NotFound', $data);
         $phpcsFile->recordMetric($stackPtr, 'Lowercase filename', 'no');
     } else {
         $phpcsFile->recordMetric($stackPtr, 'Lowercase filename', 'yes');
     }
     // Ignore the rest of the file.
     return $phpcsFile->numTokens + 1;
 }
开发者ID:thekabal,项目名称:tki,代码行数:28,代码来源:LowercasedFilenameSniff.php

示例13: 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)
 {
     // The BOM will be the very first token in the file.
     if ($stackPtr !== 0) {
         return;
     }
     $tokens = $phpcsFile->getTokens();
     foreach ($this->bomDefinitions as $bomName => $expectedBomHex) {
         $bomByteLength = strlen($expectedBomHex) / 2;
         $htmlBomHex = bin2hex(substr($tokens[$stackPtr]['content'], 0, $bomByteLength));
         if ($htmlBomHex === $expectedBomHex) {
             $errorData = array($bomName);
             $error = 'File contains %s byte order mark, which may corrupt your application';
             $phpcsFile->addError($error, $stackPtr, 'Found', $errorData);
             $phpcsFile->recordMetric($stackPtr, 'Using byte order mark', 'yes');
             return;
         }
     }
     $phpcsFile->recordMetric($stackPtr, 'Using byte order mark', 'no');
 }
开发者ID:thekabal,项目名称:tki,代码行数:29,代码来源:ByteOrderMarkSniff.php

示例14: 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)
 {
     $tokens = $phpcsFile->getTokens();
     $keyword = $tokens[$stackPtr]['content'];
     if (strtolower($keyword) !== $keyword) {
         if ($keyword === strtoupper($keyword)) {
             $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'upper');
         } else {
             $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'mixed');
         }
         $error = 'PHP keywords must be lowercase; expected "%s" but found "%s"';
         $data = array(strtolower($keyword), $keyword);
         $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found', $data);
         if ($fix === true) {
             $phpcsFile->fixer->replaceToken($stackPtr, strtolower($keyword));
         }
     } else {
         $phpcsFile->recordMetric($stackPtr, 'PHP keyword case', 'lower');
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:29,代码来源:LowerCaseKeywordSniff.php

示例15: 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 + 1]['code'] !== T_WHITESPACE) {
         $error = 'A cast statement must be followed by a single space';
         $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpace');
         if ($fix === true) {
             $phpcsFile->fixer->addContent($stackPtr, ' ');
         }
         $phpcsFile->recordMetric($stackPtr, 'Spacing after cast statement', 0);
         return;
     }
     $phpcsFile->recordMetric($stackPtr, 'Spacing after cast statement', $tokens[$stackPtr + 1]['length']);
     if ($tokens[$stackPtr + 1]['length'] !== 1) {
         $error = 'A cast statement must be followed by a single space';
         $fix = $phpcsFile->addFixableError($error, $stackPtr, 'TooMuchSpace');
         if ($fix === true) {
             $phpcsFile->fixer->replaceToken($stackPtr + 1, ' ');
         }
     }
 }
开发者ID:thekabal,项目名称:tki,代码行数:30,代码来源:SpaceAfterCastSniff.php


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