@@ -40,6 +40,7 @@ public function fromClassReflection(\ReflectionClass $from, bool $withBodies = f
4040 $ class ->setImplements ($ ifaces );
4141
4242 $ class ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
43+ $ class ->setAttributes (self ::getAttributes ($ from ));
4344 if ($ from ->getParentClass ()) {
4445 $ class ->setExtends ($ from ->getParentClass ()->name );
4546 $ class ->setImplements (array_diff ($ class ->getImplements (), $ from ->getParentClass ()->getInterfaceNames ()));
@@ -99,6 +100,7 @@ public function fromMethodReflection(\ReflectionMethod $from): Method
99100 $ method ->setReturnReference ($ from ->returnsReference ());
100101 $ method ->setVariadic ($ from ->isVariadic ());
101102 $ method ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
103+ $ method ->setAttributes (self ::getAttributes ($ from ));
102104 if ($ from ->getReturnType () instanceof \ReflectionNamedType) {
103105 $ method ->setReturnType ($ from ->getReturnType ()->getName ());
104106 $ method ->setReturnNullable ($ from ->getReturnType ()->allowsNull ());
@@ -117,6 +119,7 @@ public function fromFunctionReflection(\ReflectionFunction $from, bool $withBody
117119 if (!$ from ->isClosure ()) {
118120 $ function ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
119121 }
122+ $ function ->setAttributes (self ::getAttributes ($ from ));
120123 if ($ from ->getReturnType () instanceof \ReflectionNamedType) {
121124 $ function ->setReturnType ($ from ->getReturnType ()->getName ());
122125 $ function ->setReturnNullable ($ from ->getReturnType ()->allowsNull ());
@@ -150,6 +153,7 @@ public function fromParameterReflection(\ReflectionParameter $from): Parameter
150153 : $ from ->getDefaultValue ());
151154 $ param ->setNullable ($ param ->isNullable () && $ param ->getDefaultValue () !== null );
152155 }
156+ $ param ->setAttributes (self ::getAttributes ($ from ));
153157 return $ param ;
154158 }
155159
@@ -164,6 +168,7 @@ public function fromConstantReflection(\ReflectionClassConstant $from): Constant
164168 : ($ from ->isProtected () ? ClassType::VISIBILITY_PROTECTED : ClassType::VISIBILITY_PUBLIC )
165169 );
166170 $ const ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
171+ $ const ->setAttributes (self ::getAttributes ($ from ));
167172 return $ const ;
168173 }
169174
@@ -185,6 +190,7 @@ public function fromPropertyReflection(\ReflectionProperty $from): Property
185190 $ prop ->setInitialized (array_key_exists ($ prop ->getName (), $ defaults ));
186191 }
187192 $ prop ->setComment (Helpers::unformatDocComment ((string ) $ from ->getDocComment ()));
193+ $ prop ->setAttributes (self ::getAttributes ($ from ));
188194 return $ prop ;
189195 }
190196
@@ -327,4 +333,17 @@ private function parse($from): array
327333
328334 return [$ code , $ stmts ];
329335 }
336+
337+
338+ private function getAttributes ($ from ): array
339+ {
340+ if (PHP_VERSION_ID < 80000 ) {
341+ return [];
342+ }
343+ $ res = [];
344+ foreach ($ from ->getAttributes () as $ attr ) {
345+ $ res [] = new Attribute ($ attr ->getName (), $ attr ->getArguments ());
346+ }
347+ return $ res ;
348+ }
330349}
0 commit comments