Description
Today encountered problem with codesniffer on PSR1/PSR2 rules set.
In my class I have next part of code:
protected function getCategoryFeatureRepositoryMock(
array $map,
int $getExistingIdsCalls
): CategoryFeatureRepositoryInterface {
/** @var MockObject|CategoryFeatureRepository $repository */
$repository = $this->getMockBuilder(CategoryFeatureRepository::class)
->disableOriginalConstructor()
->setMethods(['getCategoryFeatureIds'])
->getMock();
$repository->expects(self::exactly($getExistingIdsCalls))
->method('getCategoryFeatureIds')
->willReturnCallback(
function (string $providerId, int $categoryId, array $idsList) use ($map) { \\ line 91
self::assertEquals($this->providerId, $providerId); \\ line 92
self::assertEquals($this->categoryId, $categoryId); \\ line 93
\\ line 94
return \array_intersect($map, $idsList); \\ line 95
} \\ line 96
);
return $repository;
}
It is well formatted by PhpStorm but code sniffer throw next errors for this code part:
----------------------------------------------------------------------------------------
FOUND 5 ERRORS AFFECTING 5 LINES
----------------------------------------------------------------------------------------
91 | ERROR | [x] Line indented incorrectly; expected at least 24 spaces, found 23
92 | ERROR | [x] Line indented incorrectly; expected at least 28 spaces, found 27
93 | ERROR | [x] Line indented incorrectly; expected at least 28 spaces, found 27
95 | ERROR | [x] Line indented incorrectly; expected at least 28 spaces, found 27
96 | ERROR | [x] Line indented incorrectly; expected 24 spaces, found 23
Firstly I decided that there is something with my IDE formatting settings and manually edited as required - I added 1 space for each marked line. But code sniffer again throw bad formatting error:
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------
91 | ERROR | [x] Multi-line function call not indented correctly; expected 23 spaces but found 24
---------------------------------------------------------------------------------------------------
What should I do in this case?
P.S. As temporary bypass I edited my code part by splitting chained method calls:
protected function getCategoryFeatureRepositoryMock(
array $map,
int $getExistingIdsCalls
): CategoryFeatureRepositoryInterface {
/** @var MockObject|CategoryFeatureRepository $repository */
$repository = $this->getMockBuilder(CategoryFeatureRepository::class)
->disableOriginalConstructor()
->setMethods(['getCategoryFeatureIds'])
->getMock();
$repository->expects(self::exactly($getExistingIdsCalls))
->method('getCategoryFeatureIds');
$repository->willReturnCallback( \\ <----------- this is take away code sniffer errors.
function (string $providerId, int $categoryId, array $idsList) use ($map) {
self::assertEquals($this->providerId, $providerId);
self::assertEquals($this->categoryId, $categoryId);
return \array_intersect($map, $idsList);
}
);
return $repository;
}