diff --git a/src/MemoizeAttributeCollector.php b/src/MemoizeAttributeCollector.php index 24c9c66..25f3157 100644 --- a/src/MemoizeAttributeCollector.php +++ b/src/MemoizeAttributeCollector.php @@ -3,7 +3,6 @@ namespace olvlvl\ComposerAttributeCollector; use Composer\IO\IOInterface; -use ReflectionException; use Throwable; use function array_filter; @@ -59,7 +58,7 @@ public function collectAttributes(array $classMap): TransientCollection $timestamp, $classAttributes, $methodAttributes, - $propertyAttributes + $propertyAttributes, ] = $this->state[$class] ?? [ 0, [], [], [] ]; $mtime = filemtime($filepath); @@ -76,20 +75,26 @@ public function collectAttributes(array $classMap): TransientCollection [ $classAttributes, $methodAttributes, - $propertyAttributes + $propertyAttributes, ] = $classAttributeCollector->collectAttributes($class); } catch (Throwable $e) { $this->io->error( - "Attribute collection failed for $class: {$e->getMessage()}" + "Attribute collection failed for $class: {$e->getMessage()}", ); } $this->state[$class] = [ time(), $classAttributes, $methodAttributes, $propertyAttributes ]; } - $collector->addClassAttributes($class, $classAttributes); - $collector->addMethodAttributes($class, $methodAttributes); - $collector->addTargetProperties($class, $propertyAttributes); + if (count($classAttributes)) { + $collector->addClassAttributes($class, $classAttributes); + } + if (count($methodAttributes)) { + $collector->addMethodAttributes($class, $methodAttributes); + } + if (count($propertyAttributes)) { + $collector->addTargetProperties($class, $propertyAttributes); + } } /** @@ -98,7 +103,7 @@ public function collectAttributes(array $classMap): TransientCollection $this->state = array_filter( $this->state, static fn(string $k): bool => $filterClasses[$k] ?? false, - ARRAY_FILTER_USE_KEY + ARRAY_FILTER_USE_KEY, ); $this->datastore->set(self::KEY, $this->state);