Skip to content

[RFC] Support by default that Gedmo properties are always written #231

@yguedidi

Description

@yguedidi

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions