Skip to content

Commit

Permalink
try/catch class_exists failure
Browse files Browse the repository at this point in the history
  • Loading branch information
jlabno committed Jul 20, 2022
1 parent f7447d5 commit 9aacf50
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/Scanner/DoctrineAnnotationsScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
use ReflectionMethod;
use Throwable;

class DoctrineAnnotationsScanner extends AbstractAnnotationScanner implements AnnotationScanner
class DoctrineAnnotationsScanner extends AbstractAnnotationScanner
implements AnnotationScanner
{
private Reader $annotationReader;
private AnnotationsToSearchCollection $annotationsToSearchCollection;
Expand All @@ -21,10 +22,10 @@ class DoctrineAnnotationsScanner extends AbstractAnnotationScanner implements An

public function __construct(
AnnotationsToSearchCollection $annotationsToSearchCollection,
string $basePath,
string $scanMethod,
?string $excludeDirsRegex = null,
Reader $reader = null
string $basePath,
string $scanMethod,
?string $excludeDirsRegex = null,
Reader $reader = null
) {
$this->annotationsToSearchCollection = $annotationsToSearchCollection;

Expand Down Expand Up @@ -58,19 +59,25 @@ public function scan(ScanMode $mode = null): ScanResult
$filesPaths = [];

foreach ($foundMethods as $foundMethod) {
$filesPaths[] = $this->getUsedAnnotationsClassPaths(...$foundMethod);
$filesPaths[] = $this->getUsedAnnotationsClassPaths(...
$foundMethod);
}

return new ScanResult(array_unique(array_merge(...$filesPaths)));
}

private function getUsedAnnotationsClassPaths(ReflectionMethod ...$reflectionMethod): array
{
private function getUsedAnnotationsClassPaths(
ReflectionMethod ...$reflectionMethod
): array {
$foundPaths = [];

foreach ($reflectionMethod as $foundMethod) {
foreach ($this->annotationsToSearchCollection as $lookedForAnnotation) {
$foundAnnotationOnMethod = $this->annotationReader->getMethodAnnotation($foundMethod, $lookedForAnnotation);
foreach (
$this->annotationsToSearchCollection as $lookedForAnnotation
) {
$foundAnnotationOnMethod
= $this->annotationReader->getMethodAnnotation($foundMethod,
$lookedForAnnotation);

if ($foundAnnotationOnMethod) {
$foundPaths[] = $foundMethod->getFileName();
Expand All @@ -86,7 +93,11 @@ private function getUsedAnnotationsClassPaths(ReflectionMethod ...$reflectionMet
*/
private function getMethods(string $className): ?array
{
if (!class_exists($className)) {
try {
if ( ! class_exists($className)) {
return null;
}
} catch (Throwable $t) {
return null;
}

Expand All @@ -104,6 +115,7 @@ private function getMethods(string $className): ?array
*/
private function getClassesNames(): array
{
return $this->getClassFinder($this->scanMethod)->getClassesNames($this->basePath);
return $this->getClassFinder($this->scanMethod)
->getClassesNames($this->basePath);
}
}

0 comments on commit 9aacf50

Please sign in to comment.