Skip to content

Commit 5cc68dc

Browse files
committed
SlevomatCodingStandard.ControlStructures.NewWithParentheses: Fixed false positive for readonly anonymous class
1 parent 8aa456f commit 5cc68dc

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

SlevomatCodingStandard/Sniffs/ControlStructures/NewWithParenthesesSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use const T_INLINE_THEN;
1919
use const T_NEW;
2020
use const T_OPEN_PARENTHESIS;
21+
use const T_READONLY;
2122
use const T_SEMICOLON;
2223

2324
class NewWithParenthesesSniff implements Sniff
@@ -49,7 +50,7 @@ public function process(File $phpcsFile, $newPointer): void
4950
$nextPointer = AttributeHelper::getAttributeTarget($phpcsFile, $nextPointer);
5051
}
5152

52-
if ($tokens[$nextPointer]['code'] === T_ANON_CLASS) {
53+
if ($tokens[$nextPointer]['code'] === T_ANON_CLASS || $tokens[$nextPointer]['code'] === T_READONLY) {
5354
return;
5455
}
5556

tests/Sniffs/ControlStructures/data/newWithoutParenthesesNoErrors.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php // lint >= 8.3
22

33
$foo = new \DateTimeImmutable;
44

@@ -32,6 +32,10 @@ public static function getInstance()
3232

3333
};
3434

35+
$coo = new readonly class {
36+
37+
};
38+
3539
$whitespaceBetweenClassNameAndParentheses = new stdClass ;
3640

3741
new $a->{'b'}["c"]->$d['e'][1];

0 commit comments

Comments
 (0)