Skip to content

Commit 12270c0

Browse files
committed
Fix new NoConstructor purity
1 parent b116d25 commit 12270c0

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3130,6 +3130,7 @@ static function (): void {
31303130
$className = $scope->resolveName($expr->class);
31313131
}
31323132

3133+
$classReflection = null;
31333134
if ($className !== null && $this->reflectionProvider->hasClass($className)) {
31343135
$classReflection = $this->reflectionProvider->getClass($className);
31353136
if ($classReflection->hasConstructor()) {
@@ -3160,7 +3161,7 @@ static function (): void {
31603161
$certain,
31613162
);
31623163
}
3163-
} else {
3164+
} elseif ($classReflection === null) {
31643165
$impurePoints[] = new ImpurePoint(
31653166
$scope,
31663167
$expr,

tests/PHPStan/Rules/Pure/data/pure-method.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,23 @@ public function doFoo(
297297
}
298298

299299
}
300+
301+
class NoConstructor
302+
{
303+
304+
}
305+
306+
class TestNoConstructor
307+
{
308+
309+
/**
310+
* @phpstan-pure
311+
*/
312+
public function doFoo(): int
313+
{
314+
new NoConstructor();
315+
316+
return 1;
317+
}
318+
319+
}

0 commit comments

Comments
 (0)