File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,29 @@ public function extractMethodBodies(string $className): array
79
79
}
80
80
81
81
82
+ /** @return array<string, array<string, string>> */
83
+ public function extractPropertyHookBodies (string $ className ): array
84
+ {
85
+ $ nodeFinder = new NodeFinder ();
86
+ $ classNode = $ nodeFinder ->findFirst (
87
+ $ this ->statements ,
88
+ fn (Node $ node ) => $ node instanceof Node \Stmt \ClassLike && $ node ->namespacedName ->toString () === $ className ,
89
+ );
90
+
91
+ $ res = [];
92
+ foreach ($ nodeFinder ->findInstanceOf ($ classNode , Node \Stmt \Property::class) as $ propertyNode ) {
93
+ foreach ($ propertyNode ->props as $ propNode ) {
94
+ $ propName = $ propNode ->name ->toString ();
95
+ foreach ($ propertyNode ->hooks as $ hookNode ) {
96
+ $ hookType = $ hookNode ->name ->toString ();
97
+ $ res [$ propName ][$ hookType ] = $ this ->getReformattedContents ([$ hookNode ->body ], 1 );
98
+ }
99
+ }
100
+ }
101
+ return $ res ;
102
+ }
103
+
104
+
82
105
public function extractFunctionBody (string $ name ): ?string
83
106
{
84
107
$ functionNode = (new NodeFinder )->findFirst (
Original file line number Diff line number Diff line change @@ -124,6 +124,15 @@ public function fromClassReflection(
124
124
$ resolutions = [];
125
125
}
126
126
127
+ if ($ withBodies ) {
128
+ $ hookBodies = $ this ->getExtractor ($ declaringClass ->getFileName ())->extractPropertyHookBodies ($ declaringClass ->name );
129
+ foreach ($ class ->getProperties () as $ property ) {
130
+ foreach ($ hookBodies [$ property ->getName ()] ?? [] as $ hookType => $ body ) {
131
+ $ property ->getHook ($ hookType )?->setBody($ body , short: true );
132
+ }
133
+ }
134
+ }
135
+
127
136
$ consts = $ cases = [];
128
137
foreach ($ from ->getReflectionConstants () as $ const ) {
129
138
if ($ class ->isEnum () && $ from ->hasCase ($ const ->name )) {
You can’t perform that action at this time.
0 commit comments