I have this error that I can't figure out if it is a bug or expected (and I don't know why)
Property PspAbstractBankAccount::$bankAccount type mapping mismatch: database can contain AbstractBankAccount but property expects T of TestAbstract.
I have this code
<?php
declare(strict_types=1);
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
* @ORM\Table()
*/
class AbstractBankAccount
{
/**
* @ORM\Id
* @ORM\Column
* @ORM\GeneratedValue
*/
protected int $id;
}
/**
* @template T of AbstractBankAccount
*
* @ORM\Entity()
* @ORM\Table()
*/
class PspAbstractBankAccount
{
/**
* @ORM\Id
* @ORM\Column
* @ORM\GeneratedValue
*/
protected int $id;
/**
* @var T
* @ORM\ManyToOne(targetEntity="AbstractBankAccount")
* @ORM\JoinColumn(nullable=false)
*/
protected AbstractBankAccount $bankAccount;
/**
* @return T
*/
public function getBankAccount(): AbstractBankAccount
{
return $this->bankAccount;
}
/**
* @param T $bankAccount
*/
public function __construct(AbstractBankAccount $bankAccount) {
$this->bankAccount = $bankAccount;
}
}
This is a simplified version of my actual code: both classes are abstract and used with SINGLE_TABLE Doctrine inheritance.
My goal is to "tell" phpstan & my IDE that implementations of PspAbstractBankAccount will work with a related implementation of AbstractBankAccount: for instance, the getBankAccount() method of PspEuropeanBankAccount extends PspAbstractBankAccount will return an EuropeanBankAccount extends AbstractBankAccount.
My phpstan setup
$ composer show phpstan/*
phpstan/phpstan 1.4.0 PHPStan - PHP Static Analysis Tool
phpstan/phpstan-doctrine 1.0.4 Doctrine extensions for PHPStan
phpstan/phpstan-phpunit 1.0.0 PHPUnit extensions and rules for PHPStan
phpstan/phpstan-strict-rules 1.1.0 Extra strict and opinionated rules for PHPStan
phpstan/phpstan-symfony 1.1.1 Symfony Framework extensions and rules for PHPStan
phpstan/phpstan-webmozart-assert 1.0.7 PHPStan webmozart/assert extension
Hello
I have this error that I can't figure out if it is a bug or expected (and I don't know why)
I have this code
This is a simplified version of my actual code: both classes are abstract and used with
SINGLE_TABLE
Doctrine inheritance. My goal is to "tell" phpstan & my IDE that implementations ofPspAbstractBankAccount
will work with a related implementation ofAbstractBankAccount
: for instance, thegetBankAccount()
method ofPspEuropeanBankAccount extends PspAbstractBankAccount
will return anEuropeanBankAccount extends AbstractBankAccount
.My phpstan setup
Both commands were run before executing phpstan
Thank you for your help!