Skip to content

Commit

Permalink
fix thrown Error from yieldAttributes, e.g. when a class extends a no…
Browse files Browse the repository at this point in the history
…nexistent other class
  • Loading branch information
frederikbosch committed Aug 23, 2024
1 parent bb32321 commit 8660aa5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/ClassScanner/ComposerMapGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ private function convertToClassMap(ClassMap $classMap, array $composerMap): Clas
$path = \substr($path, \strlen($this->basePath));
}

$classMap->addClass(
new ClassSpecification(
$class,
$path,
[...$this->reflector->yieldAttributes($class)]
)
);
try {
$attributes = [...$this->reflector->yieldAttributes($class)];
} catch (\Error) {
$attributes = [];
}

$classMap->addClass(new ClassSpecification($class, $path, $attributes));
}

return $classMap;
Expand Down
13 changes: 10 additions & 3 deletions src/Resolver/Reflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
namespace Aura\Di\Resolver;

use Aura\Di\ClassScanner\AttributeSpecification;
use Error;
use Generator;
use ReflectionClass;
use ReflectionException;

Expand Down Expand Up @@ -149,10 +151,15 @@ public function getTraits($class): array

/**
* @param string $className
* @return \Generator<int, AttributeSpecification>
*
* @return Generator<int, AttributeSpecification>
*
* @throws ReflectionException
*
* @throws Error An error is thrown when a class contains references to nonexistent other class, e.g. extending
* a class from a package that is not available.
*/
public function yieldAttributes(string $className): \Generator
public function yieldAttributes(string $className): Generator
{
$reflectionClass = $this->getClass($className);
foreach ($reflectionClass->getAttributes() as $attribute) {
Expand Down Expand Up @@ -223,7 +230,7 @@ public function configureAttribute(
string $className,
int $targetMethod,
array $targetConfig = []
): \Generator
): Generator
{
$instance = $attribute->newInstance();
yield new AttributeSpecification(
Expand Down

0 comments on commit 8660aa5

Please sign in to comment.