Is there an Annotation for a method call?

Hi there,

is there a way to annotate a string construct (like PHPUnit Mocks) with some hint about the "real method call" which is used by find usages (e.g. when renaming a method)? 

Something like this:

/** @methodCall MyClass::myMethod() */
$mock->method('myMethod')->willReturn('foo');

(Yes, the test will fail when renaming the method, but think about this as a "easy to imagine" placeholder for "classes/methods as strings".)

Thank you in advance.

0

There's no way to do that via PHPDoc, but advanced metadata can be used for that: https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata

And here's a feature request: https://youtrack.jetbrains.com/issue/WI-31270

0

Hi Eugene,

thank you for your answer. I've looked into the metadata - it looks like it's a WIP feature, right? ("mixed $argNum ignored, for now its always 0")

Maybe it's just the examples, but I can't see how I can configure the method call for this. In a concrete requirement for a (legacy) project: we have tons of static method calls, which makes it superhard to mock/test.

So we created a trait to be able to mock static methods. I pretty much just takes the class name and the method name as strings, combines and calls them with call_user_func_array and adds the remaining args (if any). 

class LegacyClass {   
public static function foo($arg1, $arg2) { return 'foo: ' + $arg1 . ' ' . $arg2; }
}

class AnotherClass {
use StaticCallTrait;

public function foo($arg1, $arg2) {
return $this->callStatic(LegacyClass::class, 'foo', $arg1, $arg2);
}
}

So we have the problem that we are now able to mock this calls (better way would be to refactor the static methods, but thats easier said then done) but lose "visibility" and can't use "find usages". I struggle to find a way to configure the metadata to help me with this problem.

0

Yeah, it's WIP currently. 

It would be more efficient to ask questions directly in WI-31270 - you'll be able to receive reply directly from developers.

1

请先登录再写评论。