Skip to content

Commit

Permalink
use interface for AnnotationReader
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Oct 30, 2019
1 parent aa98acb commit cfb0262
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions packages/BetterPhpDocParser/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ services:

PHPStan\PhpDocParser\Parser\PhpDocParser:
alias: 'Rector\BetterPhpDocParser\PhpDocParser\BetterPhpDocParser'

Doctrine\Common\Annotations\Reader:
alias: 'Doctrine\Common\Annotations\AnnotationReader'
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\Reader;

final class AnnotationReaderFactory
{
public function create(): AnnotationReader
public function create(): Reader
{
AnnotationRegistry::registerLoader('class_exists');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\BetterPhpDocParser\AnnotationReader;

use Doctrine\Common\Annotations\AnnotationException;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\Reader;
use Doctrine\ORM\Mapping\Annotation;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
Expand All @@ -22,18 +22,18 @@
final class NodeAnnotationReader
{
/**
* @var AnnotationReader
* @var Reader
*/
private $annotationReader;
private $reader;

/**
* @var NameResolver
*/
private $nameResolver;

public function __construct(AnnotationReader $annotationReader, NameResolver $nameResolver)
public function __construct(Reader $reader, NameResolver $nameResolver)
{
$this->annotationReader = $annotationReader;
$this->reader = $reader;
$this->nameResolver = $nameResolver;
}

Expand All @@ -51,7 +51,7 @@ public function readMethodAnnotation(ClassMethod $classMethod, string $annotatio
$reflectionMethod = new ReflectionMethod($className, $methodName);

try {
return $this->annotationReader->getMethodAnnotation($reflectionMethod, $annotationClassName);
return $this->reader->getMethodAnnotation($reflectionMethod, $annotationClassName);
} catch (AnnotationException $annotationException) {
// unable to laod
return null;
Expand All @@ -65,7 +65,7 @@ public function readClassAnnotation(Class_ $class, string $annotationClassName)
{
$classReflection = $this->createClassReflectionFromNode($class);

return $this->annotationReader->getClassAnnotation($classReflection, $annotationClassName);
return $this->reader->getClassAnnotation($classReflection, $annotationClassName);
}

/**
Expand All @@ -79,7 +79,7 @@ public function readPropertyAnnotation(Property $property, string $annotationCla
}

/** @var Annotation|null $propertyAnnotation */
$propertyAnnotation = $this->annotationReader->getPropertyAnnotation($propertyReflection, $annotationClassName);
$propertyAnnotation = $this->reader->getPropertyAnnotation($propertyReflection, $annotationClassName);
if ($propertyAnnotation === null) {
return null;
}
Expand Down

0 comments on commit cfb0262

Please sign in to comment.