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 @@ -167,7 +167,13 @@ public function printClass(
167167 }
168168
169169 $ consts = [];
170- if ($ class instanceof ClassType || $ class instanceof InterfaceType || $ class instanceof EnumType) {
170+ $ methods = [];
171+ if (
172+ $ class instanceof ClassType
173+ || $ class instanceof InterfaceType
174+ || $ class instanceof TraitType
175+ || $ class instanceof EnumType
176+ ) {
171177 foreach ($ class ->getConstants () as $ const ) {
172178 $ def = ($ const ->isFinal () ? 'final ' : '' )
173179 . ($ const ->getVisibility () ? $ const ->getVisibility () . ' ' : '' )
@@ -178,15 +184,7 @@ public function printClass(
178184 . $ def
179185 . $ this ->dump ($ const ->getValue (), strlen ($ def )) . "; \n" ;
180186 }
181- }
182187
183- $ methods = [];
184- if (
185- $ class instanceof ClassType
186- || $ class instanceof InterfaceType
187- || $ class instanceof EnumType
188- || $ class instanceof TraitType
189- ) {
190188 foreach ($ class ->getMethods () as $ method ) {
191189 $ methods [] = $ this ->printMethod ($ method , $ namespace , $ class ->isInterface ());
192190 }
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