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


PHP PHP_CodeSniffer_File::addFixableError方法代码示例

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


在下文中一共展示了PHP_CodeSniffer_File::addFixableError方法的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();
     $lastLineChecked = $tokens[$stackPtr]['line'];
     for ($i = $stackPtr + 1; $i < $tokens[$stackPtr]['comment_closer'] - 1; $i++) {
         // We are only interested in the beginning of the line.
         if ($tokens[$i]['line'] === $lastLineChecked) {
             continue;
         }
         // The first token on the line must be a whitespace followed by a star.
         if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE) {
             if ($tokens[$i + 1]['code'] !== T_DOC_COMMENT_STAR) {
                 $error = 'Doc comment star missing';
                 $fix = $phpcsFile->addFixableError($error, $i, 'StarMissing');
                 if ($fix === true) {
                     $phpcsFile->fixer->replaceToken($i, str_repeat(' ', $tokens[$stackPtr]['column']) . '* ');
                 }
             }
         } else {
             if ($tokens[$i]['code'] !== T_DOC_COMMENT_STAR) {
                 $error = 'Doc comment star missing';
                 $fix = $phpcsFile->addFixableError($error, $i, 'StarMissing');
                 if ($fix === true) {
                     $phpcsFile->fixer->addContentBefore($i, str_repeat(' ', $tokens[$stackPtr]['column']) . '* ');
                 }
             }
         }
         $lastLineChecked = $tokens[$i]['line'];
     }
     //end for
 }
开发者ID:atif-shaikh,项目名称:DCX-Profile,代码行数:40,代码来源:DocCommentStarSniff.php

示例2: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
  * @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();
     $next = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
     if ($tokens[$next]['code'] !== T_WHITESPACE && $next !== $stackPtr + 2) {
         // Last character in a line is ok.
         if ($tokens[$next]['line'] === $tokens[$stackPtr]['line']) {
             $error = 'Missing space after comma';
             $phpcsFile->addFixableError($error, $next);
             // Fix the error
             if ($phpcsFile->fixer->enabled === true) {
                 $phpcsFile->fixer->addContent($stackPtr, ' ');
             }
         }
     }
     $previous = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
     if ($tokens[$previous]['code'] !== T_WHITESPACE && $previous !== $stackPtr - 1) {
         $error = 'Space before comma, expected none, though';
         $phpcsFile->addFixableError($error, $next);
         // Fix the error
         if ($phpcsFile->fixer->enabled === true) {
             $content = $tokens[$previous]['content'];
             $phpcsFile->fixer->replaceToken($previous + 1, '');
         }
     }
 }
开发者ID:dereuromark,项目名称:codesniffer-standards,代码行数:34,代码来源:CommaSpacingSniff.php

示例3: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param int                  $stackPtr  The position of the current token
  *                                        in the stack passed in $tokens.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     if (isset($tokens[$stackPtr]['parenthesis_opener']) === true) {
         $parenOpener = $tokens[$stackPtr]['parenthesis_opener'];
         $parenCloser = $tokens[$stackPtr]['parenthesis_closer'];
         if ($tokens[$parenOpener + 1]['code'] === T_WHITESPACE) {
             $gap = strlen($tokens[$parenOpener + 1]['content']);
             $error = 'Expected 0 spaces after opening bracket; %s found';
             $data = array($gap);
             $fix = $phpcsFile->addFixableError($error, $parenOpener + 1, 'SpacingAfterOpenBrace', $data);
             if ($fix === true && $phpcsFile->fixer->enabled === true) {
                 $phpcsFile->fixer->replaceToken($parenOpener + 1, '');
             }
         }
         if ($tokens[$parenOpener]['line'] === $tokens[$parenCloser]['line'] && $tokens[$parenCloser - 1]['code'] === T_WHITESPACE) {
             $gap = strlen($tokens[$parenCloser - 1]['content']);
             $error = 'Expected 0 spaces before closing bracket; %s found';
             $data = array($gap);
             $fix = $phpcsFile->addFixableError($error, $parenCloser - 1, 'SpaceBeforeCloseBrace', $data);
             if ($fix === true && $phpcsFile->fixer->enabled === true) {
                 $phpcsFile->fixer->replaceToken($parenCloser - 1, '');
             }
         }
     }
     //end if
 }
开发者ID:dereuromark,项目名称:cakephp-codesniffer,代码行数:36,代码来源:ControlStructureSpacingSniff.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)
 {
     $tokens = $phpcsFile->getTokens();
     $colour = $tokens[$stackPtr]['content'];
     $expected = strtoupper($colour);
     if ($colour !== $expected) {
         $error = 'CSS colours must be defined in uppercase; expected %s but found %s';
         $data = array($expected, $colour);
         $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotUpper', $data);
         if ($fix === true && $phpcsFile->fixer->enabled === true) {
             $phpcsFile->fixer->replaceToken($stackPtr, $expected);
         }
     }
     // Now check if shorthand can be used.
     if (strlen($colour) !== 7) {
         return;
     }
     if ($colour[1] === $colour[2] && $colour[3] === $colour[4] && $colour[5] === $colour[6]) {
         $expected = '#' . $colour[1] . $colour[3] . $colour[5];
         $error = 'CSS colours must use shorthand if available; expected %s but found %s';
         $data = array($expected, $colour);
         $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Shorthand', $data);
         if ($fix === true && $phpcsFile->fixer->enabled === true) {
             $phpcsFile->fixer->replaceToken($stackPtr, $expected);
         }
     }
 }
开发者ID:dereuromark,项目名称:cakephp-codesniffer,代码行数:36,代码来源:ColourDefinitionSniff.php

示例5: process

 /**
  * @inheritdoc
  */
 public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     if ($tokens[$stackPtr]['content'] === '!') {
         $prevIndex = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
         if ($tokens[$prevIndex]['content'] !== '!') {
             return;
         }
         $fix = $phpcsFile->addFixableError('`!!` cast not allowed, use `(bool)`', $stackPtr);
         if ($fix) {
             $phpcsFile->fixer->replaceToken($prevIndex, '');
             $phpcsFile->fixer->replaceToken($stackPtr, '(bool)');
         }
         return;
     }
     $content = $tokens[$stackPtr]['content'];
     $key = strtolower($content);
     if (!isset(static::$matching[$key])) {
         return;
     }
     $fix = $phpcsFile->addFixableError($content . ' found, expected ' . static::$matching[$key], $stackPtr);
     if ($fix) {
         $phpcsFile->fixer->replaceToken($stackPtr, static::$matching[$key]);
     }
 }
开发者ID:spryker,项目名称:code-sniffer,代码行数:28,代码来源:ShortCastSniff.php

示例6: 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 + 1]['code'] === T_SEMICOLON) {
         // No content for this language construct.
         return;
     }
     if ($tokens[$stackPtr + 1]['code'] === T_WHITESPACE) {
         $content = $tokens[$stackPtr + 1]['content'];
         $contentLength = strlen($content);
         if ($contentLength !== 1) {
             $error = 'Language constructs must be followed by a single space; expected 1 space but found %s';
             $data = array($contentLength);
             $fix = $phpcsFile->addFixableError($error, $stackPtr, 'IncorrectSingle', $data);
             if ($fix === true) {
                 $phpcsFile->fixer->replaceToken($stackPtr + 1, ' ');
             }
         }
     } else {
         $error = 'Language constructs must be followed by a single space; expected "%s" but found "%s"';
         $data = array($tokens[$stackPtr]['content'] . ' ' . $tokens[$stackPtr + 1]['content'], $tokens[$stackPtr]['content'] . $tokens[$stackPtr + 1]['content']);
         $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Incorrect', $data);
         if ($fix === true) {
             $phpcsFile->fixer->addContent($stackPtr, ' ');
         }
     }
     //end if
 }
开发者ID:lunnlew,项目名称:Norma_Code,代码行数:37,代码来源:LanguageConstructSpacingSniff.php

示例7: 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();
     $line = $tokens[$stackPtr]['line'];
     if ($stackPtr > 0 && $tokens[$stackPtr - 1]['line'] !== $line) {
         return;
     }
     if (strpos($tokens[$stackPtr]['content'], '  ') !== false) {
         $error = 'Double space found';
         $phpcsFile->addFixableError($error, $stackPtr);
         if ($phpcsFile->fixer->enabled === true) {
             $phpcsFile->fixer->replaceToken($stackPtr, ' ');
         }
     }
     if (strpos($tokens[$stackPtr]['content'], " \t") !== false) {
         $error = 'Space and tab found';
         $phpcsFile->addFixableError($error, $stackPtr);
         if ($phpcsFile->fixer->enabled === true) {
             $phpcsFile->fixer->replaceToken($stackPtr, ' ');
         }
     }
     if (strpos($tokens[$stackPtr]['content'], "\t ") !== false) {
         $error = 'Tab and space found';
         $phpcsFile->addFixableError($error, $stackPtr);
         if ($phpcsFile->fixer->enabled === true) {
             $phpcsFile->fixer->replaceToken($stackPtr, ' ');
         }
     }
 }
开发者ID:dereuromark,项目名称:codesniffer-standards,代码行数:37,代码来源:TabAndSpaceSniff.php

示例8: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param int                  $stackPtr  The position of the current token
  *                                        in the stack passed in $tokens.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $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(PHP_CodeSniffer_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:squizlabs,项目名称:php_codesniffer,代码行数:38,代码来源:DisallowShortOpenTagSniff.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
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $token = $tokens[$stackPtr];
     $content = $token['content'];
     // Check if the previous is an asterisk, if so => error.
     if ($token['code'] === T_DOC_COMMENT_STRING) {
         if ($tokens[$stackPtr - 1]['code'] === T_DOC_COMMENT_STAR) {
             $fix = $phpcsFile->addFixableError('Whitespace must be added after the asterisk in doc comments. Expected "* ' . $content . '" but "*' . $content . '" was found.', $stackPtr);
             if ($fix === true) {
                 $phpcsFile->fixer->replaceToken($stackPtr, ' ' . $content);
             }
         }
         return;
     }
     $trimmed = ltrim($content);
     // We ignore empty lines in doc comment.
     if ($trimmed == '*') {
         return;
     }
     if (strpos($trimmed, '*') === 0 && strpos($trimmed, ' ') != 1 && strpos($trimmed, '/') != 1 && strpos($trimmed, "\n") != 1) {
         $asterisk = strpos($content, '*');
         $prefix = substr($content, 0, $asterisk + 1) . ' ';
         $fix = $phpcsFile->addFixableError('Whitespace must be added after the asterisk in doc comments. Expected "' . $prefix . ltrim($trimmed, '*') . '" but "' . $content . '" was found.', $stackPtr);
         if ($fix === true) {
             $replacement = $prefix . ltrim($trimmed, '*');
             $phpcsFile->fixer->replaceToken($stackPtr, $replacement);
         }
     }
 }
开发者ID:phpcq,项目名称:coding-standard,代码行数:41,代码来源:WhitespaceAfterAsteriskSniff.php

示例10: process

 /**
  * @inheritdoc
  */
 public function process(\PHP_CodeSniffer_File $phpCsFile, $stackPointer)
 {
     $tokens = $phpCsFile->getTokens();
     $level = $tokens[$stackPointer]['level'];
     if ($level < 1) {
         return;
     }
     $openingBraceIndex = $phpCsFile->findNext(T_OPEN_CURLY_BRACKET, $stackPointer + 1);
     if (!$openingBraceIndex) {
         $openingParenthesisIndex = $phpCsFile->findNext(T_OPEN_PARENTHESIS, $stackPointer + 1);
         $closingParenthesisIndex = $tokens[$openingParenthesisIndex]['parenthesis_closer'];
         $semicolonIndex = $phpCsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $closingParenthesisIndex + 1, null, true);
         $nextContentIndex = $phpCsFile->findNext(T_WHITESPACE, $semicolonIndex + 1, null, true);
         if ($tokens[$nextContentIndex]['line'] - $tokens[$semicolonIndex]['line'] <= 1) {
             $fix = $phpCsFile->addFixableError('Every function/method needs a newline afterwards', $closingParenthesisIndex, 'Abstract');
             if ($fix) {
                 $phpCsFile->fixer->addNewline($semicolonIndex);
             }
         }
         return;
     }
     $closingBraceIndex = $tokens[$openingBraceIndex]['scope_closer'];
     // Ignore closures
     $nextIndex = $phpCsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $closingBraceIndex + 1, null, true);
     if (in_array($tokens[$nextIndex]['content'], [';', ',', ')'])) {
         return;
     }
     $nextContentIndex = $phpCsFile->findNext(T_WHITESPACE, $closingBraceIndex + 1, null, true);
     if (!$nextContentIndex || $tokens[$nextContentIndex]['line'] - $tokens[$closingBraceIndex]['line'] <= 1) {
         $fix = $phpCsFile->addFixableError('Every function/method needs a newline afterwards', $closingBraceIndex, 'Concrete');
         if ($fix) {
             $phpCsFile->fixer->addNewline($closingBraceIndex);
         }
     }
 }
开发者ID:spryker,项目名称:code-sniffer,代码行数:38,代码来源:FunctionSpacingSniff.php

示例11: processIncDec

 /**
  * @param \PHP_CodeSniffer_File $phpcsFile
  * @param int $stackPtr
  *
  * @return void
  */
 protected function processIncDec(\PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $nextIndex = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
     if ($tokens[$nextIndex]['code'] === T_VARIABLE) {
         if ($nextIndex - $stackPtr === 1) {
             return;
         }
         $fix = $phpcsFile->addFixableError('No whitespace should be between incrementor and variable.', $stackPtr);
         if ($fix) {
             $phpcsFile->fixer->beginChangeset();
             $phpcsFile->fixer->replaceToken($stackPtr + 1, '');
             $phpcsFile->fixer->endChangeset();
         }
         return;
     }
     $prevIndex = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
     if ($tokens[$prevIndex]['code'] === T_VARIABLE) {
         if ($stackPtr - $prevIndex === 1) {
             return;
         }
         $fix = $phpcsFile->addFixableError('No whitespace should be between variable and incrementor.', $stackPtr);
         if ($fix) {
             $phpcsFile->fixer->beginChangeset();
             $phpcsFile->fixer->replaceToken($stackPtr - 1, '');
             $phpcsFile->fixer->endChangeset();
         }
         return;
     }
 }
开发者ID:spryker,项目名称:code-sniffer,代码行数:36,代码来源:ImplicitCastSpacingSniff.php

示例12: process

 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  * @param int                  $stackPtr  The position in the stack where
  *                                        the token was found.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     // Do not check nested style definitions as, for example, in @media style rules.
     $nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $stackPtr + 1, $tokens[$stackPtr]['bracket_closer']);
     if ($nested !== false) {
         return;
     }
     // Find the first blank line before this opening brace, unless we get
     // to another style definition, comment or the start of the file.
     $endTokens = array(T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, T_OPEN_TAG => T_OPEN_TAG);
     $endTokens += PHP_CodeSniffer_Tokens::$commentTokens;
     $foundContent = false;
     $currentLine = $tokens[$stackPtr]['line'];
     for ($i = $stackPtr - 1; $i >= 0; $i--) {
         if (isset($endTokens[$tokens[$i]['code']]) === true) {
             break;
         }
         // A comma must be followed by a new line character.
         if ($tokens[$i]['code'] === T_COMMA && strpos($tokens[$i + 1]['content'], $phpcsFile->eolChar) === false) {
             $error = 'Multiple selectors should each be on a single line';
             $fix = $phpcsFile->addFixableError($error, $i + 1, 'MultipleSelectors');
             if ($fix === true) {
                 $phpcsFile->fixer->addNewline($i);
             }
         }
         // Selectors must be on the same line.
         if ($tokens[$i]['code'] === T_WHITESPACE && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false && isset($endTokens[$tokens[$i - 1]['code']]) === false && in_array($tokens[$i - 1]['code'], array(T_WHITESPACE, T_COMMA)) === false) {
             $error = 'Selectors must be on a single line';
             $fix = $phpcsFile->addFixableError($error, $i, 'SeletorSingleLine');
             if ($fix === true) {
                 $phpcsFile->fixer->replaceToken($i, str_replace($phpcsFile->eolChar, ' ', $tokens[$i]['content']));
             }
         }
         if ($tokens[$i]['line'] === $currentLine) {
             if ($tokens[$i]['code'] !== T_WHITESPACE) {
                 $foundContent = true;
             }
             continue;
         }
         // We changed lines.
         if ($foundContent === false) {
             // Before we throw an error, make sure we are not looking
             // at a gap before the style definition.
             $prev = $phpcsFile->findPrevious(T_WHITESPACE, $i, null, true);
             if ($prev !== false && isset($endTokens[$tokens[$prev]['code']]) === false) {
                 $error = 'Blank lines are not allowed between class names';
                 $fix = $phpcsFile->addFixableError($error, $i + 1, 'BlankLinesFound');
                 if ($fix === true) {
                     $phpcsFile->fixer->replaceToken($i + 1, '');
                 }
             }
             break;
         }
         $foundContent = false;
         $currentLine = $tokens[$i]['line'];
     }
     //end for
 }
开发者ID:atif-shaikh,项目名称:DCX-Profile,代码行数:68,代码来源:ClassDefinitionNameSpacingSniff.php

示例13: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
  * @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();
     // Make sure there is one space before.
     $previousToken = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
     if ($stackPtr - $previousToken === 1) {
         $error = 'Expected 1 space before ternary IF, none found';
         $phpcsFile->addFixableError($error, $stackPtr, 'NotFound');
         if ($phpcsFile->fixer->enabled === true) {
             $phpcsFile->fixer->addContent($previousToken, ' ');
         }
     }
     // Make sure there is one space after - but not for short ternary.
     $nextToken = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
     $shortTernary = false;
     if ($tokens[$nextToken]['code'] === T_INLINE_ELSE) {
         $shortTernary = true;
         if ($nextToken - $stackPtr > 1) {
             $error = 'Expected no space between short ternary IF/ELSE, 1 found';
             $phpcsFile->addFixableError($error, $stackPtr, 'TooMany');
             if ($phpcsFile->fixer->enabled === true) {
                 $phpcsFile->fixer->replaceToken($stackPtr + 1, '');
             }
         }
     }
     if (!$shortTernary && $nextToken - $stackPtr === 1) {
         $error = 'Expected 1 space after ternary IF, none found';
         $phpcsFile->addFixableError($error, $stackPtr, 'NotFound');
         if ($phpcsFile->fixer->enabled === true) {
             $phpcsFile->fixer->addContent($stackPtr, ' ');
         }
     }
     // Make sure the : has the correct spacing.
     $inlineElse = $phpcsFile->findNext(T_INLINE_ELSE, $stackPtr + 1, null, false);
     if (!$shortTernary) {
         $previousToken = $phpcsFile->findPrevious(T_WHITESPACE, $inlineElse - 1, null, true);
         if ($inlineElse - $previousToken === 1) {
             $error = 'Expected 1 space before ternary ELSE, none found';
             $phpcsFile->addFixableError($error, $inlineElse, 'NotFound');
             if ($phpcsFile->fixer->enabled === true) {
                 $phpcsFile->fixer->addContent($previousToken, ' ');
             }
         }
     }
     $nextToken = $phpcsFile->findNext(T_WHITESPACE, $inlineElse + 1, null, true);
     if ($nextToken - $inlineElse === 1) {
         $error = 'Expected 1 space after ternary ELSE, none found';
         $phpcsFile->addFixableError($error, $inlineElse, 'NotFound');
         if ($phpcsFile->fixer->enabled === true) {
             $phpcsFile->fixer->addContent($inlineElse, ' ');
         }
     }
 }
开发者ID:dereuromark,项目名称:codesniffer-standards,代码行数:61,代码来源:TernarySpacingSniff.php

示例14: process

 /**
  * Processes the tokens that this sniff is interested in.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  * @param int                  $stackPtr  The position in the stack where
  *                                        the token was found.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr - 1, null, true);
     if ($tokens[$prev]['code'] !== T_STYLE) {
         // The colon is not part of a style definition.
         return;
     }
     if ($tokens[$prev]['content'] === 'progid') {
         // Special case for IE filters.
         return;
     }
     if ($tokens[$stackPtr - 1]['code'] === T_WHITESPACE) {
         $error = 'There must be no space before a colon in a style definition';
         $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Before');
         if ($fix === true) {
             $phpcsFile->fixer->replaceToken($stackPtr - 1, '');
         }
     }
     if ($tokens[$stackPtr + 1]['code'] === T_SEMICOLON) {
         // Empty style definition, ignore it.
         return;
     }
     if ($tokens[$stackPtr + 1]['code'] !== T_WHITESPACE) {
         $error = 'Expected 1 space after colon in style definition; 0 found';
         $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoneAfter');
         if ($fix === true) {
             $phpcsFile->fixer->addContent($stackPtr, ' ');
         }
     } else {
         $content = $tokens[$stackPtr + 1]['content'];
         if (strpos($content, $phpcsFile->eolChar) === false) {
             $length = strlen($content);
             if ($length !== 1) {
                 $error = 'Expected 1 space after colon in style definition; %s found';
                 $data = array($length);
                 $fix = $phpcsFile->addFixableError($error, $stackPtr, 'After', $data);
                 if ($fix === true) {
                     $phpcsFile->fixer->replaceToken($stackPtr + 1, ' ');
                 }
             }
         } else {
             $error = 'Expected 1 space after colon in style definition; newline found';
             $fix = $phpcsFile->addFixableError($error, $stackPtr, 'AfterNewline');
             if ($fix === true) {
                 $phpcsFile->fixer->replaceToken($stackPtr + 1, ' ');
             }
         }
     }
     //end if
 }
开发者ID:ppwalks33,项目名称:cleansure,代码行数:60,代码来源:ColonSpacingSniff.php

示例15: 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)
 {
     // We are only interested if this is the first open tag and in a file
     // that only contains PHP code.
     if ($stackPtr !== 0) {
         if ($phpcsFile->findPrevious(array(T_OPEN_TAG, T_INLINE_HTML), $stackPtr - 1) !== false) {
             return;
         }
     }
     if ($phpcsFile->findNext(T_INLINE_HTML, $stackPtr + 1) !== false) {
         return;
     }
     // 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->enabled === true) {
             $phpcsFile->fixer->addNewline($lastToken);
         }
         return;
     }
     // 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;
     if ($blankLines > 0) {
         $error = 'Expected 1 blank line at end of file; %s found';
         $data = array($blankLines + 1);
         $fix = $phpcsFile->addFixableError($error, $lastCode, 'TooMany', $data);
         if ($fix === true && $phpcsFile->fixer->enabled === 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();
         }
     }
     //end if
 }
开发者ID:dereuromark,项目名称:cakephp-codesniffer,代码行数:59,代码来源:EndFileNewlineSniff.php


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