Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qa: Remove redundant code in WhiteSpace\ScopeIndentSniff as upstream is fixed #207

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ public function process(File $phpcsFile, $stackPtr)
if ($tokens[$prev]['line'] === $tokens[$i]['line']
&& ! ($fp = $this->findPrevious($phpcsFile, $i, [T_OBJECT_OPERATOR]))
) {
$endOfStatement = min($this->findEndOfStatement($phpcsFile, $i), $this->findNext($phpcsFile, $i));
$endOfStatement = min($phpcsFile->findEndOfStatement($i), $this->findNext($phpcsFile, $i));
$newLine = $this->hasContainNewLine($phpcsFile, $i, $endOfStatement);

if ($newLine) {
Expand Down Expand Up @@ -618,7 +618,7 @@ public function process(File $phpcsFile, $stackPtr)
],
true
)) {
$endOfStatement = $this->findEndOfStatement($phpcsFile, $i);
$endOfStatement = $phpcsFile->findEndOfStatement($i);
$newLine = $this->hasContainNewLine($phpcsFile, $i, $endOfStatement);

if ($newLine) {
Expand All @@ -640,7 +640,7 @@ public function process(File $phpcsFile, $stackPtr)
&& isset($tokens[$next]['scope_closer'])
&& $tokens[$next]['scope_closer'] === $next
) {
$endOfStatement = $this->findEndOfStatement($phpcsFile, $next);
$endOfStatement = $phpcsFile->findEndOfStatement($next);
$this->extras($endOfStatement, $this->indent);

$extraIndent += $this->indent;
Expand Down Expand Up @@ -946,70 +946,6 @@ private function findNext(File $phpcsFile, int $ptr, array $search = []) : ?int
return null;
}

/**
* Overrides File::findEndOfStatement as temporary solution until
* https://github.com/squizlabs/PHP_CodeSniffer/issues/2748
* is fixed.
*/
private function findEndOfStatement(File $phpcsFile, int $ptr) : int
{
$closingBracket = [
T_CLOSE_PARENTHESIS,
T_CLOSE_SQUARE_BRACKET,
T_CLOSE_CURLY_BRACKET,
T_CLOSE_SHORT_ARRAY,
];

$tokens = $phpcsFile->getTokens();
$lastToken = $phpcsFile->numTokens;

if ($tokens[$ptr]['code'] === T_DOUBLE_ARROW && $ptr < $lastToken) {
++$ptr;
}

while ($ptr < $lastToken) {
if ($tokens[$ptr]['code'] === T_OPEN_PARENTHESIS) {
$ptr = $tokens[$ptr]['parenthesis_closer'] + 1;
continue;
}

if ($tokens[$ptr]['code'] === T_OPEN_CURLY_BRACKET
|| $tokens[$ptr]['code'] === T_OPEN_SQUARE_BRACKET
|| $tokens[$ptr]['code'] === T_OPEN_SHORT_ARRAY
) {
$ptr = $tokens[$ptr]['bracket_closer'] + 1;
continue;
}

if (isset($tokens[$ptr]['scope_closer']) && $ptr < $tokens[$ptr]['scope_closer']) {
$ptr = $tokens[$ptr]['scope_closer'];
if (in_array($tokens[$ptr]['code'], $closingBracket, true)) {
++$ptr;
}
} elseif (isset($tokens[$ptr]['parenthesis_closer']) && $ptr < $tokens[$ptr]['parenthesis_closer']) {
$ptr = $tokens[$ptr]['parenthesis_closer'];
if (in_array($tokens[$ptr]['code'], $closingBracket, true)) {
++$ptr;
}
}

if ($tokens[$ptr]['code'] === T_COMMA
|| $tokens[$ptr]['code'] === T_SEMICOLON
|| $tokens[$ptr]['code'] === T_DOUBLE_ARROW
) {
return $ptr;
}

if (in_array($tokens[$ptr]['code'], $closingBracket, true)) {
return $phpcsFile->findPrevious(Tokens::$emptyTokens, $ptr - 1, null, true);
}

++$ptr;
}

return $lastToken;
}

/**
* Checks if there is another object operator
* before $ptr token.
Expand Down
Loading