Help getting started with scalar_objects plugin #5706
Unanswered
still-dreaming-1
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using the php extension scalar_objects to add something like "extension methods" to strings. That part is working. I am trying to make a plugin that will help Psalm understand these "methods", but I'm not sure if it is possible or where to begin. Any tips? So far I have cloned the skeleton plugin project, and that's it.
My real goal is actually more ambitious and complicated than that, but that would be a good starting point to see if it even might be possible. What I actually want to do is only have the "extension methods" be considered by Psalm to be valid if the argument type matches what it is being called on, even if I used a psalm specific type. What I mean is, if the first parameter is explicitly typed as a
non-empty-string
, I don't want Psalm to consider that to be a callable method on a regular string.If it is not currently possible to make a plugin for this in Psalm, I would like to either extend the Psalm plugin system to make it possible, or else extend Psalm to have built in support for the scalar_objects extension. Please let me know what you think.
Here is what one of these extension methods might look like, how you could register it with the scalar_types extension, and how you could call the "method".
https://psalm.dev/r/0a4f4633a7
My first steps into getting this to work is to see if I can get any plugin to work for anything. So far no luck with that. I have a class called Classic. I tried adding a hook to the plugin that would help it to say the method ->doIt() exists in it even though it does not. Psalm is showing an error when I try to call it saying the method does not exist. Here is the code of the hook
I tried adding an echo inside ->doesMethodExist(). It doesn't seem to be running. I compared my plugin code to other plugins and apparently the hooks have to be hooked in from my Plugin entry point class. I added that code, but it's still not working. I tried adding an echo to the __invoke method of the entry point class and it seems that may not be running. I also tried completely rewriting this to be a file based plugin, and changed the echoes to just log to a file. It would have logged if the plugin invoked at all or checked if a method existed. Psalm still thinks the method does not exist and nothing is logged.
Unless I can get some help I'm now at a complete loss of ideas to try for a plugin approach, so the only thing I try now is adding support for this PHP extension directly into Psalm.
Beta Was this translation helpful? Give feedback.
All reactions