本文整理汇总了PHP中PHP_CodeSniffer\Files\File::findStartOfStatement方法的典型用法代码示例。如果您正苦于以下问题:PHP File::findStartOfStatement方法的具体用法?PHP File::findStartOfStatement怎么用?PHP File::findStartOfStatement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_CodeSniffer\Files\File
的用法示例。
在下文中一共展示了File::findStartOfStatement方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processMultiLineCall
/**
* Processes multi-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 processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $tokens)
{
// We need to work out how far indented the function
// call itself is, so we can work out how far to
// indent the arguments.
$start = $phpcsFile->findStartOfStatement($stackPtr);
foreach (array('stackPtr', 'start') as $checkToken) {
$x = ${$checkToken};
for ($i = $x - 1; $i >= 0; $i--) {
if ($tokens[$i]['line'] !== $tokens[$x]['line']) {
$i++;
break;
}
}
if ($i <= 0) {
$functionIndent = 0;
} else {
if ($tokens[$i]['code'] === T_WHITESPACE) {
$functionIndent = strlen($tokens[$i]['content']);
} else {
if ($tokens[$i]['code'] === T_CONSTANT_ENCAPSED_STRING) {
$functionIndent = 0;
} else {
$trimmed = ltrim($tokens[$i]['content']);
if ($trimmed === '') {
if ($tokens[$i]['code'] === T_INLINE_HTML) {
$functionIndent = strlen($tokens[$i]['content']);
} else {
$functionIndent = $tokens[$i]['column'] - 1;
}
} else {
$functionIndent = strlen($tokens[$i]['content']) - strlen($trimmed);
}
}
}
}
$varName = $checkToken . 'Indent';
${$varName} = $functionIndent;
}
//end foreach
$functionIndent = max($startIndent, $stackPtrIndent);
$next = $phpcsFile->findNext(Tokens::$emptyTokens, $openBracket + 1, null, true);
if ($tokens[$next]['line'] === $tokens[$openBracket]['line']) {
$error = 'Opening parenthesis of a multi-line function call must be the last content on the line';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContentAfterOpenBracket');
if ($fix === true) {
$phpcsFile->fixer->addContent($openBracket, $phpcsFile->eolChar . str_repeat(' ', $functionIndent + $this->indent));
}
}
$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
$prev = $phpcsFile->findPrevious(T_WHITESPACE, $closeBracket - 1, null, true);
if ($tokens[$prev]['line'] === $tokens[$closeBracket]['line']) {
$error = 'Closing parenthesis of a multi-line function call must be on a line by itself';
$fix = $phpcsFile->addFixableError($error, $closeBracket, 'CloseBracketLine');
if ($fix === true) {
$phpcsFile->fixer->addContentBefore($closeBracket, $phpcsFile->eolChar . str_repeat(' ', $functionIndent + $this->indent));
}
}
// Each line between the parenthesis should be indented n spaces.
$lastLine = $tokens[$openBracket]['line'] - 1;
$argStart = null;
$argEnd = null;
$inArg = false;
// Start processing at the first argument.
$i = $phpcsFile->findNext(T_WHITESPACE, $openBracket + 1, null, true);
if ($tokens[$i - 1]['code'] === T_WHITESPACE && $tokens[$i - 1]['line'] === $tokens[$i]['line']) {
// Make sure we check the indent.
$i--;
}
for ($i; $i < $closeBracket; $i++) {
if ($i > $argStart && $i < $argEnd) {
$inArg = true;
} else {
$inArg = false;
}
if ($tokens[$i]['line'] !== $lastLine) {
$lastLine = $tokens[$i]['line'];
// Ignore heredoc indentation.
if (isset(Tokens::$heredocTokens[$tokens[$i]['code']]) === true) {
continue;
}
// Ignore multi-line string indentation.
if (isset(Tokens::$stringTokens[$tokens[$i]['code']]) === true && $tokens[$i]['code'] === $tokens[$i - 1]['code']) {
continue;
}
// Ignore inline HTML.
if ($tokens[$i]['code'] === T_INLINE_HTML) {
//.........这里部分代码省略.........
示例2: process
//.........这里部分代码省略.........
}
$currentIndent = $checkIndent;
if ($this->debug === true) {
$type = $tokens[$lastOpenTag]['type'];
echo "\t=> checking indent of {$checkIndent}; main indent set to {$currentIndent} by token {$lastOpenTag} ({$type})" . PHP_EOL;
}
} else {
if ($condition > 0 && isset($tokens[$condition]['scope_opener']) === true && isset($setIndents[$tokens[$condition]['scope_opener']]) === true) {
$checkIndent = $setIndents[$tokens[$condition]['scope_opener']];
if (isset($adjustments[$condition]) === true) {
$checkIndent += $adjustments[$condition];
}
$currentIndent = $checkIndent;
if ($this->debug === true) {
$type = $tokens[$condition]['type'];
echo "\t=> checking indent of {$checkIndent}; main indent set to {$currentIndent} by token {$condition} ({$type})" . PHP_EOL;
}
} else {
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $parenOpener, true);
$checkIndent = $tokens[$first]['column'] - 1;
if (isset($adjustments[$first]) === true) {
$checkIndent += $adjustments[$first];
}
if ($this->debug === true) {
$line = $tokens[$first]['line'];
$type = $tokens[$first]['type'];
echo "\t* first token on line {$line} is {$first} ({$type}) *" . PHP_EOL;
}
if ($first === $tokens[$parenCloser]['parenthesis_opener']) {
// This is unlikely to be the start of the statement, so look
// back further to find it.
$first--;
}
$prev = $phpcsFile->findStartOfStatement($first, T_COMMA);
if ($prev !== $first) {
// This is not the start of the statement.
if ($this->debug === true) {
$line = $tokens[$prev]['line'];
$type = $tokens[$prev]['type'];
echo "\t* previous is {$type} on line {$line} *" . PHP_EOL;
}
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true);
$prev = $phpcsFile->findStartOfStatement($first, T_COMMA);
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true);
if ($this->debug === true) {
$line = $tokens[$first]['line'];
$type = $tokens[$first]['type'];
echo "\t* amended first token is {$first} ({$type}) on line {$line} *" . PHP_EOL;
}
}
if (isset($tokens[$first]['scope_closer']) === true && $tokens[$first]['scope_closer'] === $first) {
if ($this->debug === true) {
echo "\t* first token is a scope closer *" . PHP_EOL;
}
if (isset($tokens[$first]['scope_condition']) === true) {
$scopeCloser = $first;
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$scopeCloser]['scope_condition'], true);
$currentIndent = $tokens[$first]['column'] - 1;
if (isset($adjustments[$first]) === true) {
$currentIndent += $adjustments[$first];
}
// Make sure it is divisible by our expected indent.
if ($tokens[$tokens[$scopeCloser]['scope_condition']]['code'] !== T_CLOSURE) {
$currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent);
}
$setIndents[$first] = $currentIndent;