Skip to content

Commit

Permalink
RequireMultiLineCallSniff: Improved fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Aug 28, 2020
1 parent a3a10c1 commit 75e4cf9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
Expand Up @@ -143,6 +143,9 @@ public function process(File $phpcsFile, $stringPointer): void
$phpcsFile->fixer->addContentBefore($i, $phpcsFile->eolChar . $parametersIndentation);
} elseif ($tokens[$i]['content'] === $phpcsFile->eolChar) {
$phpcsFile->fixer->addContent($i, $oneIndentation);
} else {
// Create conflict so inner calls are fixed in next loop
$phpcsFile->fixer->replaceToken($i, $tokens[$i]['content']);
}
}

Expand Down
14 changes: 13 additions & 1 deletion tests/Sniffs/Functions/RequireMultiLineCallSniffTest.php
Expand Up @@ -17,7 +17,7 @@ public function testErrors(): void
{
$report = self::checkFile(__DIR__ . '/data/requireMultiLineCallErrors.php');

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

self::assertSniffError(
$report,
Expand Down Expand Up @@ -85,6 +85,18 @@ public function testErrors(): void
RequireMultiLineCallSniff::CODE_REQUIRED_MULTI_LINE_CALL,
'Call of method doSomething() should be splitted to more lines.'
);
self::assertSniffError(
$report,
44,
RequireMultiLineCallSniff::CODE_REQUIRED_MULTI_LINE_CALL,
'Call of method doNowOrAfterCommit() should be splitted to more lines.'
);
self::assertSniffError(
$report,
45,
RequireMultiLineCallSniff::CODE_REQUIRED_MULTI_LINE_CALL,
'Call of method sendDelayedMessage() should be splitted to more lines.'
);

self::assertAllFixedInFile($report);
}
Expand Down
17 changes: 17 additions & 0 deletions tests/Sniffs/Functions/data/requireMultiLineCallErrors.fixed.php
Expand Up @@ -73,3 +73,20 @@ static function () use ($phpcsFile, $pointer): array {
}
);
};

class Nothing
{
public function commit($message, $originalQueueName, $delayedQueueName, $nextAttemptTime)
{
$this->doNowOrAfterCommit(
function () use ($message, $originalQueueName, $delayedQueueName, $nextAttemptTime): void {
$this->instantQueueMessageProducer->sendDelayedMessage(
$message,
$originalQueueName,
$delayedQueueName,
$nextAttemptTime
);
}
);
}
}
10 changes: 10 additions & 0 deletions tests/Sniffs/Functions/data/requireMultiLineCallErrors.php
Expand Up @@ -36,3 +36,13 @@ function ($phpcsFile, $pointer) {
return Whatever::doSomething($phpcsFile, sprintf('annotations-%d', $pointer), static function () use ($phpcsFile, $pointer): array {
});
};

class Nothing
{
public function commit($message, $originalQueueName, $delayedQueueName, $nextAttemptTime)
{
$this->doNowOrAfterCommit(function () use ($message, $originalQueueName, $delayedQueueName, $nextAttemptTime): void {
$this->instantQueueMessageProducer->sendDelayedMessage($message, $originalQueueName, $delayedQueueName, $nextAttemptTime);
});
}
}

0 comments on commit 75e4cf9

Please sign in to comment.