-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Labels
Description
https://phpstan.org/r/3be3170f-9b1b-401a-b57f-cf90907850f4
I think that I get why phpstan reports the issue but I don't think it's correct.
I want to document that the only accepted values of the function are an instance of Bar or a string. At the same time I obviously want to validate that the passed arguments are of the required types (I don't want to rely on a "good user behavior"), but according to phpstan I'm not able to do that.
Am I missing something or is this a bug? Any suggestions on how to go around it? Or do you suggest that such validation is not neccessary and that I should rely on the phpstan to check the arguments somewhere where the function is called?
/**
* @param Bar|string $a
*/
function foo ($a) : bool {
if ($a instanceof Bar) {
return true;
} elseif (!is_string($a)) {
throw new \Exception('Not Bar or string');
}
return false;
}
foo(123); // I expect an exception here...Reactions are currently unavailable