Skip to content

Commit

Permalink
Fix false positives about uninitialized readonly properties
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Feb 2, 2024
1 parent d8fb1e8 commit 4cc3e25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Node/ClassPropertiesNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ private function getMethodsCalledFromConstructor(
continue;
}

if ($callScope->isInAnonymousFunction() && $callScope->getParentScope() !== null) {
$callScope = $callScope->getParentScope();
}

$methodName = $methodCallNode->name->toString();
if (array_key_exists($methodName, $initializedProperties)) {
foreach ($this->getInitializedProperties($callScope, $initializedProperties[$inMethod->getName()] ?? $initialInitializedProperties) as $propertyName => $isInitialized) {
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Properties/data/bug-10048.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php declare(strict_types=1);
<?php // lint >= 8.1

namespace Bug10048;

Expand Down

0 comments on commit 4cc3e25

Please sign in to comment.