Skip to content

Commit 5ec4cd4

Browse files
committed
SlevomatCodingStandard.ControlStructures.NewWithParentheses: Fixed false positive
1 parent bacbc0a commit 5ec4cd4

File tree

5 files changed

+12
-2
lines changed

5 files changed

+12
-2
lines changed

SlevomatCodingStandard/Sniffs/ControlStructures/NewWithParenthesesSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public function process(File $phpcsFile, $newPointer): void
4848
return;
4949
}
5050

51+
if ($tokens[$nextPointer]['code'] === T_OPEN_PARENTHESIS) {
52+
$nextPointer = $tokens[$nextPointer]['parenthesis_closer'];
53+
}
54+
5155
$shouldBeOpenParenthesisPointer = $nextPointer + 1;
5256
do {
5357
$shouldBeOpenParenthesisPointer = TokenHelper::findNext(

tests/Sniffs/ControlStructures/NewWithParenthesesSniffTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public function testErrors(): void
1717
{
1818
$report = self::checkFile(__DIR__ . '/data/newWithParenthesesErrors.php', [], [NewWithParenthesesSniff::CODE_MISSING_PARENTHESES]);
1919

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

22-
foreach ([3, 9, 17, 22, 25, 29, 35, 37, 40, 43, 45, 47, 48, 50, 52, 57] as $line) {
22+
foreach ([3, 9, 17, 22, 25, 29, 35, 37, 40, 43, 45, 47, 48, 50, 52, 57, 60] as $line) {
2323
self::assertSniffError($report, $line, NewWithParenthesesSniff::CODE_MISSING_PARENTHESES);
2424
}
2525

tests/Sniffs/ControlStructures/data/newWithParenthesesErrors.fixed.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ public static function getInstance()
5656
$aaa = [
5757
(string) new stdClass() => new stdClass()
5858
];
59+
60+
$aaaa = new (stdClass::class)();

tests/Sniffs/ControlStructures/data/newWithParenthesesErrors.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ public static function getInstance()
5656
$aaa = [
5757
(string) new stdClass => new stdClass
5858
];
59+
60+
$aaaa = new (stdClass::class);

tests/Sniffs/ControlStructures/data/newWithParenthesesNoErrors.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ public static function getInstance()
5656
$aaa = [
5757
(string) new stdClass() => new stdClass()
5858
];
59+
60+
$aaaa = new (stdClass::class)();

0 commit comments

Comments
 (0)