-
-
Notifications
You must be signed in to change notification settings - Fork 94
fix: Phpstan errors in current master build #413
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: master
Are you sure you want to change the base?
Changes from all commits
8624690
5030837
f13e78b
e4bbdeb
dbaeb9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,6 +151,12 @@ public function resolveLoader(mixed $resource) | |
| { | ||
| foreach ($this->loaders as $loader) { | ||
| if ($loader->supports($resource)) { | ||
| /** | ||
| * If the loader supports the provided resource, then it can safely be typed as | ||
| * LoaderInterface<ResourceType>. | ||
| * | ||
| * @var LoaderInterface<TResourceType> $loader | ||
| */ | ||
|
Comment on lines
+154
to
+159
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still need to narrow the type returned from Here, we assume that the caller will call Therefore, it doesn't matter if the type we return is stricter than the actual implementation of the loader we're returning, so long as it accepts the type of resource that was passed in. So the easiest way to do this is just to explicitly tag it the specialised type for phpstan. |
||
| return $loader; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,9 @@ interface LoaderInterface | |
| /** | ||
| * Checks if current loader supports provided resource. | ||
| * | ||
| * @template TSupportedResourceType | ||
| * @param mixed $resource Resource to load | ||
| * | ||
| * @param TSupportedResourceType $resource Resource to load | ||
| * | ||
| * @phpstan-assert-if-true =LoaderInterface<TSupportedResourceType> $this | ||
| * @phpstan-assert-if-true =TResourceType $resource | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As @stof identified, calling However we can safely refine |
||
| * | ||
| * @return bool | ||
| */ | ||
|
|
||
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
@varshould probably go near the assignment of the value (on line 24) instead.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.
Unfortunately it can't go higher up because if it's before the
assert(array_filter(...))then phpstan will complain that the assertions are redundant https://phpstan.org/r/5e86b039-21e8-4bb9-82a1-4877aef0c1c2Unless we only tag it, and don't assert at runtime at all, but that feels a bit like cheating