Skip to content

Commit

Permalink
feat(core): Added Cast::toNullable().
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDragon-ru committed Aug 5, 2024
1 parent 6862a0a commit e65d0ff
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/core/src/Utils/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,17 @@ public static function to(string $class, mixed $value): object {

return $value;
}

/**
* @template T of object
*
* @param class-string<T> $class
*
* @return ?T
*/
public static function toNullable(string $class, mixed $value): ?object {
assert($value === null || $value instanceof $class);

return $value;
}
}

0 comments on commit e65d0ff

Please sign in to comment.