Skip to content

Commit b7e305f

Browse files
committed
PHPDoc tag @phpstan-consistent-constructor no longer requires constructor to exist
1 parent 85fd1a4 commit b7e305f

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/Rules/Classes/NewStaticRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public function processNode(Node $node, Scope $scope): array
5656
->build(),
5757
];
5858
if (!$classReflection->hasConstructor()) {
59+
if ($classReflection->hasConsistentConstructor()) {
60+
return [];
61+
}
62+
5963
return $messages;
6064
}
6165

tests/PHPStan/Rules/Classes/NewStaticRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,9 @@ public function testBug9654(): void
6262
$this->analyse([__DIR__ . '/data/bug-9654.php'], $errors);
6363
}
6464

65+
public function testBug11316(): void
66+
{
67+
$this->analyse([__DIR__ . '/data/bug-11316.php'], []);
68+
}
69+
6570
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Bug11316;
4+
5+
/** @phpstan-consistent-constructor */
6+
class Model
7+
{
8+
public static function create(): static
9+
{
10+
return new static();
11+
}
12+
}
13+
14+
class ParentWithoutConstructor
15+
{
16+
17+
}
18+
19+
/** @phpstan-consistent-constructor */
20+
class ChildExtendingParentWithoutConstructor extends ParentWithoutConstructor
21+
{
22+
23+
public static function create(): static
24+
{
25+
return new static();
26+
}
27+
28+
}

0 commit comments

Comments
 (0)