File tree 6 files changed +27
-9
lines changed
6 files changed +27
-9
lines changed Original file line number Diff line number Diff line change @@ -167,7 +167,13 @@ public function printClass(
167
167
}
168
168
169
169
$ 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
+ ) {
171
177
foreach ($ class ->getConstants () as $ const ) {
172
178
$ def = ($ const ->isFinal () ? 'final ' : '' )
173
179
. ($ const ->getVisibility () ? $ const ->getVisibility () . ' ' : '' )
@@ -178,15 +184,7 @@ public function printClass(
178
184
. $ def
179
185
. $ this ->dump ($ const ->getValue (), strlen ($ def )) . "; \n" ;
180
186
}
181
- }
182
187
183
- $ methods = [];
184
- if (
185
- $ class instanceof ClassType
186
- || $ class instanceof InterfaceType
187
- || $ class instanceof EnumType
188
- || $ class instanceof TraitType
189
- ) {
190
188
foreach ($ class ->getMethods () as $ method ) {
191
189
$ methods [] = $ this ->printMethod ($ method , $ namespace , $ class ->isInterface ());
192
190
}
Original file line number Diff line number Diff line change 20
20
*/
21
21
final class TraitType extends ClassLike
22
22
{
23
+ use Traits \ConstantsAware;
23
24
use Traits \MethodsAware;
24
25
use Traits \PropertiesAware;
25
26
use Traits \TraitsAware;
@@ -28,6 +29,7 @@ public function addMember(Method|Property|Constant|TraitUse $member): static
28
29
{
29
30
$ name = $ member ->getName ();
30
31
[$ type , $ n ] = match (true ) {
32
+ $ member instanceof Constant => ['consts ' , $ name ],
31
33
$ member instanceof Method => ['methods ' , strtolower ($ name )],
32
34
$ member instanceof Property => ['properties ' , $ name ],
33
35
$ member instanceof TraitUse => ['traits ' , $ name ],
@@ -43,6 +45,7 @@ public function addMember(Method|Property|Constant|TraitUse $member): static
43
45
public function __clone ()
44
46
{
45
47
$ clone = fn ($ item ) => clone $ item ;
48
+ $ this ->consts = array_map ($ clone , $ this ->consts );
46
49
$ this ->methods = array_map ($ clone , $ this ->methods );
47
50
$ this ->properties = array_map ($ clone , $ this ->properties );
48
51
$ 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';
13
13
require __DIR__ . '/fixtures/classes.82.php ' ;
14
14
15
15
$ res [] = ClassType::from (new Abc \Class13 );
16
+ $ res [] = ClassType::from (Abc \Trait13::class);
16
17
17
18
sameFile (__DIR__ . '/expected/ClassType.from.82.expect ' , implode ("\n" , $ res ));
Original file line number Diff line number Diff line change 1
1
readonly class Class13
2
2
{
3
3
}
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;
7
7
readonly class Class13
8
8
{
9
9
}
10
+
11
+ trait Trait13
12
+ {
13
+ public const FOO = 123;
14
+ }
Original file line number Diff line number Diff line change 7
7
readonly class Class13
8
8
{
9
9
}
10
+
11
+
12
+ trait Trait13
13
+ {
14
+ public const FOO = 123 ;
15
+ }
You can’t perform that action at this time.
0 commit comments