Skip to content

Commit 1855d72

Browse files
franmomukukulich
authored andcommitted
SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion: Fixes using prefixed var phpdoc
1 parent 9117a15 commit 1855d72

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

SlevomatCodingStandard/Sniffs/Classes/RequireConstructorPropertyPromotionSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ private function isPropertyDocCommentUseful(File $phpcsFile, int $propertyPointe
320320
}
321321

322322
foreach (AnnotationHelper::getAnnotations($phpcsFile, $propertyPointer) as $annotationType => $annotations) {
323-
if ($annotationType !== '@var') {
323+
if (!in_array($annotationType, ['@var', '@phpstan-var', '@psalm-var'], true)) {
324324
return true;
325325
}
326326

tests/Sniffs/Classes/RequireConstructorPropertyPromotionSniffTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testErrors(): void
2121
'enable' => true,
2222
]);
2323

24-
self::assertSame(6, $report->getErrorCount());
24+
self::assertSame(7, $report->getErrorCount());
2525

2626
self::assertSniffError(
2727
$report,
@@ -55,7 +55,13 @@ public function testErrors(): void
5555
);
5656
self::assertSniffError(
5757
$report,
58-
39,
58+
23,
59+
RequireConstructorPropertyPromotionSniff::CODE_REQUIRED_CONSTRUCTOR_PROPERTY_PROMOTION,
60+
'Required promotion of property $g.'
61+
);
62+
self::assertSniffError(
63+
$report,
64+
44,
5965
RequireConstructorPropertyPromotionSniff::CODE_REQUIRED_CONSTRUCTOR_PROPERTY_PROMOTION,
6066
'Required promotion of property $from.'
6167
);

tests/Sniffs/Classes/data/requireConstructorPropertyPromotionErrors.fixed.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class Whatever
66
#[SomeAttribute]
77
private $d;
88

9-
public function __construct(public string $a, protected int|null $b = 0, private ?bool $c = null, $d, private $e, private readonly string $f)
9+
/** @phpstan-param array<int, string> $g */
10+
public function __construct(public string $a, protected int|null $b = 0, private ?bool $c = null, $d, private $e, private readonly string $f, private array $g)
1011
{
1112
$this->d = $d;
1213
}

tests/Sniffs/Classes/data/requireConstructorPropertyPromotionErrors.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@ class Whatever
1919

2020
private readonly string $f;
2121

22-
public function __construct(string $a, int|null $b = 0, ?bool $c, $d, $e, string $f)
22+
/** @phpstan-var array<int, string> */
23+
private array $g;
24+
25+
/** @phpstan-param array<int, string> $g */
26+
public function __construct(string $a, int|null $b = 0, ?bool $c, $d, $e, string $f, array $g)
2327
{
2428
$this->a = $a;
2529
$this->b = $b;
2630
$this->c = $c;
2731
$this->d = $d;
2832
$this->e = $e;
2933
$this->f = $f;
34+
$this->g = $g;
3035
}
3136

3237
}

0 commit comments

Comments
 (0)