Is it possible that you hint the returned type of a PHP function/method, determined by one if it's arguments? Something like this:
/**
* @param string $class
* @param array $attributes
* @return $class <- this doesn't work
*/
public function create($class, $attributes) {
... // finally returns object of type $class
}
I'm implementing a library that allows to create factory objects for unit tests. So I want to make it possible in the client code to have:
$user = $factory->create('Users', ['name' => 'John', 'email' => '[email protected]']);
And have autocompletion of object methods/attributes without having to add explicit PHPDoc comments in the client code like this:
/* @var $user Users */
$user = $factory->create('Users', ['name' => 'John', 'email' => '[email protected]']);
Any suggestions are most welcome! As long as I get it working in popular IDEs (PHPStorm, Eclipse, NetBeans), it's a valid solution.
Try DynamicReturnTypePlugin. then you can add this configuration manually
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With