phpstan / phpstan-doctrine

Doctrine extensions for PHPStan
MIT License
598 stars 97 forks source link

ODM always-read and written properties #613

Open aivchen opened 1 month ago

aivchen commented 1 month ago

Hi! Thank you for this project - it's awesome and we use it a lot!

But I noticed, currently, phpstan-doctrine doesn't support analysing of always-read and written properties in ODM documents like this:

/**
 * @ODM\Document
 */
class MyDocument
{

    /** @ODM\Id */
    private int $id;

    /** @ODM\Field */
    private int $myField;

    private int $unused;

}

PHPStan reports that all three properties are unused.

I found src/Rules/Doctrine/ORM/PropertiesExtension.php but it's working only with ORM entities.

I don't have experience in writing extension for PHPStan, but I think I can write a similar implementation for ODM by analogy with ORM. What do you think?