3
3
namespace olvlvl \ComposerAttributeCollector ;
4
4
5
5
use Composer \IO \IOInterface ;
6
- use ReflectionException ;
7
6
use Throwable ;
8
7
9
8
use function array_filter ;
@@ -59,7 +58,7 @@ public function collectAttributes(array $classMap): TransientCollection
59
58
$ timestamp ,
60
59
$ classAttributes ,
61
60
$ methodAttributes ,
62
- $ propertyAttributes
61
+ $ propertyAttributes,
63
62
] = $ this ->state [$ class ] ?? [ 0 , [], [], [] ];
64
63
65
64
$ mtime = filemtime ($ filepath );
@@ -76,20 +75,26 @@ public function collectAttributes(array $classMap): TransientCollection
76
75
[
77
76
$ classAttributes ,
78
77
$ methodAttributes ,
79
- $ propertyAttributes
78
+ $ propertyAttributes,
80
79
] = $ classAttributeCollector ->collectAttributes ($ class );
81
80
} catch (Throwable $ e ) {
82
81
$ this ->io ->error (
83
- "Attribute collection failed for $ class: {$ e ->getMessage ()}"
82
+ "Attribute collection failed for $ class: {$ e ->getMessage ()}" ,
84
83
);
85
84
}
86
85
87
86
$ this ->state [$ class ] = [ time (), $ classAttributes , $ methodAttributes , $ propertyAttributes ];
88
87
}
89
88
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
+ }
93
98
}
94
99
95
100
/**
@@ -98,7 +103,7 @@ public function collectAttributes(array $classMap): TransientCollection
98
103
$ this ->state = array_filter (
99
104
$ this ->state ,
100
105
static fn (string $ k ): bool => $ filterClasses [$ k ] ?? false ,
101
- ARRAY_FILTER_USE_KEY
106
+ ARRAY_FILTER_USE_KEY ,
102
107
);
103
108
104
109
$ this ->datastore ->set (self ::KEY , $ this ->state );
0 commit comments