/** * Checks whether the provided type is assignable to this type. * Returns true, if the provided type is equal to this instance, or * if this instance is "mixed", or if this is "object" and type is an object type * or if this is "callable" and type is a class with a method __invoke. * * @param Type $type * @return boolean */ public function isAssignableFrom(Type $type) { if ($type->getName() === $this->name) { return true; } if ($this->name === self::MIXED_NAME) { return true; } if ($this->name === self::OBJECT_NAME) { return $type instanceof ObjectType; } if ($this->name === self::CALLABLE_NAME) { if ($type instanceof ObjectType) { return $type->getReflectionClass()->hasMethod("__invoke"); } } return false; }