Skip to content

Commit

Permalink
Don't add empty lists
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Nov 27, 2024
1 parent 17eed38 commit 929d155
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/MemoizeAttributeCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace olvlvl\ComposerAttributeCollector;

use Composer\IO\IOInterface;
use ReflectionException;
use Throwable;

use function array_filter;
Expand Down Expand Up @@ -59,7 +58,7 @@ public function collectAttributes(array $classMap): TransientCollection
$timestamp,
$classAttributes,
$methodAttributes,
$propertyAttributes
$propertyAttributes,
] = $this->state[$class] ?? [ 0, [], [], [] ];

$mtime = filemtime($filepath);
Expand All @@ -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);
}
}

/**
Expand All @@ -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);
Expand Down

0 comments on commit 929d155

Please sign in to comment.