invalidReturnTypeHint() public static method

public static invalidReturnTypeHint ( $className, $methodName, Exception $previous = null ) : self
$className
$methodName
$previous Exception
return self
Beispiel #1
0
 /**
  * @param \ReflectionType $type
  * @param \ReflectionMethod $method
  * @param \ReflectionParameter|null $parameter
  *
  * @return string
  */
 private function formatType(\ReflectionType $type, \ReflectionMethod $method, \ReflectionParameter $parameter = null)
 {
     $name = method_exists($type, 'getName') ? $type->getName() : (string) $type;
     $nameLower = strtolower($name);
     if ('self' === $nameLower) {
         $name = $method->getDeclaringClass()->getName();
     }
     if ('parent' === $nameLower) {
         $name = $method->getDeclaringClass()->getParentClass()->getName();
     }
     if (!$type->isBuiltin() && !class_exists($name) && !interface_exists($name)) {
         if (null !== $parameter) {
             throw UnexpectedValueException::invalidParameterTypeHint($method->getDeclaringClass()->getName(), $method->getName(), $parameter->getName());
         }
         throw UnexpectedValueException::invalidReturnTypeHint($method->getDeclaringClass()->getName(), $method->getName());
     }
     if (!$type->isBuiltin()) {
         $name = '\\' . $name;
     }
     if ($type->allowsNull() && (null === $parameter || !$parameter->isOptional() || null !== $parameter->getDefaultValue())) {
         $name = '?' . $name;
     }
     return $name;
 }