Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Adjust source code to remove dependency on Annotation classes
Browse files Browse the repository at this point in the history
  • Loading branch information
lisachenko committed Apr 10, 2018
1 parent 6b1059d commit 0664577
Show file tree
Hide file tree
Showing 17 changed files with 12 additions and 357 deletions.
35 changes: 0 additions & 35 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
namespace Zend\Code\Reflection;

use ReflectionClass;
use Zend\Code\Annotation\AnnotationCollection;
use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\Scanner\AnnotationScanner;
use Zend\Code\Scanner\FileScanner;

use function array_shift;
Expand All @@ -25,10 +22,6 @@

class ClassReflection extends ReflectionClass implements ReflectionInterface
{
/**
* @var AnnotationScanner
*/
protected $annotations;

/**
* @var DocBlockReflection
Expand Down Expand Up @@ -68,34 +61,6 @@ public function getDocBlock()
return $this->docBlock;
}

/**
* @param AnnotationManager $annotationManager
* @return AnnotationCollection
*/
public function getAnnotations(AnnotationManager $annotationManager)
{
$docComment = $this->getDocComment();

if ($docComment == '') {
return false;
}

if ($this->annotations) {
return $this->annotations;
}

$fileScanner = $this->createFileScanner($this->getFileName());
$nameInformation = $fileScanner->getClassNameInformation($this->getName());

if (! $nameInformation) {
return false;
}

$this->annotations = new AnnotationScanner($annotationManager, $docComment, $nameInformation);

return $this->annotations;
}

/**
* Return the start line of the class
*
Expand Down
33 changes: 0 additions & 33 deletions src/Reflection/MethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
namespace Zend\Code\Reflection;

use ReflectionMethod as PhpReflectionMethod;
use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\Scanner\AnnotationScanner;
use Zend\Code\Scanner\CachingFileScanner;

use function array_shift;
Expand Down Expand Up @@ -41,11 +39,6 @@ class MethodReflection extends PhpReflectionMethod implements ReflectionInterfac
*/
const PROTOTYPE_AS_STRING = 'prototype_as_string';

/**
* @var AnnotationScanner
*/
protected $annotations;

/**
* Retrieve method DocBlock reflection
*
Expand All @@ -62,32 +55,6 @@ public function getDocBlock()
return $instance;
}

/**
* @param AnnotationManager $annotationManager
* @return AnnotationScanner
*/
public function getAnnotations(AnnotationManager $annotationManager)
{
if (($docComment = $this->getDocComment()) == '') {
return false;
}

if ($this->annotations) {
return $this->annotations;
}

$cachingFileScanner = $this->createFileScanner($this->getFileName());
$nameInformation = $cachingFileScanner->getClassNameInformation($this->getDeclaringClass()->getName());

if (! $nameInformation) {
return false;
}

$this->annotations = new AnnotationScanner($annotationManager, $docComment, $nameInformation);

return $this->annotations;
}

/**
* Get start line (position) of method
*
Expand Down
34 changes: 0 additions & 34 deletions src/Reflection/PropertyReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@
namespace Zend\Code\Reflection;

use ReflectionProperty as PhpReflectionProperty;
use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\Scanner\AnnotationScanner;
use Zend\Code\Scanner\CachingFileScanner;

/**
* @todo implement line numbers
*/
class PropertyReflection extends PhpReflectionProperty implements ReflectionInterface
{
/**
* @var AnnotationScanner
*/
protected $annotations;

/**
* Get declaring class reflection object
*
Expand Down Expand Up @@ -62,33 +55,6 @@ public function getDocBlock()
return $docBlockReflection;
}

/**
* @param AnnotationManager $annotationManager
* @return AnnotationScanner
*/
public function getAnnotations(AnnotationManager $annotationManager)
{
if (null !== $this->annotations) {
return $this->annotations;
}

if (($docComment = $this->getDocComment()) == '') {
return false;
}

$class = $this->getDeclaringClass();
$cachingFileScanner = $this->createFileScanner($class->getFileName());
$nameInformation = $cachingFileScanner->getClassNameInformation($class->getName());

if (! $nameInformation) {
return false;
}

$this->annotations = new AnnotationScanner($annotationManager, $docComment, $nameInformation);

return $this->annotations;
}

/**
* @return string
*/
Expand Down
18 changes: 3 additions & 15 deletions src/Scanner/CachingFileScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Zend\Code\Scanner;

use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\Exception;
use Zend\Code\NameInformation;

Expand All @@ -33,10 +32,9 @@ class CachingFileScanner extends FileScanner

/**
* @param string $file
* @param AnnotationManager $annotationManager
* @throws Exception\InvalidArgumentException
*/
public function __construct($file, AnnotationManager $annotationManager = null)
public function __construct($file)
{
if (! file_exists($file)) {
throw new Exception\InvalidArgumentException(sprintf(
Expand All @@ -47,14 +45,12 @@ public function __construct($file, AnnotationManager $annotationManager = null)

$file = realpath($file);

$cacheId = md5($file) . '/' . (isset($annotationManager)
? spl_object_hash($annotationManager)
: 'no-annotation');
$cacheId = md5($file);

if (isset(static::$cache[$cacheId])) {
$this->fileScanner = static::$cache[$cacheId];
} else {
$this->fileScanner = new FileScanner($file, $annotationManager);
$this->fileScanner = new FileScanner($file);
static::$cache[$cacheId] = $this->fileScanner;
}
}
Expand All @@ -67,14 +63,6 @@ public static function clearCache()
static::$cache = [];
}

/**
* @return AnnotationManager
*/
public function getAnnotationManager()
{
return $this->fileScanner->getAnnotationManager();
}

/**
* @return array|null|string
*/
Expand Down
16 changes: 0 additions & 16 deletions src/Scanner/ClassScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Zend\Code\Scanner;

use ReflectionClass;
use Zend\Code\Annotation;
use Zend\Code\Exception;
use Zend\Code\NameInformation;

Expand Down Expand Up @@ -140,21 +139,6 @@ public function __construct(array $classTokens, NameInformation $nameInformation
$this->nameInformation = $nameInformation;
}

/**
* Get annotations
*
* @param Annotation\AnnotationManager $annotationManager
* @return Annotation\AnnotationCollection
*/
public function getAnnotations(Annotation\AnnotationManager $annotationManager)
{
if (($docComment = $this->getDocComment()) == '') {
return false;
}

return new AnnotationScanner($annotationManager, $docComment, $this->nameInformation);
}

/**
* Return documentation comment
*
Expand Down
14 changes: 0 additions & 14 deletions src/Scanner/ConstantScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Zend\Code\Scanner;

use Zend\Code\Annotation;
use Zend\Code\Exception;
use Zend\Code\NameInformation;

Expand Down Expand Up @@ -131,19 +130,6 @@ public function getDocComment()
return $this->docComment;
}

/**
* @param Annotation\AnnotationManager $annotationManager
* @return AnnotationScanner
*/
public function getAnnotations(Annotation\AnnotationManager $annotationManager)
{
if (($docComment = $this->getDocComment()) == '') {
return false;
}

return new AnnotationScanner($annotationManager, $docComment, $this->nameInformation);
}

/**
* @return string
*/
Expand Down
21 changes: 0 additions & 21 deletions src/Scanner/DocBlockScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Zend\Code\Scanner;

use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\NameInformation;

use function array_pop;
Expand Down Expand Up @@ -42,11 +41,6 @@ class DocBlockScanner implements ScannerInterface
*/
protected $nameInformation;

/**
* @var AnnotationManager
*/
protected $annotationManager;

/**
* @var string
*/
Expand All @@ -62,11 +56,6 @@ class DocBlockScanner implements ScannerInterface
*/
protected $tags = [];

/**
* @var array
*/
protected $annotations = [];

/**
* @param string $docComment
* @param null|NameInformation $nameInformation
Expand Down Expand Up @@ -107,16 +96,6 @@ public function getTags()
return $this->tags;
}

/**
* @return array
*/
public function getAnnotations()
{
$this->scan();

return $this->annotations;
}

/**
* @return void
*/
Expand Down
6 changes: 2 additions & 4 deletions src/Scanner/FileScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Zend\Code\Scanner;

use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\Exception;

use function file_exists;
Expand All @@ -26,10 +25,9 @@ class FileScanner extends TokenArrayScanner implements ScannerInterface

/**
* @param string $file
* @param null|AnnotationManager $annotationManager
* @throws Exception\InvalidArgumentException
*/
public function __construct($file, AnnotationManager $annotationManager = null)
public function __construct($file)
{
$this->file = $file;
if (! file_exists($file)) {
Expand All @@ -38,7 +36,7 @@ public function __construct($file, AnnotationManager $annotationManager = null)
$file
));
}
parent::__construct(token_get_all(file_get_contents($file)), $annotationManager);
parent::__construct(token_get_all(file_get_contents($file)));
}

/**
Expand Down
14 changes: 0 additions & 14 deletions src/Scanner/MethodScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Zend\Code\Scanner;

use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\Exception;
use Zend\Code\NameInformation;

Expand Down Expand Up @@ -187,19 +186,6 @@ public function getDocComment()
return $this->docComment;
}

/**
* @param AnnotationManager $annotationManager
* @return AnnotationScanner
*/
public function getAnnotations(AnnotationManager $annotationManager)
{
if (($docComment = $this->getDocComment()) == '') {
return false;
}

return new AnnotationScanner($annotationManager, $docComment, $this->nameInformation);
}

/**
* @return bool
*/
Expand Down
Loading

0 comments on commit 0664577

Please sign in to comment.