diff --git a/src/Exception/NonPublicConstructorException.php b/src/Exception/NonPublicConstructorException.php index f8366b1..b2a4407 100644 --- a/src/Exception/NonPublicConstructorException.php +++ b/src/Exception/NonPublicConstructorException.php @@ -4,23 +4,23 @@ namespace Yiisoft\Hydrator\Exception; +use LogicException; use ReflectionMethod; final class NonPublicConstructorException extends NonInstantiableException { public function __construct(ReflectionMethod $constructor) { - $type = $this->getConstructorType($constructor); parent::__construct( sprintf( - '%s is not instantiable because contain non-public%s constructor.', + '%s is not instantiable because contain non-public (%s) constructor.', $constructor->getDeclaringClass()->getName(), - $type !== null ? ' (' . $type . ')' : '', + $this->getConstructorType($constructor), ), ); } - private function getConstructorType(ReflectionMethod $constructor): ?string + private function getConstructorType(ReflectionMethod $constructor): string { if ($constructor->isPrivate()) { return 'private'; @@ -30,6 +30,8 @@ private function getConstructorType(ReflectionMethod $constructor): ?string return 'protected'; } - return null; + throw new LogicException( + 'Exception "NonPublicConstructorException" can be used only for non-public constructors.' + ); } } diff --git a/src/Exception/WrongConstructorArgumentsCountException.php b/src/Exception/WrongConstructorArgumentsCountException.php index 0bfec22..4774fc8 100644 --- a/src/Exception/WrongConstructorArgumentsCountException.php +++ b/src/Exception/WrongConstructorArgumentsCountException.php @@ -4,9 +4,11 @@ namespace Yiisoft\Hydrator\Exception; +use ReflectionMethod; + final class WrongConstructorArgumentsCountException extends NonInstantiableException { - public function __construct(\ReflectionMethod $constructor, int $countArguments) + public function __construct(ReflectionMethod $constructor, int $countArguments) { parent::__construct( sprintf( diff --git a/src/Temp/RouteArgument.php b/src/Temp/RouteArgument.php index cc9a700..be9fcd9 100644 --- a/src/Temp/RouteArgument.php +++ b/src/Temp/RouteArgument.php @@ -7,6 +7,9 @@ use Attribute; use Yiisoft\Hydrator\Attribute\Parameter\ParameterAttributeInterface; +/** + * @codeCoverageIgnore + */ #[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER | Attribute::IS_REPEATABLE)] final class RouteArgument implements ParameterAttributeInterface { diff --git a/src/Temp/RouteArgumentResolver.php b/src/Temp/RouteArgumentResolver.php index 52307b8..798604c 100644 --- a/src/Temp/RouteArgumentResolver.php +++ b/src/Temp/RouteArgumentResolver.php @@ -13,6 +13,9 @@ use function array_key_exists; +/** + * @codeCoverageIgnore + */ final class RouteArgumentResolver implements ParameterAttributeResolverInterface { public function __construct( diff --git a/tests/Exception/NonPublicConstructorExceptionTest.php b/tests/Exception/NonPublicConstructorExceptionTest.php new file mode 100644 index 0000000..67e82fd --- /dev/null +++ b/tests/Exception/NonPublicConstructorExceptionTest.php @@ -0,0 +1,30 @@ +getConstructor(); + + $this->expectException(LogicException::class); + $this->expectExceptionMessage( + 'Exception "NonPublicConstructorException" can be used only for non-public constructors.' + ); + new NonPublicConstructorException($reflection); + } +} diff --git a/tests/TypeCaster/TypeCastContextTest.php b/tests/TypeCaster/TypeCastContextTest.php new file mode 100644 index 0000000..d4056af --- /dev/null +++ b/tests/TypeCaster/TypeCastContextTest.php @@ -0,0 +1,26 @@ + null))->getParameters()[0]; + + $context = new TypeCastContext($hydrator, $reflection); + + $this->assertSame($reflection, $context->getReflection()); + $this->assertInstanceOf(ReflectionNamedType::class, $context->getReflectionType()); + $this->assertSame($hydrator, $context->getHydrator()); + } +}