rectorphp / type-perfect

Next level type declaration check PHPStan rules
https://getrector.com/blog/introducing-type-perfect-for-extra-safety
MIT License
73 stars 3 forks source link

ArrayObject access a bit too strict #27

Closed dereuromark closed 2 months ago

dereuromark commented 2 months ago
    /**
     * @param \Cake\Event\EventInterface $event
     * @param \ArrayObject<string, mixed> $data
     * @param \ArrayObject<string, mixed> $options
     *
     * @return void
     */
    public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options): void
    {
        if (isset($data['password']) && $data['password'] === '') {
            unset($data['password']);
        }
    }

From framework perspective this is the only way to work with it. I would not expect the errors here then, if I typehinted it as \ArrayObject<string, mixed> instead of just \ArrayObject etc:

Use explicit methods over array access on object
Use explicit methods over array access on object

TomasVotruba commented 2 months ago

I see. What do you suggest?

dereuromark commented 2 months ago

It should only alert for normal \ArrayObject annotation. Once you specify that it is expected to be used as assoc array, it should not alert anymore. Would make it possible to be used for us at least like this.

TomasVotruba commented 2 months ago

I see. I'm out of time for this package, so if you need such feature, please provide a patch 👍