Closed
Description
Hello ,
I have the following error in my phpstan report (level 8), I'm using php 8 with doctrine annotations. The following code is working fine, but phpstan raises me an error.
How can I fix it ?
Here's my configuration:
parameters:
level: 8
paths:
- src
- tests
symfony:
container_xml_path: var/cache/dev/App_KernelDevDebugContainer.xml
doctrine:
objectManagerLoader: tests/object-manager.php
bootstrapFiles:
- bin/.phpunit/phpunit/vendor/autoload.php
checkMissingIterableValueType: false
ignoreErrors:
- '#Property [a-zA-Z0-9\\_]+::\$entity type mapping mismatch: property can contain App\\Entity\\Behavior\\LoggableInterface but database expects [a-zA-Z0-9\\_]+\.#'
- '#Property [a-zA-Z0-9\\_]+::\$entity type mapping mismatch: database can contain [a-zA-Z0-9\\_]+ but property expects App\\Entity\\Behavior\\LoggableInterface.#'
- '#Property App\\Entity\\Bank\\Account::\$operations(.*)#'
- '#Property App\\Entity\\Accounting\\Plan::\$labels(.*)#'
- '#Property App\\Entity\\Accounting\\Plan::\$labelCategories(.*)#'
The entity mapping
#[ORM\ManyToMany(targetEntity: LabelVat::class)]
#[ORM\JoinTable(name: 'accounting_label_has_vat')]
/**
* @var Collection<int, LabelVat>&iterable<LabelVat>
*/
private Collection $vatRates;
The error
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line src/Entity/Accounting/Label.php
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
68 Property App\Entity\Accounting\Label::$vatRates type mapping mismatch: property can contain iterable but database expects Doctrine\Common\Collections\Collection&iterable<App\Entity\Accounting\LabelVat>.
120 Method App\Entity\Accounting\Label::getVatRates() 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.dist.
122 Method App\Entity\Accounting\Label::getVatRates() should return Doctrine\Common\Collections\Collection but returns iterable.
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Metadata
Metadata
Assignees
Labels
No labels