-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
IDE support for Filesystem\Asset
proxied methods
#6598
Comments
Filesystem\Asset
proxied methods
@gaufde Does your IDE pick it up when you add the The whole setup is a bit of a mess but also not easy to refactor, so we probably cannot make it ideal. E.g. I have no idea how to tell the IDE when File and when Image is used. Does it accept multiple mixins? Guess we have either the choice that the IDE doesn't know about certain methods on images or that the IDE thinks some methods are available on all files that are only available for images. |
Yeah, my IDE seems to pick it up equally well regardless of whether I add
Yeah, using two mixins for
I'm just learning about how some of this stuff works, but my guess is that the IDE won't be able to intuit what type of file will be returned based on the string passed to either the What I think would be intuitive to me would be something like if It looks to me like the purpose of |
Description
Code like
asset('logo.svg')->read()
is flagged in PhpStorm because "Method 'read' not found in Kirby\Filesystem\Asset".Expected behavior
No warning to appear for valid code.
Screenshots
None
To reproduce
asset('logo.svg')->read()
into a templateYour setup
Kirby Version
4.3.0 and 5.0.0-alpha.1
Your system (please complete the following information)
After talking to Lukas Kleinschmidt about whether his typing plugin could handle this, it seems like it would be best if Kirby core could add some
@mixin
annotations directly to fix this issue. See: lukaskleinschmidt/kirby-types#4 (comment)Lukas mentioned I could try to submit a PR for this, but the relevant source code wasn't entirely clear to me. It seems like the
Kirby\Filesystem\IsFile
trait can return either aKirby\Filesystem\File
orKirby\Image\Image
object, which I would assume means that the mixin methods will not always be the same when::asset()
fromKirby\Filesystem\IsFile
is called.It looks like
Kirby\Image\Image
is a child ofKirby\Filesystem\File
so it is probably safe to add@mixin File
forKirby\Filesystem\Asset
. However, I don't know what would be needed to account for methods ofKirby\Image\Image
. I'm not sure if@mixin
annotations alone can do that, or if larger changes would be needed for static analysis tools to be able to understand what types of objects are used insideKirby\Filesystem\Asset
.The text was updated successfully, but these errors were encountered: