Skip to content

Commit 75e4cf9

Browse files
committed
RequireMultiLineCallSniff: Improved fixer
1 parent a3a10c1 commit 75e4cf9

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

SlevomatCodingStandard/Sniffs/Functions/RequireMultiLineCallSniff.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ public function process(File $phpcsFile, $stringPointer): void
143143
$phpcsFile->fixer->addContentBefore($i, $phpcsFile->eolChar . $parametersIndentation);
144144
} elseif ($tokens[$i]['content'] === $phpcsFile->eolChar) {
145145
$phpcsFile->fixer->addContent($i, $oneIndentation);
146+
} else {
147+
// Create conflict so inner calls are fixed in next loop
148+
$phpcsFile->fixer->replaceToken($i, $tokens[$i]['content']);
146149
}
147150
}
148151

tests/Sniffs/Functions/RequireMultiLineCallSniffTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function testErrors(): void
1717
{
1818
$report = self::checkFile(__DIR__ . '/data/requireMultiLineCallErrors.php');
1919

20-
self::assertSame(11, $report->getErrorCount());
20+
self::assertSame(13, $report->getErrorCount());
2121

2222
self::assertSniffError(
2323
$report,
@@ -85,6 +85,18 @@ public function testErrors(): void
8585
RequireMultiLineCallSniff::CODE_REQUIRED_MULTI_LINE_CALL,
8686
'Call of method doSomething() should be splitted to more lines.'
8787
);
88+
self::assertSniffError(
89+
$report,
90+
44,
91+
RequireMultiLineCallSniff::CODE_REQUIRED_MULTI_LINE_CALL,
92+
'Call of method doNowOrAfterCommit() should be splitted to more lines.'
93+
);
94+
self::assertSniffError(
95+
$report,
96+
45,
97+
RequireMultiLineCallSniff::CODE_REQUIRED_MULTI_LINE_CALL,
98+
'Call of method sendDelayedMessage() should be splitted to more lines.'
99+
);
88100

89101
self::assertAllFixedInFile($report);
90102
}

tests/Sniffs/Functions/data/requireMultiLineCallErrors.fixed.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,20 @@ static function () use ($phpcsFile, $pointer): array {
7373
}
7474
);
7575
};
76+
77+
class Nothing
78+
{
79+
public function commit($message, $originalQueueName, $delayedQueueName, $nextAttemptTime)
80+
{
81+
$this->doNowOrAfterCommit(
82+
function () use ($message, $originalQueueName, $delayedQueueName, $nextAttemptTime): void {
83+
$this->instantQueueMessageProducer->sendDelayedMessage(
84+
$message,
85+
$originalQueueName,
86+
$delayedQueueName,
87+
$nextAttemptTime
88+
);
89+
}
90+
);
91+
}
92+
}

tests/Sniffs/Functions/data/requireMultiLineCallErrors.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ function ($phpcsFile, $pointer) {
3636
return Whatever::doSomething($phpcsFile, sprintf('annotations-%d', $pointer), static function () use ($phpcsFile, $pointer): array {
3737
});
3838
};
39+
40+
class Nothing
41+
{
42+
public function commit($message, $originalQueueName, $delayedQueueName, $nextAttemptTime)
43+
{
44+
$this->doNowOrAfterCommit(function () use ($message, $originalQueueName, $delayedQueueName, $nextAttemptTime): void {
45+
$this->instantQueueMessageProducer->sendDelayedMessage($message, $originalQueueName, $delayedQueueName, $nextAttemptTime);
46+
});
47+
}
48+
}

0 commit comments

Comments
 (0)