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

[10.x] Narrow down array type for $attributes in CastsAttributes #47365

Merged
merged 1 commit into from Jun 6, 2023

Conversation

devfrey
Copy link
Contributor

@devfrey devfrey commented Jun 6, 2023

The documentation contains an example with an array<string, mixed> type hint for $attributes, which is more specific than array, as type hinted in the source. However, if I wanted to use the more specific type hint from the example in my application, PHPStan reports the following:

Parameter #4 $attributes (array<string, mixed>) of method App\Casts\MyCast::get() should be contravariant with parameter $attributes (array) of method Illuminate\Contracts\Database\Eloquent\CastsAttributes<App\Value\MyValueObject,string>::get()

So I propose to update the type hint in the source to be consistent with the example in the documentation. Thanks!

Edit: the make:cast stub also uses the array<string, mixed> type hint.

@taylorotwell taylorotwell merged commit 2e471cd into laravel:10.x Jun 6, 2023
17 checks passed
@devfrey devfrey deleted the patch-2 branch June 6, 2023 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants