Skip to content

Commit

Permalink
Merge branch refs/heads/1.10.x into 1.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
phpstan-bot committed Jul 18, 2023
2 parents a599885 + d22a9f1 commit 9362748
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Node/ClassPropertiesNode.php
Expand Up @@ -112,6 +112,7 @@ public function getUninitializedProperties(
if ($extensions === null) {
$extensions = $this->readWritePropertiesExtensionProvider->getExtensions();
}
$initializedViaExtension = [];
foreach ($this->getProperties() as $property) {
if ($property->isStatic()) {
continue;
Expand All @@ -134,6 +135,7 @@ public function getUninitializedProperties(
continue;
}
$is = TrinaryLogic::createYes();
$initializedViaExtension[$property->getName()] = true;
break;
}
}
Expand Down Expand Up @@ -197,7 +199,11 @@ public function getUninitializedProperties(
if ($usage instanceof PropertyWrite) {
if (array_key_exists($propertyName, $initializedPropertiesMap)) {
$hasInitialization = $initializedPropertiesMap[$propertyName]->or($usageScope->hasExpressionType(new PropertyInitializationExpr($propertyName)));
if (!$hasInitialization->no() && !$usage->isPromotedPropertyWrite()) {
if (
!$hasInitialization->no()
&& !$usage->isPromotedPropertyWrite()
&& !array_key_exists($propertyName, $initializedViaExtension)
) {
$additionalAssigns[] = [
$propertyName,
$fetch->getLine(),
Expand Down
Expand Up @@ -7,6 +7,7 @@
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use function in_array;
use function strpos;
use const PHP_VERSION_ID;

/**
Expand Down Expand Up @@ -54,6 +55,25 @@ private function isEntityId(PropertyReflection $property, string $propertyName):
}

},
new class() implements ReadWritePropertiesExtension {

public function isAlwaysRead(PropertyReflection $property, string $propertyName): bool
{
return false;
}

public function isAlwaysWritten(PropertyReflection $property, string $propertyName): bool
{
return $this->isInitialized($property, $propertyName);
}

public function isInitialized(PropertyReflection $property, string $propertyName): bool
{
return $property->isPublic() &&
strpos($property->getDocComment() ?? '', '@init') !== false;
}

},
];
}

Expand Down
Expand Up @@ -287,3 +287,16 @@ public function getFoo(): int
}

}

class PropertyHasInitPhpDocButIsAlsoAssignedInConstructor
{

/** @init */
public readonly int $foo;

public function __construct(int $foo)
{
$this->foo = $foo;
}

}

0 comments on commit 9362748

Please sign in to comment.