doctrine / common

Doctrine Common
https://www.doctrine-project.org/projects/common.html
MIT License
5.79k stars 294 forks source link

fix: proxy with BackedEnum integer on identifier #997

Open Gwemox opened 2 years ago

Gwemox commented 2 years ago

If entity identifier return an int BackedEnum, Proxy Generator generate method with cast to int. But it's impossible to cast a BackedEnum to int.

Call getId() on proxy throw an error : Warning: Object of class App\\Enum\\ProviderId could not be converted to int

Original entity:

    public function getId(): ProviderId
    {
        return $this->id;
    }

Generated proxy method before fix:

    /**
     * {@inheritDoc}
     */
    public function getId(): \App\Enum\ProviderId
    {
        if ($this->__isInitialized__ === false) {
            return (int)  parent::getId();
        }

        $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', []);

        return parent::getId();
    }

Generated proxy method after fix:

    /**
     * {@inheritDoc}
     */
    public function getId(): \App\Enum\ProviderId
    {
        if ($this->__isInitialized__ === false) {
            return  parent::getId();
        }

        $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', []);

        return parent::getId();
    }