Type hinting in PHPStorm for transfer object collections

vasily.rodin
vasily.rodin Spryker Solution Partner Posts: 25 ✨ - Novice

Hello community!

Recently on our project we've updated the `spryker/transfer` module, including this version: https://github.com/spryker/transfer/releases/tag/3.35.0

In the changelog, it says:

  • Adjusted docblock type hint for the collection using generic syntax ArrayObject<Object> instead ArrayObject|Object[].

This improvement makes sense to me, but PHPStorm does not support this properly.

With the new annotation, many of our tests no longer have type hinting. This happens in the case when we try to access ArrayObject element by index [0], [1], etc

I've tried different settings in PHPStorm (or even plugins), but couldn't find a solution. offsetGet or getArrayCopy don't work as well.

So my question here: am I missing something in PHPStorm? Or if the problem exists for all projects, maybe it makes sense to rollback the PHPDoc for collections in spryker/transfer module to the old logic?

Comments

  • profuel
    profuel Sprykee Posts: 55 🪐 - Explorer

    Hi, Vasily!

    It seems to me that this inconvenience is affecting only a very limited amount of developers, since we hear about it for the first time, although many of our customers are using this version of Transfer module.

    Semantically, we now define more accurate type for the properties of type ArrayObject.

    Though it seems to me as well - PhpStorm is not working correctly with PHP Generics.

    We will look into this issue as soon as possible.

    Meanwhile, I'm happy to support your report to PhpStorm in order to start supporting PHP Generics.

    I found that the support is very limited around 2 months ago, although PHP Stan supports them very well, what was our primary goal.