-
Notifications
You must be signed in to change notification settings - Fork 10
Closed
Description
Suppose I have the following code
BaseClient.php
abstract class BaseClient
{
abstract protected function getResultClassName(): string;
/**
* @return BaseResult
*
* @throws RuntimeException
*/
public function getResult(): BaseResult
{
$className = $this->getResultClassName();
if (!is_subclass_of($className, BaseResult::class)) {
throw new RuntimeException('Result class must be a subclass of BaseResult.');
}
return new $className();
}
}Client1.php
/**
* @method Result1 getResult()
*/
class Client1 extends BaseClient
{
protected function getResultClassName(): string
{
return Result1::class;
}
}BaseResult.php
abstract class BaseResult
{
}Result1.php
class Result1 extends BaseResult
{
}As you can see I have added @method phpdoc to Client1 class to enable type hinting.
Then, if I do something like
$client = new Client1();
$result = $client->getResult();and run phpstan, I do not get Missing @throws RuntimeException annotation error. Why? Can I fix it somehow?
Of course I could write this
class Client1 extends BaseClient
{
public function getResult(): BaseResult
{
/** @var Result1 $result */
$result = parent::getResult();
return $result;
}
protected function getResultClassName(): string
{
return Result1::class;
}
}but there's too much code I think.
Thank you in advance!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels