I need to build a trait (or class for that matter) on which I can template multiple types; I've tried something like the following (also descriptive of the problem; the car context is just for illustrating the problem, I know a car is supposed to be aggregated not composed but this is not the issue to discuss):
/**
* @template TyreType of Tyre
* @template EngineType of Engine
*/
trait Car {
/**
* @return TyreType
*/
public function getTyre(): Tyre {
}
/**
* @return EngineType
*/
public function getEngine(): Engine{
}
}
trait SomeCar {
/**
* @use Car<AirlessTyre><DieselEngine>
*/
use Car;
public function test() {
$this->getEngine()->dieselSpecificMethod();
}
}
class Engine{}
class Tyre{}
class DieselEngine extends Engine {
public function dieselSpecificMethod() {}
}
class AirlessTyre extends Tyre {}
The problem is, in PhpStorm I get "Potentially polymorphic call. Engine does not have members in its hierarchy" on dieselSpecificMethod()
.
So my questions are:
- Does psalm support multiple-type templating as I'm trying to achieve
- Am I missing the correct semantics in the example above; how should I annotate this?
- Or is it just a PhpStorm limitation