common icon indicating copy to clipboard operation
common copied to clipboard

fix: proxy with BackedEnum integer on identifier

Open Gwemox opened this issue 3 years ago • 0 comments

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();
    }

Gwemox avatar Oct 14 '22 09:10 Gwemox