Skip to content

Commit 8f11e0f

Browse files
committed
Cleanup
1 parent f026751 commit 8f11e0f

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

SlevomatCodingStandard/Sniffs/ControlStructures/DisallowTrailingMultiLineTernaryOperatorSniff.php

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use SlevomatCodingStandard\Helpers\IndentationHelper;
99
use SlevomatCodingStandard\Helpers\TernaryOperatorHelper;
1010
use SlevomatCodingStandard\Helpers\TokenHelper;
11-
use function strlen;
12-
use function substr;
1311
use const T_INLINE_ELSE;
1412
use const T_INLINE_THEN;
1513
use const T_WHITESPACE;
@@ -57,14 +55,19 @@ public function process(File $phpcsFile, $inlineThenPointer): void
5755
}
5856

5957
$inlineElsePointer = TernaryOperatorHelper::getElsePointer($phpcsFile, $inlineThenPointer);
60-
$endOfLineBeforeInlineThenPointer = TokenHelper::findLastTokenOnPreviousLine($phpcsFile, $inlineThenPointer);
6158

62-
$indentation = $this->getIndentation($phpcsFile, $endOfLineBeforeInlineThenPointer);
6359
$pointerBeforeInlineThen = TokenHelper::findPreviousEffective($phpcsFile, $inlineThenPointer - 1);
6460
$pointerAfterInlineThen = TokenHelper::findNextExcluding($phpcsFile, [T_WHITESPACE], $inlineThenPointer + 1);
6561
$pointerBeforeInlineElse = TokenHelper::findPreviousEffective($phpcsFile, $inlineElsePointer - 1);
6662
$pointerAfterInlineElse = TokenHelper::findNextExcluding($phpcsFile, [T_WHITESPACE], $inlineElsePointer + 1);
6763

64+
$indentation = IndentationHelper::addIndentation(
65+
IndentationHelper::getIndentation(
66+
$phpcsFile,
67+
TokenHelper::findFirstNonWhitespaceOnLine($phpcsFile, $inlineThenPointer)
68+
)
69+
);
70+
6871
$phpcsFile->fixer->beginChangeset();
6972

7073
FixerHelper::removeBetween($phpcsFile, $pointerBeforeInlineThen, $inlineThenPointer);
@@ -82,21 +85,4 @@ public function process(File $phpcsFile, $inlineThenPointer): void
8285
$phpcsFile->fixer->endChangeset();
8386
}
8487

85-
private function getIndentation(File $phpcsFile, int $endOfLinePointer): string
86-
{
87-
$pointerAfterWhitespace = TokenHelper::findNextNonWhitespace($phpcsFile, $endOfLinePointer + 1);
88-
$actualIndentation = TokenHelper::getContent($phpcsFile, $endOfLinePointer + 1, $pointerAfterWhitespace - 1);
89-
90-
if (strlen($actualIndentation) !== 0) {
91-
return $actualIndentation . (
92-
substr($actualIndentation, -1) === IndentationHelper::TAB_INDENT
93-
? IndentationHelper::TAB_INDENT
94-
: IndentationHelper::SPACES_INDENT
95-
);
96-
}
97-
98-
$tabPointer = TokenHelper::findPreviousContent($phpcsFile, T_WHITESPACE, IndentationHelper::TAB_INDENT, $endOfLinePointer - 1);
99-
return $tabPointer !== null ? IndentationHelper::TAB_INDENT : IndentationHelper::SPACES_INDENT;
100-
}
101-
10288
}

0 commit comments

Comments
 (0)