I am currently upgrading a project to use phpstan to better catch type errors, @template
and class-string
have been particularly helpfull
However, I have a method on the projects router, that takes two string parameters for a controller action.
Those parameters map to a controller class name, and method, eg:
/**
* @param class-string<Controller> $controllerName
* @param string $methodName
* @return Route
*/
public function toController(string $controllerName, string $methodName) : Route
I can tell phpstan that the first parameter $controllerName
must be a class name, and a subtype of Controller
.
However the $methodName
param is currently just an untyped string.
I would like to be able to say it must be a public method on the class $className
, but cannot find anything in the docs, or google searching.
I did find key-of<Type::ARRAY_CONST>
which seems close, but works on const arrays.
Does anything exist to handle this at present?