/**
* Checks if parameter is typehinted to accept \Joomla\Event\EventInterface.
*
* @param \ReflectionParameter $parameter
*
* @return boolean
*
* @since 4.0.0
*/
private function parameterImplementsEventInterface(\ReflectionParameter $parameter) : bool
{
$reflectionType = $parameter->getType();
// Parameter is not typehinted.
if ($reflectionType === null) {
return false;
}
// Parameter is nullable.
if ($reflectionType->allowsNull()) {
return false;
}
// Handle standard typehints.
if ($reflectionType instanceof \ReflectionNamedType) {
return \is_a($reflectionType->getName(), EventInterface::class, true);
}
// Handle PHP 8 union types.
if ($reflectionType instanceof \ReflectionUnionType) {
foreach ($reflectionType->getTypes() as $type) {
if (!\is_a($type->getName(), EventInterface::class, true)) {
return false;
}
}
return true;
}
return false;
}