Hi, folks!
I’m looking for a way to resolve the state of generic for such constructions as:
<?php
namespace Generic;
/**
* @template Related
*/
class ModelOf
{
/**
* @param class-string<Related> $ref
*/
public function __construct(string $ref)
{
}
/**
* @param Related $ref
* @return self<Related>
*/
public static function from(object $ref)
{
}
/**
* @return Related
*/
function related() {}
}
Now we’re gonna fetch the parameters state:
$of = new ModelOf(\DateTime::class);
$of->related() /// <- DateTime
// or
$of = ModelOf::from(new \DateTime());
$of->related() /// <- DateTime
// or
/**
* @var $of ModelOf<\DateTime>
*/
$of->related() /// <- DateTime
So PHPStorm understands the type of Related
template parameter when it does Completion. But I need to catch this state in my custom completion handler.
I’ve tried to re-use many PhpGenerics*TypeProviders, but, unfortunately, unsuccessful.
Any thoughts how to solve it?