Skip to content

Commit

Permalink
fix: remove previous exception from UnresolvableType
Browse files Browse the repository at this point in the history
Following up eaa1283, fixes an issue where cache mechanism could break
when relying on serialization.
  • Loading branch information
romm committed Jul 7, 2023
1 parent eaa1283 commit 5c89c66
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
4 changes: 1 addition & 3 deletions src/Mapper/Object/Exception/InvalidConstructorReturnType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ public function __construct(FunctionDefinition $function)

if ($returnType instanceof UnresolvableType) {
$message = $returnType->message();
$previous = $returnType->previous();
} else {
$message = "Invalid return type `{$returnType->toString()}` for constructor `{$function->signature()}`, it must be a valid class name.";
$previous = null;
}

parent::__construct($message, 1659446121, $previous);
parent::__construct($message, 1659446121);
}
}
19 changes: 4 additions & 15 deletions src/Type/Types/UnresolvableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,36 @@
use CuyZ\Valinor\Type\Type;
use CuyZ\Valinor\Utility\ValueDumper;
use LogicException;
use Throwable;

/** @internal */
final class UnresolvableType implements Type
{
public function __construct(
private string $rawType,
private string $message,
private ?Throwable $previous = null
) {}

public static function forProperty(string $raw, string $signature, InvalidType $exception): self
{
return new self(
$raw,
"The type `$raw` for property `$signature` could not be resolved: {$exception->getMessage()}",
$exception
"The type `$raw` for property `$signature` could not be resolved: {$exception->getMessage()}"
);
}

public static function forParameter(string $raw, string $signature, InvalidType $exception): self
{
return new self(
$raw,
"The type `$raw` for parameter `$signature` could not be resolved: {$exception->getMessage()}",
$exception
"The type `$raw` for parameter `$signature` could not be resolved: {$exception->getMessage()}"
);
}

public static function forMethodReturnType(string $raw, string $signature, InvalidType $exception): self
{
return new self(
$raw,
"The type `$raw` for return type of method `$signature` could not be resolved: {$exception->getMessage()}",
$exception
"The type `$raw` for return type of method `$signature` could not be resolved: {$exception->getMessage()}"
);
}

Expand Down Expand Up @@ -71,8 +66,7 @@ public static function forLocalAlias(string $raw, string $name, ClassType $type,
{
return new self(
$raw,
"The type `$raw` for local alias `$name` of the class `{$type->className()}` could not be resolved: {$exception->getMessage()}",
$exception
"The type `$raw` for local alias `$name` of the class `{$type->className()}` could not be resolved: {$exception->getMessage()}"
);
}

Expand All @@ -81,11 +75,6 @@ public function message(): string
return $this->message;
}

public function previous(): ?Throwable
{
return $this->previous;
}

public function accepts(mixed $value): bool
{
throw new LogicException();
Expand Down

0 comments on commit 5c89c66

Please sign in to comment.