Skip to content

Conversation

janedbal
Copy link
Contributor

  • Since this rule reports assignment issues, it is irrelevant if it is always read or not
  • Found this by dropping similar rule of our own and Doctrine entities are no longer reported:
#[Entity]
class FooEntity 
{

    /**
     * @var array<string>|null
     */
    #[Column(type: Types::SIMPLE_ARRAY, nullable: true)]
    private ?array $zones; // null never assigned

    /**
     * @param list<string> $zones
     */
    public function __construct(
        array $zones,
    )
    {
        $this->zones = $zones;
    }

}

@ondrejmirtes ondrejmirtes merged commit adcabb3 into phpstan:2.0.x Nov 23, 2024
422 of 425 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

@ondrejmirtes
Copy link
Member

FYI I had to revert this. It causes false positives for properties like this:

    #[ORM\Column(type: 'json', nullable: true)]
    private ?array $rawContent;

After your change PHPStan reports "is never assigned null so it can be removed from the property type" which is not exactly true, because the DB column allows null and there can be null values coming from the database.

Ideally we'd have an extension that would tell PHPStan bout the meaning of #[ORM\Column(type: 'json', nullable: true)] (and the fact that null can be written there) but we don't have that information right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants