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


PHP File::findEndOfStatement方法代码示例

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


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

示例1: isMultiLineCall

 /**
  * Processes single-line calls.
  *
  * @param PHP_CodeSniffer_File $phpcsFile   The file being scanned.
  * @param int                  $stackPtr    The position of the current token
  *                                          in the stack passed in $tokens.
  * @param int                  $openBracket The position of the opening bracket
  *                                          in the stack passed in $tokens.
  * @param array                $tokens      The stack of tokens that make up
  *                                          the file.
  *
  * @return void
  */
 public function isMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $tokens)
 {
     // If the first argument is on a new line, this is a multi-line
     // function call, even if there is only one argument.
     $next = $phpcsFile->findNext(Tokens::$emptyTokens, $openBracket + 1, null, true);
     if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
         return true;
     }
     $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
     $end = $phpcsFile->findEndOfStatement($openBracket + 1);
     while ($tokens[$end]['code'] === T_COMMA) {
         // If the next bit of code is not on the same line, this is a
         // multi-line function call.
         $next = $phpcsFile->findNext(Tokens::$emptyTokens, $end + 1, $closeBracket, true);
         if ($next === false) {
             return false;
         }
         if ($tokens[$next]['line'] !== $tokens[$end]['line']) {
             return true;
         }
         $end = $phpcsFile->findEndOfStatement($next);
     }
     // We've reached the last argument, so see if the next content
     // (should be the close bracket) is also on the same line.
     $next = $phpcsFile->findNext(Tokens::$emptyTokens, $end + 1, $closeBracket, true);
     if ($next !== false && $tokens[$next]['line'] !== $tokens[$end]['line']) {
         return true;
     }
     return false;
 }
开发者ID:thekabal,项目名称:tki,代码行数:43,代码来源:FunctionCallSignatureSniff.php

示例2: processMultiLineCall


//.........这里部分代码省略.........
                 // We changed lines, so this should be a whitespace indent token, but first make
                 // sure it isn't a blank line because we don't need to check indent unless there
                 // is actually some code to indent.
                 if ($tokens[$i]['code'] === T_WHITESPACE) {
                     $nextCode = $phpcsFile->findNext(T_WHITESPACE, $i + 1, $closeBracket + 1, true);
                     if ($tokens[$nextCode]['line'] !== $lastLine) {
                         if ($inArg === false) {
                             $error = 'Empty lines are not allowed in multi-line function calls';
                             $fix = $phpcsFile->addFixableError($error, $i, 'EmptyLine');
                             if ($fix === true) {
                                 $phpcsFile->fixer->replaceToken($i, '');
                             }
                         }
                         continue;
                     }
                 } else {
                     $nextCode = $i;
                 }
                 if ($tokens[$nextCode]['line'] === $tokens[$closeBracket]['line']) {
                     // Closing brace needs to be indented to the same level
                     // as the function call.
                     $inArg = false;
                     $expectedIndent = $functionIndent;
                 } else {
                     $expectedIndent = $functionIndent + $this->indent;
                 }
                 if ($tokens[$i]['code'] !== T_WHITESPACE && $tokens[$i]['code'] !== T_DOC_COMMENT_WHITESPACE) {
                     // Just check if it is a multi-line block comment. If so, we can
                     // calculate the indent from the whitespace before the content.
                     if ($tokens[$i]['code'] === T_COMMENT && $tokens[$i - 1]['code'] === T_COMMENT) {
                         $trimmed = ltrim($tokens[$i]['content']);
                         $foundIndent = strlen($tokens[$i]['content']) - strlen($trimmed);
                     } else {
                         $foundIndent = 0;
                     }
                 } else {
                     $foundIndent = strlen($tokens[$i]['content']);
                 }
                 if ($foundIndent < $expectedIndent || $inArg === false && $expectedIndent !== $foundIndent) {
                     $error = 'Multi-line function call not indented correctly; expected %s spaces but found %s';
                     $data = array($expectedIndent, $foundIndent);
                     $fix = $phpcsFile->addFixableError($error, $i, 'Indent', $data);
                     if ($fix === true) {
                         $padding = str_repeat(' ', $expectedIndent);
                         if ($foundIndent === 0) {
                             $phpcsFile->fixer->addContentBefore($i, $padding);
                         } else {
                             if ($tokens[$i]['code'] === T_COMMENT) {
                                 $comment = $padding . ltrim($tokens[$i]['content']);
                                 $phpcsFile->fixer->replaceToken($i, $comment);
                             } else {
                                 $phpcsFile->fixer->replaceToken($i, $padding);
                             }
                         }
                     }
                 }
                 //end if
             } else {
                 $nextCode = $i;
             }
             //end if
             if ($inArg === false) {
                 $argStart = $nextCode;
                 $argEnd = $phpcsFile->findEndOfStatement($nextCode);
             }
         }
         //end if
         // If we are within an argument we should be ignoring commas
         // as these are not signaling the end of an argument.
         if ($inArg === false && $tokens[$i]['code'] === T_COMMA) {
             $next = $phpcsFile->findNext(array(T_WHITESPACE, T_COMMENT), $i + 1, $closeBracket, true);
             if ($next === false) {
                 continue;
             }
             if ($this->allowMultipleArguments === false) {
                 // Comma has to be the last token on the line.
                 if ($tokens[$i]['line'] === $tokens[$next]['line']) {
                     $error = 'Only one argument is allowed per line in a multi-line function call';
                     $fix = $phpcsFile->addFixableError($error, $next, 'MultipleArguments');
                     if ($fix === true) {
                         $phpcsFile->fixer->beginChangeset();
                         for ($x = $next - 1; $x > $i; $x--) {
                             if ($tokens[$x]['code'] !== T_WHITESPACE) {
                                 break;
                             }
                             $phpcsFile->fixer->replaceToken($x, '');
                         }
                         $phpcsFile->fixer->addContentBefore($next, $phpcsFile->eolChar . str_repeat(' ', $functionIndent + $this->indent));
                         $phpcsFile->fixer->endChangeset();
                     }
                 }
             }
             //end if
             $argStart = $next;
             $argEnd = $phpcsFile->findEndOfStatement($next);
         }
         //end if
     }
     //end for
 }
开发者ID:thekabal,项目名称:tki,代码行数:101,代码来源:FunctionCallSignatureSniff.php

示例3: process


//.........这里部分代码省略.........
         }
         $opener = $tokens[$nextCase]['scope_opener'];
         if ($tokens[$opener - 1]['type'] === 'T_WHITESPACE') {
             $error = 'There must be no space before the colon in a ' . strtoupper($type) . ' statement';
             $fix = $phpcsFile->addFixableError($error, $nextCase, 'SpaceBeforeColon' . $type);
             if ($fix === true) {
                 $phpcsFile->fixer->replaceToken($opener - 1, '');
             }
         }
         $nextBreak = $tokens[$nextCase]['scope_closer'];
         if ($tokens[$nextBreak]['code'] === T_BREAK || $tokens[$nextBreak]['code'] === T_RETURN || $tokens[$nextBreak]['code'] === T_CONTINUE || $tokens[$nextBreak]['code'] === T_THROW || $tokens[$nextBreak]['code'] === T_EXIT) {
             if ($tokens[$nextBreak]['scope_condition'] === $nextCase) {
                 // Only need to check a couple of things once, even if the
                 // break is shared between multiple case statements, or even
                 // the default case.
                 if ($tokens[$nextBreak]['column'] !== $caseAlignment) {
                     $error = 'Case breaking statement must be indented ' . $this->indent . ' spaces from SWITCH keyword';
                     $fix = $phpcsFile->addFixableError($error, $nextBreak, 'BreakIndent');
                     if ($fix === true) {
                         $padding = str_repeat(' ', $caseAlignment - 1);
                         if ($tokens[$nextBreak]['column'] === 1 || $tokens[$nextBreak - 1]['code'] !== T_WHITESPACE) {
                             $phpcsFile->fixer->addContentBefore($nextBreak, $padding);
                         } else {
                             $phpcsFile->fixer->replaceToken($nextBreak - 1, $padding);
                         }
                     }
                 }
                 $prev = $phpcsFile->findPrevious(T_WHITESPACE, $nextBreak - 1, $stackPtr, true);
                 if ($tokens[$prev]['line'] !== $tokens[$nextBreak]['line'] - 1) {
                     $error = 'Blank lines are not allowed before case breaking statements';
                     $phpcsFile->addError($error, $nextBreak, 'SpacingBeforeBreak');
                 }
                 $nextLine = $tokens[$tokens[$stackPtr]['scope_closer']]['line'];
                 $semicolon = $phpcsFile->findEndOfStatement($nextBreak);
                 for ($i = $semicolon + 1; $i < $tokens[$stackPtr]['scope_closer']; $i++) {
                     if ($tokens[$i]['type'] !== 'T_WHITESPACE') {
                         $nextLine = $tokens[$i]['line'];
                         break;
                     }
                 }
                 if ($type === 'Case') {
                     // Ensure the BREAK statement is followed by
                     // a single blank line, or the end switch brace.
                     if ($nextLine !== $tokens[$semicolon]['line'] + 2 && $i !== $tokens[$stackPtr]['scope_closer']) {
                         $error = 'Case breaking statements must be followed by a single blank line';
                         $fix = $phpcsFile->addFixableError($error, $nextBreak, 'SpacingAfterBreak');
                         if ($fix === true) {
                             $phpcsFile->fixer->beginChangeset();
                             for ($i = $semicolon + 1; $i <= $tokens[$stackPtr]['scope_closer']; $i++) {
                                 if ($tokens[$i]['line'] === $nextLine) {
                                     $phpcsFile->fixer->addNewlineBefore($i);
                                     break;
                                 }
                                 if ($tokens[$i]['line'] === $tokens[$semicolon]['line']) {
                                     continue;
                                 }
                                 $phpcsFile->fixer->replaceToken($i, '');
                             }
                             $phpcsFile->fixer->endChangeset();
                         }
                     }
                     //end if
                 } else {
                     // Ensure the BREAK statement is not followed by a blank line.
                     if ($nextLine !== $tokens[$semicolon]['line'] + 1) {
                         $error = 'Blank lines are not allowed after the DEFAULT case\'s breaking statement';
开发者ID:thekabal,项目名称:tki,代码行数:67,代码来源:SwitchDeclarationSniff.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();
     // If this token is preceded with an "or", it only relates to one line
     // and should be ignored. For example: fopen() or die().
     $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true);
     if ($tokens[$prev]['code'] === T_LOGICAL_OR || $tokens[$prev]['code'] === T_BOOLEAN_OR) {
         return;
     }
     // Check if this token is actually part of a one-line IF or ELSE statement.
     for ($i = $stackPtr - 1; $i > 0; $i--) {
         if ($tokens[$i]['code'] === T_CLOSE_PARENTHESIS) {
             $i = $tokens[$i]['parenthesis_opener'];
             continue;
         } else {
             if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
                 continue;
             }
         }
         break;
     }
     if ($tokens[$i]['code'] === T_IF || $tokens[$i]['code'] === T_ELSE || $tokens[$i]['code'] === T_ELSEIF) {
         return;
     }
     if ($tokens[$stackPtr]['code'] === T_RETURN) {
         $next = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
         if ($tokens[$next]['code'] === T_SEMICOLON) {
             $next = $phpcsFile->findNext(T_WHITESPACE, $next + 1, null, true);
             if ($tokens[$next]['code'] === T_CLOSE_CURLY_BRACKET) {
                 // If this is the closing brace of a function
                 // then this return statement doesn't return anything
                 // and is not required anyway.
                 $owner = $tokens[$next]['scope_condition'];
                 if ($tokens[$owner]['code'] === T_FUNCTION) {
                     $warning = 'Empty return statement not required here';
                     $phpcsFile->addWarning($warning, $stackPtr, 'ReturnNotRequired');
                     return;
                 }
             }
         }
     }
     if (isset($tokens[$stackPtr]['scope_opener']) === true) {
         $owner = $tokens[$stackPtr]['scope_condition'];
         if ($tokens[$owner]['code'] === T_CASE || $tokens[$owner]['code'] === T_DEFAULT) {
             // This token closes the scope of a CASE or DEFAULT statement
             // so any code between this statement and the next CASE, DEFAULT or
             // end of SWITCH token will not be executable.
             $end = $phpcsFile->findEndOfStatement($stackPtr);
             $next = $phpcsFile->findNext(array(T_CASE, T_DEFAULT, T_CLOSE_CURLY_BRACKET), $end + 1);
             if ($next !== false) {
                 $lastLine = $tokens[$end]['line'];
                 for ($i = $stackPtr + 1; $i < $next; $i++) {
                     if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
                         continue;
                     }
                     $line = $tokens[$i]['line'];
                     if ($line > $lastLine) {
                         $type = substr($tokens[$stackPtr]['type'], 2);
                         $warning = 'Code after %s statement cannot be executed';
                         $data = array($type);
                         $phpcsFile->addWarning($warning, $i, 'Unreachable', $data);
                         $lastLine = $line;
                     }
                 }
             }
             //end if
             // That's all we have to check for these types of statements.
             return;
         }
         //end if
     }
     //end if
     // This token may be part of an inline condition.
     // If we find a closing parenthesis that belongs to a condition
     // we should ignore this token.
     $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true);
     if (isset($tokens[$prev]['parenthesis_owner']) === true) {
         $owner = $tokens[$prev]['parenthesis_owner'];
         $ignore = array(T_IF => true, T_ELSE => true, T_ELSEIF => true);
         if (isset($ignore[$tokens[$owner]['code']]) === true) {
             return;
         }
     }
     $ourConditions = array_keys($tokens[$stackPtr]['conditions']);
     if (empty($ourConditions) === false) {
         $condition = array_pop($ourConditions);
         if (isset($tokens[$condition]['scope_closer']) === false) {
             return;
         }
         // Special case for BREAK statements sitting directly inside SWITCH
         // statements. If we get to this point, we know the BREAK is not being
//.........这里部分代码省略.........
开发者ID:thekabal,项目名称:tki,代码行数:101,代码来源:NonExecutableCodeSniff.php


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