Skip to content

Commit

Permalink
get rid of external dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jlabno committed Jul 20, 2022
1 parent 05de885 commit 0c45bab
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/Finder/DirectoryIteratorClassFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public function setExcludeRegex(string $regex): void

private function getClassNameFromFile(string $fileName): ?string
{
return ClassNameFromPathGeneratorReflectionBased::getFullClassNameFromFile($fileName);
return ClassNameFromPathGenerator::getFullClassNameFromFile($fileName);
}
}
20 changes: 7 additions & 13 deletions src/Scanner/DoctrineAnnotationsScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand All @@ -49,7 +45,7 @@ public function __construct(
public function scan(ScanMode $mode = null): ScanResult
{
/**
* @var $foundMethods \Roave\BetterReflection\Reflection\ReflectionMethod[]
* @var $foundMethods ReflectionMethod[]
*/
$foundMethods = [];

Expand All @@ -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();
Expand All @@ -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;
}

Expand Down

0 comments on commit 0c45bab

Please sign in to comment.