-
-
Notifications
You must be signed in to change notification settings - Fork 929
fix: array shape in ProviderInterface #7150
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
base: 4.1
Are you sure you want to change the base?
Conversation
With this syntax `request` and `resource_class` can be detected. Otherwise it just becomes an unsealed associative array.
needs #7154 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
src/State/ProviderInterface.php
Outdated
* @param array<string, mixed> $uriVariables | ||
* @param array<string, mixed>|array{request?: Request, resource_class?: string} $context | ||
* @param array<string, mixed> $uriVariables | ||
* @param array{request?: Request, resource_class?: string, ...array<string, mixed>} $context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this syntax doesn't work yet? @VincentLanglet any idea how to fix this and #7151
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No unlike psalm, phpstan doesnt work well with sealed/unsealed syntax for array
(There is some issue about it in phpstn repo)
I can take a look how to solve your issue @soyuka but it will be in one week cause i'm in vacation without a computer atm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I fixed the syntax but unfortunately it causes issues because phpstan only added parsing support, it doesn't make use of it yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes so maybe (and unfortunately) the solution will be to only use
Array<string, mixed>
Without more precision...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two solutions I have in mind @soyuka are:
-
Just using
@param array<string, mixed> $context
-
Or Using
@phpstan-param array<string, mixed> $context
@psalm-param array{request?: Request, resource_class?: string, ...array<string, mixed>} $context
What do you prefer ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@param array<string, mixed> $context
@psalm-param array{request?: Request, resource_class?: string, ...array<string, mixed>} $context
Does this work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work?
Unfortunately phpstan load @psalm-param
over @param
.
So it's either
@param array<string, mixed> $context
@phpstan-param array<string, mixed> $context
@psalm-param array{request?: Request, resource_class?: string, ...array<string, mixed>} $context
or just
@phpstan-param array<string, mixed> $context
@psalm-param array{request?: Request, resource_class?: string, ...array<string, mixed>} $context
It could be good to fix IriConverterInterface and ParameterProviderInterface too. |
With this syntax
request
andresource_class
can be detected. Otherwise it just becomes an unsealed associative array.See phpstan/phpdoc-parser#250 for the syntax. I reported phpstan/phpstan#13019 because the extra keys aren't working as per the PR that added support, but the known keys do.