Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Weak) generics on ide-helper:models array types. #1614

Open
LauJosefsen opened this issue Nov 19, 2024 · 2 comments
Open

(Weak) generics on ide-helper:models array types. #1614

LauJosefsen opened this issue Nov 19, 2024 · 2 comments

Comments

@LauJosefsen
Copy link
Contributor

Summary

Hi.

Since the higher PHPStan levels wants generics on array types, I was wondering how you would feel about changing array properties on models from

 * @property array|null $metadata

to

 * @property array<array-key, mixed>|null $metadata

This looks like it could be a small change to the ModelsCommand https://github.com/barryvdh/laravel-ide-helper/blob/master/src/Console/ModelsCommand.php#L392 to

                case 'array':
                case 'json':
                    $realType = 'array<array-key, mixed>';

Alternatively it would be nice to be able to implement this using the Barryvdh\LaravelIdeHelper\Contracts\ModelHookInterface, but I think a public getter to properties in \Barryvdh\LaravelIdeHelper\Console\ModelsCommand is needed.

@LauJosefsen
Copy link
Contributor Author

Our use case is running ide-helper:models as part of CI to enforce migrations matching what PHPstan is checking. For this purpose we use the reset option. This is a very nice setup as it our properties on our models always match the migrations and casts, and static analysis is able to detect more errors.

How would you feel of an option to enforce the types like reset does, but keep some changes like generics? I am happy to contribute any changes needed, but before investing the hours I would love to get some feedback for the proposals.

@chescos
Copy link

chescos commented Dec 4, 2024

I also ran into this issue. Currently ignoring the error in phpstan.neon like this:

    ignoreErrors:
        - '#^Class App\\Models\\.+? has PHPDoc tag @property(-read)? for property \$.+? with no value type specified in iterable type array\.$#'

But that's obviously not optimal. It would be great if laravel-ide-helper would generate a compatible PHPDoc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants