Skip to content

[dev-master] PHPDoc tag @var for property App\Company::$administrations with type App\Collection<int, App\Administration>|array<App\Administration> is not subtype of native type App\Collection. #4715

@ruudk

Description

@ruudk

Bug report

After phpstan/phpstan-src#477 was merged I decided to checkout phpstan dev-master (coming from 0.12.81) to see if it solved my problem.

It introduced 681 new errors in my codebase 😳 It could be that this is totally correct, and that I should fix some things, but since you haven't tagged a release yet, I wanted to check-in to see if all is good.

I'm getting these errors:

 ------ -------------------------------------------------------------------------------------------------------------------------------
  Line   src/Company.php
 ------ -------------------------------------------------------------------------------------------------------------------------------
  38     PHPDoc tag @var for property App\Company::$administrations with type
         array<App\Administration>|Doctrine\Common\Collections\Collection<int,
         App\Administration> is not subtype of native type Doctrine\Common\Collections\Collection.
  38     Property App\Company::$administrations type mapping mismatch: property can contain
         Doctrine\Common\Collections\Collection but database expects
         Doctrine\Common\Collections\Collection&iterable<App\Administration>.
  38     Property App\Company::$administrations with generic interface
         Doctrine\Common\Collections\Collection does not specify its types: TKey, T
         💡 You can turn this off by setting checkGenericClassInNonGenericObjectType: false in your
         phpstan.neon.
  60     Method App\Company::getAdministrations() return type with generic interface
         Doctrine\Common\Collections\Collection does not specify its types: TKey, T
         💡 You can turn this off by setting checkGenericClassInNonGenericObjectType: false in your
         phpstan.neon.
  60     PHPDoc tag @return with type
         array<App\Administration>|Doctrine\Common\Collections\Collection<int,
         App\Administration> is not subtype of native type Doctrine\Common\Collections\Collection.
 ------ -----------------------------------------------------------------------------------------------------------------

Code snippet that reproduces the problem

/**
 * @var Collection<int, Administration>|Administration[]
 */
protected Collection $administrations;

https://phpstan.org/r/dd4860d5-62df-4b99-bfe0-5470a6764355

The reason why I add |Administration[] is to let PHPStorm understand the type properly. Before, PHPStan would just allow this.

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