-
Notifications
You must be signed in to change notification settings - Fork 112
Closed
Description
From PHPStan 1.0 there is a better Detecting Unused Private Properties, Methods, and Constants enabled.
Since then, many entity properties get reported as
Property $foo is never written, only read.
In my case, all of them were properties using Timestampable from Doctrine Extensions, without setter/getter.
I suggest to include by default with phpstan-doctrine a PHPStan extension that marks properties using Timestampable as always written, following the official PHPStan instructions
What do you think?
Here a basic example of that extension that work in my case:
<?php
namespace App\PHPStan;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Rules\Properties\ReadWritePropertiesExtension;
final class PropertiesExtension implements ReadWritePropertiesExtension
{
public function isAlwaysRead(PropertyReflection $property, string $propertyName): bool
{
return false;
}
public function isAlwaysWritten(PropertyReflection $property, string $propertyName): bool
{
return str_contains($property->getDocComment(), '@Gedmo\Timestampable');
}
public function isInitialized(PropertyReflection $property, string $propertyName): bool
{
return false;
}
}Metadata
Metadata
Assignees
Labels
No labels