Skip to content

Commit 214ca45

Browse files
Add scenario
1 parent 21bcb53 commit 214ca45

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/Rules/Methods/CallToConstructorStatementWithoutSideEffectsRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public function processNode(Node $node, Scope $scope): array
5757
}
5858

5959
$constructor = $classReflection->getConstructor();
60+
if (count($constructor->getAsserts()->getAsserts()) > 0) {
61+
return [];
62+
}
63+
6064
$methodResult = $scope->getType($instantiation);
6165
if ($methodResult instanceof NeverType && $methodResult->isExplicit()) {
6266
return [];

tests/PHPStan/Rules/Methods/CallToConstructorStatementWithoutSideEffectsRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ public function testBug4455(): void
5151
$this->analyse([__DIR__ . '/data/bug-4455-constructor.php'], []);
5252
}
5353

54+
public function testBug12224(): void
55+
{
56+
$this->analyse([__DIR__ . '/data/bug-12224.php'], []);
57+
}
58+
5459
}

tests/PHPStan/Rules/Methods/data/bug-12224.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,22 @@ public function string(mixed $value): string
2929
}
3030
}
3131

32+
class AssertConstructor
33+
{
34+
/**
35+
* @phpstan-pure
36+
* @phpstan-assert string $value
37+
*/
38+
public function __construct(mixed $value)
39+
{
40+
if (!\is_string($value)) {
41+
throw new \RuntimeException();
42+
}
43+
}
44+
}
45+
3246
/** @var string|null $a */
3347
$a = '';
3448
Assert::staticString($a);
3549
(new Assert())->string($a);
50+
new AssertConstructor($a);

0 commit comments

Comments
 (0)