From 48b6ea47b4a4c3326f6aced81479e9a5a9af1d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Letord?= Date: Wed, 3 Apr 2024 18:13:56 +0200 Subject: [PATCH] Small fixes from review --- .../Compiler/ServiceProxyPass.php | 4 +++- .../AccessInterceptorGenerator.php | 12 ++++-------- .../Cache/ClassWithInvalidateCacheAttributes.php | 2 -- tests/Double/Stub/FinalClass.php | 3 +++ 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/FrameworkBridge/Symfony/DependencyInjection/Compiler/ServiceProxyPass.php b/src/FrameworkBridge/Symfony/DependencyInjection/Compiler/ServiceProxyPass.php index b45a97d..7abbf3e 100644 --- a/src/FrameworkBridge/Symfony/DependencyInjection/Compiler/ServiceProxyPass.php +++ b/src/FrameworkBridge/Symfony/DependencyInjection/Compiler/ServiceProxyPass.php @@ -44,7 +44,9 @@ private function overrideServiceDefinition(string $taggedServiceName): void if ($definition->getFactory() !== null) { $this->compiler->log($this, "Service {$taggedServiceName} is not compatible with service proxy"); - return; + throw new \RuntimeException( + "Unable to override {$taggedServiceName}, remove the factory definition or the Interceptable interface." + ); } $definition->setFactory([new Reference(ProxyFactory::class), 'createInstance']); diff --git a/src/Generator/AccessInterceptorGenerator/AccessInterceptorGenerator.php b/src/Generator/AccessInterceptorGenerator/AccessInterceptorGenerator.php index 5e5da37..c163335 100644 --- a/src/Generator/AccessInterceptorGenerator/AccessInterceptorGenerator.php +++ b/src/Generator/AccessInterceptorGenerator/AccessInterceptorGenerator.php @@ -18,10 +18,6 @@ use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion; use ProxyManager\ProxyGenerator\ProxyGeneratorInterface; -use InvalidArgumentException; -use ReflectionClass; -use ReflectionMethod; - class AccessInterceptorGenerator implements ProxyGeneratorInterface { /** @@ -29,13 +25,13 @@ class AccessInterceptorGenerator implements ProxyGeneratorInterface * * @param array{'methods'?: array} $proxyOptions * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidProxiedClassException */ - public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator, array $proxyOptions = []) + public function generate(\ReflectionClass $originalClass, ClassGenerator $classGenerator, array $proxyOptions = []) { if (!\array_key_exists('methods', $proxyOptions)) { - throw new InvalidArgumentException(sprintf('Missing methods options for %s.', __CLASS__)); + throw new \InvalidArgumentException(sprintf('Missing methods options for %s.', __CLASS__)); } CanProxyAssertion::assertClassCanBeProxied($originalClass, false); @@ -69,7 +65,7 @@ private function buildMethodInterceptor( MethodPrefixInterceptors $prefixInterceptors, MethodSuffixInterceptors $suffixInterceptors ): callable { - return static function (ReflectionMethod $method) use ( + return static function (\ReflectionMethod $method) use ( $prefixInterceptors, $suffixInterceptors ): InterceptedMethod { diff --git a/tests/Double/Stub/Cache/ClassWithInvalidateCacheAttributes.php b/tests/Double/Stub/Cache/ClassWithInvalidateCacheAttributes.php index b3ff466..66017f7 100644 --- a/tests/Double/Stub/Cache/ClassWithInvalidateCacheAttributes.php +++ b/tests/Double/Stub/Cache/ClassWithInvalidateCacheAttributes.php @@ -11,8 +11,6 @@ class ClassWithInvalidateCacheAttributes { public const DATA = 'data'; - private $data; - #[Cache(tags: ['"my_tag"'])] public function methodWithTaggedCache(): string { diff --git a/tests/Double/Stub/FinalClass.php b/tests/Double/Stub/FinalClass.php index afaa3dc..ba55962 100644 --- a/tests/Double/Stub/FinalClass.php +++ b/tests/Double/Stub/FinalClass.php @@ -4,8 +4,11 @@ namespace OpenClassrooms\ServiceProxy\Tests\Double\Stub; +use OpenClassrooms\ServiceProxy\Attribute\Cache; + final class FinalClass { + #[Cache] public function aMethod(): void { }