New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReadWritePropertiesExtension is not respected with readonly property #6632
Comments
This bug report is missing a link to reproduction on phpstan.org. It will most likely be closed after manual review. |
I think I cannot reproduce it on the playground since it needs an Extension |
I'm not sure about the nature of this problem. Do you experience this with phpstan-doctrine, or with your own custom ReadWritePropertiesExtension? |
It's my own ReadWritePropertiesExtension final class DoctrineEntityPropertiesExtension implements ReadWritePropertiesExtension
{
public function isAlwaysRead(PropertyReflection $property, string $propertyName): bool
{
return $this->hasDoctrineAnnotation($property);
}
public function isAlwaysWritten(PropertyReflection $property, string $propertyName): bool
{
return $this->hasDoctrineAnnotation($property);
}
public function isInitialized(PropertyReflection $property, string $propertyName): bool
{
return $this->hasDoctrineAnnotation($property);
}
private function hasDoctrineAnnotation(PropertyReflection $property): bool
{
if (!$property instanceof \PHPStan\Reflection\Php\PhpPropertyReflection) {
return false;
}
$attributes = $property->getNativeReflection()->getAttributes();
foreach ($attributes as $attribute) {
if (str_starts_with($attribute->getName(), 'Doctrine\ORM')) {
return true;
}
}
return false;
}
} |
Looks like MissingReadOnlyPropertyAssignRule doesn't work with ReadWritePropertiesExtension but should. @herndlm Could you please try reproducing the problem with a new RuleTestCase child class (that allows you to register a custom extension in |
Sure, is on my virtual list to be looked at next. |
Fixed: phpstan/phpstan-src#1357 |
@noemi-salaun did you check already if this is working for you now? Just asking, because we seem to be still having a related problem in the phpstan-doctrine extension and this might tell me already if phpstan or phpstan-doctrine is the cause. |
@herndlm I did not, sorry. I was on a extended weekend :) |
It's been released already https://github.com/phpstan/phpstan/releases/tag/1.7.3. |
It looks good :) PHPStan warns me about an unused "Ignored error pattern" -
message: '#Class .* has an uninitialized readonly property \$.*\. Assign it in the constructor\.#'
paths:
- src/Entity Thanks for the awesome job ;) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report
I have Doctrine entities with an
$id
properties that are never initialized in my code. I made PHPStan aware of it with aReadWritePropertiesExtension
and it works perfectly.But if I add the new
readonly
keyword on my property, PHPStan give me this errorCode snippet that reproduces the problem
Expected output
I expect no error from PHPStan, since the extension tell it that the property is always initialized
The text was updated successfully, but these errors were encountered: