How to add autocomple to a method with array arguments. Follow
Hi, i want to add autocomplete to a library, which would be the best way to implement it.
array $b(['option1' => string, 'option2' => int)]);
public function a(array $b = [], array $c = [])
I would like to be able that when the user uses it:
$class = new class();
$class->a(['suggestion from phpstorm option1 or option2
Thks,
Please sign in to leave a comment.
You might be able to achieve this using metadata, please take a look: https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html#map
If it is correct i can make it work, but not when the argument is an array, i apologize for the trouble, could provide the example that i propose when it is an array,
thks,
Did you solved that?
I search the same code problem solved.
unfortunately i have not been able to find any solution.
can u share it :D?
Apparently it seems that this issue has no solution :(
Sorry, if you could provide a code example of what you have and you're trying to achieve - I would be able to look into it & advise.
Using PHP 8 attributes:
https://github.com/JetBrains/phpstorm-attributes#arrayshape
Andriy Bazanov THANK YOU :D
Andriy Bazanov Indeed ArrayShape works but only within the same class, and the idea is to use it as a help for an API, if you use it outside the class it will not work unfortunately,
Thks.
@Terabytefrelance
What do you mean by "the same class"? An example will help clarifying the things/your requirements.
Andriy Bazanov
I notice the same thing, autcomplete for ArrayShape (at least for function arguments) only works for me when calling the annotated method from the same class/file. If I instantiate the class in another class, in another file, autocomplete does not work.
@T
Looks like https://youtrack.jetbrains.com/issue/WI-66616 to me (a ticket that was extracted from this comment in WI-56021 ). Consider voting for it so it may get fixed for next 2022.2 version.