From 0c45bab49e3031f11add78b3316d825327258d62 Mon Sep 17 00:00:00 2001 From: jlabno Date: Wed, 20 Jul 2022 13:56:53 +0200 Subject: [PATCH] get rid of external dependency --- composer.json | 5 ++--- src/Finder/DirectoryIteratorClassFinder.php | 2 +- src/Scanner/DoctrineAnnotationsScanner.php | 20 +++++++------------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index bc20620..82a94dc 100755 --- a/composer.json +++ b/composer.json @@ -22,12 +22,11 @@ } ], "require": { - "php": "^7.4||^8.0||^8.1", + "php": "^7.4||^8.01", "doctrine/annotations": "^1.13", "psr/simple-cache": "^1.0", "symfony/cache": "^5.4", - "composer/composer": "^2.2", - "roave/better-reflection": "^4.12 || ^5.6" + "composer/composer": "^2.2" }, "require-dev": { "phpunit/phpunit": "^8.5" diff --git a/src/Finder/DirectoryIteratorClassFinder.php b/src/Finder/DirectoryIteratorClassFinder.php index 223c9bc..7bd9785 100644 --- a/src/Finder/DirectoryIteratorClassFinder.php +++ b/src/Finder/DirectoryIteratorClassFinder.php @@ -43,6 +43,6 @@ public function setExcludeRegex(string $regex): void private function getClassNameFromFile(string $fileName): ?string { - return ClassNameFromPathGeneratorReflectionBased::getFullClassNameFromFile($fileName); + return ClassNameFromPathGenerator::getFullClassNameFromFile($fileName); } } diff --git a/src/Scanner/DoctrineAnnotationsScanner.php b/src/Scanner/DoctrineAnnotationsScanner.php index 1514403..b293ff0 100644 --- a/src/Scanner/DoctrineAnnotationsScanner.php +++ b/src/Scanner/DoctrineAnnotationsScanner.php @@ -8,9 +8,9 @@ use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\DocParser; use Doctrine\Common\Annotations\Reader; +use ReflectionClass; use ReflectionMethod; -use Roave\BetterReflection\Reflection\ReflectionClass; -use Roave\BetterReflection\Reflector\Exception\IdentifierNotFound; +use Throwable; class DoctrineAnnotationsScanner extends AbstractAnnotationScanner implements AnnotationScanner { @@ -30,10 +30,6 @@ public function __construct( $this->basePath = $basePath; - set_include_path(get_include_path() . PATH_SEPARATOR . $basePath); - spl_autoload_extensions('.php'); - spl_autoload_register(); - $this->scanMethod = $scanMethod; $this->excludeDirectoriesRegex = $excludeDirsRegex; @@ -49,7 +45,7 @@ public function __construct( public function scan(ScanMode $mode = null): ScanResult { /** - * @var $foundMethods \Roave\BetterReflection\Reflection\ReflectionMethod[] + * @var $foundMethods ReflectionMethod[] */ $foundMethods = []; @@ -68,15 +64,13 @@ public function scan(ScanMode $mode = null): ScanResult return new ScanResult(array_unique(array_merge(...$filesPaths))); } - private function getUsedAnnotationsClassPaths(\Roave\BetterReflection\Reflection\ReflectionMethod ...$reflectionMethod): array + private function getUsedAnnotationsClassPaths(ReflectionMethod ...$reflectionMethod): array { $foundPaths = []; foreach ($reflectionMethod as $foundMethod) { foreach ($this->annotationsToSearchCollection as $lookedForAnnotation) { - $nativeReflection = new ReflectionMethod($foundMethod->getDeclaringClass()->getName(), $foundMethod->getName()); - - $foundAnnotationOnMethod = $this->annotationReader->getMethodAnnotation($nativeReflection, $lookedForAnnotation); + $foundAnnotationOnMethod = $this->annotationReader->getMethodAnnotation($foundMethod, $lookedForAnnotation); if ($foundAnnotationOnMethod) { $foundPaths[] = $foundMethod->getFileName(); @@ -97,8 +91,8 @@ private function getMethods(string $className): ?array } try { - $reflectedClass = ReflectionClass::createFromName($className); - } catch (IdentifierNotFound $t) { + $reflectedClass = new ReflectionClass($className); + } catch (Throwable $t) { return null; }