Skip to content

Commit

Permalink
Get annotation reader from service location
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym committed Jul 17, 2021
1 parent a55270c commit 5f773a8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 30 deletions.
23 changes: 2 additions & 21 deletions src/Matcher/AnnotatedWithMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,21 @@

namespace Ray\Aop\Matcher;

use Doctrine\Common\Annotations\AnnotationException;
use Doctrine\Common\Annotations\Reader;
use Ray\Aop\AbstractMatcher;
use Ray\ServiceLocator\ServiceLocator;
use ReflectionClass;
use ReflectionMethod;

final class AnnotatedWithMatcher extends AbstractMatcher
{
/** @var Reader */
private $reader;

/**
* @throws AnnotationException
*/
public function __construct()
{
parent::__construct();
$this->reader = ServiceLocator::getReader();
}

/**
* {@inheritdoc}
*/
public function matchesClass(ReflectionClass $class, array $arguments): bool
{
/** @var array<class-string> $arguments */
[$annotation] = $arguments;
$annotation = $this->reader->getClassAnnotation($class, $annotation);
$annotation = ServiceLocator::getReader()->getClassAnnotation($class, $annotation);

return (bool) $annotation;
}
Expand All @@ -44,13 +30,8 @@ public function matchesMethod(ReflectionMethod $method, array $arguments): bool
{
/** @var array<class-string> $arguments */
[$annotation] = $arguments;
$annotation = $this->reader->getMethodAnnotation($method, $annotation);
$annotation = ServiceLocator::getReader()->getMethodAnnotation($method, $annotation);

return (bool) $annotation;
}

public function __wakeup()
{
$this->__construct();
}
}
9 changes: 3 additions & 6 deletions tests/AnnotatedMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@
namespace Ray\Aop;

use PHPUnit\Framework\TestCase;
use ReflectionException;

use function serialize;
use function unserialize;

class AnnotatedMatcherTest extends TestCase
{
/**
* @throws ReflectionException
*/
public function testSerilize(): void
public function testSerialize(): void
{
$this->assertInstanceOf(AnnotatedMatcher::class, unserialize(serialize(new AnnotatedMatcher('startsWith', ['a']))));
$object = new AnnotatedMatcher('startsWith', ['a']);
$this->assertInstanceOf(AnnotatedMatcher::class, unserialize(serialize($object)));
}
}
3 changes: 0 additions & 3 deletions tests/ReflectiveMethodInvocationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ public function testGetNamedArguments(): void
$this->assertSame((array) $args, ['n' => 1]);
}

/**
* @covers ReflectiveMethodInvocation::getNamedArguments
*/
public function testGetNamedArgumentsWithDefaultValue(): void
{
$invocation = new ReflectiveMethodInvocation(new FakeWeavedClass(), 'defaultValue', [1, null], [new FakeInterceptor(), new FakeInterceptor()]);
Expand Down

0 comments on commit 5f773a8

Please sign in to comment.