Skip to content

Commit

Permalink
Small fixes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
kletord committed Apr 15, 2024
1 parent 10b9cc3 commit 48b6ea4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,20 @@
use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion;
use ProxyManager\ProxyGenerator\ProxyGeneratorInterface;

use InvalidArgumentException;
use ReflectionClass;
use ReflectionMethod;

class AccessInterceptorGenerator implements ProxyGeneratorInterface
{
/**
* {@inheritDoc}
*
* @param array{'methods'?: array<string>} $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);
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class ClassWithInvalidateCacheAttributes
{
public const DATA = 'data';

private $data;

#[Cache(tags: ['"my_tag"'])]
public function methodWithTaggedCache(): string
{
Expand Down
3 changes: 3 additions & 0 deletions tests/Double/Stub/FinalClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

namespace OpenClassrooms\ServiceProxy\Tests\Double\Stub;

use OpenClassrooms\ServiceProxy\Attribute\Cache;

final class FinalClass
{
#[Cache]
public function aMethod(): void
{
}
Expand Down

0 comments on commit 48b6ea4

Please sign in to comment.