Skip to content

Commit 929d155

Browse files
committed
Don't add empty lists
1 parent 17eed38 commit 929d155

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/MemoizeAttributeCollector.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace olvlvl\ComposerAttributeCollector;
44

55
use Composer\IO\IOInterface;
6-
use ReflectionException;
76
use Throwable;
87

98
use function array_filter;
@@ -59,7 +58,7 @@ public function collectAttributes(array $classMap): TransientCollection
5958
$timestamp,
6059
$classAttributes,
6160
$methodAttributes,
62-
$propertyAttributes
61+
$propertyAttributes,
6362
] = $this->state[$class] ?? [ 0, [], [], [] ];
6463

6564
$mtime = filemtime($filepath);
@@ -76,20 +75,26 @@ public function collectAttributes(array $classMap): TransientCollection
7675
[
7776
$classAttributes,
7877
$methodAttributes,
79-
$propertyAttributes
78+
$propertyAttributes,
8079
] = $classAttributeCollector->collectAttributes($class);
8180
} catch (Throwable $e) {
8281
$this->io->error(
83-
"Attribute collection failed for $class: {$e->getMessage()}"
82+
"Attribute collection failed for $class: {$e->getMessage()}",
8483
);
8584
}
8685

8786
$this->state[$class] = [ time(), $classAttributes, $methodAttributes, $propertyAttributes ];
8887
}
8988

90-
$collector->addClassAttributes($class, $classAttributes);
91-
$collector->addMethodAttributes($class, $methodAttributes);
92-
$collector->addTargetProperties($class, $propertyAttributes);
89+
if (count($classAttributes)) {
90+
$collector->addClassAttributes($class, $classAttributes);
91+
}
92+
if (count($methodAttributes)) {
93+
$collector->addMethodAttributes($class, $methodAttributes);
94+
}
95+
if (count($propertyAttributes)) {
96+
$collector->addTargetProperties($class, $propertyAttributes);
97+
}
9398
}
9499

95100
/**
@@ -98,7 +103,7 @@ public function collectAttributes(array $classMap): TransientCollection
98103
$this->state = array_filter(
99104
$this->state,
100105
static fn(string $k): bool => $filterClasses[$k] ?? false,
101-
ARRAY_FILTER_USE_KEY
106+
ARRAY_FILTER_USE_KEY,
102107
);
103108

104109
$this->datastore->set(self::KEY, $this->state);

0 commit comments

Comments
 (0)