File tree Expand file tree Collapse file tree 6 files changed +27
-9
lines changed Expand file tree Collapse file tree 6 files changed +27
-9
lines changed Original file line number Diff line number Diff line change @@ -168,7 +168,13 @@ public function printClass(
168168 }
169169
170170 $ consts = [];
171- if ($ class instanceof ClassType || $ class instanceof InterfaceType || $ class instanceof EnumType) {
171+ $ methods = [];
172+ if (
173+ $ class instanceof ClassType
174+ || $ class instanceof InterfaceType
175+ || $ class instanceof TraitType
176+ || $ class instanceof EnumType
177+ ) {
172178 foreach ($ class ->getConstants () as $ const ) {
173179 $ def = ($ const ->isFinal () ? 'final ' : '' )
174180 . ($ const ->getVisibility () ? $ const ->getVisibility () . ' ' : '' )
@@ -179,15 +185,7 @@ public function printClass(
179185 . $ def
180186 . $ this ->dump ($ const ->getValue (), strlen ($ def )) . "; \n" ;
181187 }
182- }
183188
184- $ methods = [];
185- if (
186- $ class instanceof ClassType
187- || $ class instanceof InterfaceType
188- || $ class instanceof EnumType
189- || $ class instanceof TraitType
190- ) {
191189 foreach ($ class ->getMethods () as $ method ) {
192190 $ methods [] = $ this ->printMethod ($ method , $ namespace , $ class ->isInterface ());
193191 }
Original file line number Diff line number Diff line change 2020 */
2121final class TraitType extends ClassLike
2222{
23+ use Traits \ConstantsAware;
2324 use Traits \MethodsAware;
2425 use Traits \PropertiesAware;
2526 use Traits \TraitsAware;
@@ -28,6 +29,7 @@ public function addMember(Method|Property|Constant|TraitUse $member): static
2829 {
2930 $ name = $ member ->getName ();
3031 [$ type , $ n ] = match (true ) {
32+ $ member instanceof Constant => ['consts ' , $ name ],
3133 $ member instanceof Method => ['methods ' , strtolower ($ name )],
3234 $ member instanceof Property => ['properties ' , $ name ],
3335 $ member instanceof TraitUse => ['traits ' , $ name ],
@@ -43,6 +45,7 @@ public function addMember(Method|Property|Constant|TraitUse $member): static
4345 public function __clone ()
4446 {
4547 $ clone = fn ($ item ) => clone $ item ;
48+ $ this ->consts = array_map ($ clone , $ this ->consts );
4649 $ this ->methods = array_map ($ clone , $ this ->methods );
4750 $ this ->properties = array_map ($ clone , $ this ->properties );
4851 $ this ->traits = array_map ($ clone , $ this ->traits );
Original file line number Diff line number Diff line change @@ -13,5 +13,6 @@ require __DIR__ . '/../bootstrap.php';
1313require __DIR__ . '/fixtures/classes.82.php ' ;
1414
1515$ res [] = ClassType::from (new Abc \Class13 );
16+ $ res [] = ClassType::from (Abc \Trait13::class);
1617
1718sameFile (__DIR__ . '/expected/ClassType.from.82.expect ' , implode ("\n" , $ res ));
Original file line number Diff line number Diff line change 11readonly class Class13
22{
33}
4+
5+ trait Trait13
6+ {
7+ public const FOO = 123;
8+ }
Original file line number Diff line number Diff line change @@ -7,3 +7,8 @@ namespace Abc;
77readonly class Class13
88{
99}
10+
11+ trait Trait13
12+ {
13+ public const FOO = 123;
14+ }
Original file line number Diff line number Diff line change 77readonly class Class13
88{
99}
10+
11+
12+ trait Trait13
13+ {
14+ public const FOO = 123 ;
15+ }
You can’t perform that action at this time.
0 commit comments