Skip to content

Commit

Permalink
Replace RuntimeException with assert check in CompileVisitor
Browse files Browse the repository at this point in the history
Replaced is_object check with an assert to test validity of instance type in CompileVisitor.php. Removed the usage of RuntimeException. Function "gettype" has been introduced for instance type identification. This refactoring lends to a cleaner code structure and exception handling.
  • Loading branch information
koriym committed May 23, 2024
1 parent 9039b61 commit 5027b5b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/CompileVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
use Ray\Di\SetterMethods;
use Ray\Di\VisitorInterface;
use ReflectionParameter;
use RuntimeException;

use function assert;
use function gettype;
use function is_array;
use function is_object;
use function is_scalar;
Expand Down Expand Up @@ -70,11 +70,9 @@ public function visitInstance($value): string
return 'return null;';
}

if (is_object($value)) {
return sprintf('return unserialize(\'%s\');', serialize($value));
}
assert(! is_object($value), 'Invalid instance type:' . gettype($value));

throw new RuntimeException('Invalid instance value');
return sprintf('return unserialize(\'%s\');', serialize($value));
}

/** @inheritDoc */
Expand Down

0 comments on commit 5027b5b

Please sign in to comment.