vscode-intelephense
vscode-intelephense copied to clipboard
Allow method overloading at method level.
Currently overloading methods via @method
docblock appears to only be supported if done in the class's docblock.
/**
* @method void test()
* @method void test(string $name)
*/
class Foo
{
public function test(?string $name) : void
{
}
}
It would be good if the overloading could also be declared at method level:
class Foo
{
/**
* @method void test()
* @method void test(string $name)
*/
public function test(?string $name) : void
{
}
}
@method
applies to Class only since it refers to its methods, why would you need this? 🤔 If you need to customize the method itself, you can just override its PHPDoc
@danilopolani, I think the only reason @method
works at class level is because it's meant to describe magic method (that aren't actually there, so you can't declare it in the method's docblock).
If you allow for method overloading, then there's no reason to declare the overloads anywhere else than where the main method is declared.
If you allow for method overloading, then there's no reason to declare the overloads anywhere else than where the main method is declared.
But why can't you just do something like this? Maybe I'm misunderstanding your needs, sorry!
/**
* @param string $name
* @return void
*/
public function test(?string $name) : void
{
}
Ah, the example was oversimplified I think. I'm talking about having multiple signatures like this:
/**
* @param string|mixed $key_or_value
* @param ?mixed $value
* @return void
* @method void test(string $key, mixed $value)
* @method void test(mixed $value)
*/
public function test($key_or_value, $value)
{
}
Or for return type overloading:
/**
* @param Something|Other $value
* @return Something[]|Other[]
* @method Something[] test(Something $value)
* @method Other[] test(Other $value)
*/
public function test($value)
{
}
Oh got it! I have the suspect that the @method
syntax on methods is not anyway accepted by static analysis tools such as PHPStan and Psalm, though.
Maybe it could be written with Generics/Union types, depending on the scenario? Just trying to figure out a solution that already works 😄 Hopefully a maintainer will answer in the near future
Psalm doesn't support method overloading at the moment. Instead it relies on conditional return types, which gets you half way there. Full support seems to be on the roadmap tho.
Don't know about the other static analyzers.
There's no plans to support @method
annotations anywhere other than from within the class docblock.