16
16
use PHPStan \Type \TypeTraverser ;
17
17
use function array_key_exists ;
18
18
use function count ;
19
+ use function is_bool ;
19
20
use function strtolower ;
20
21
use function substr ;
21
22
@@ -128,18 +129,24 @@ public static function resolvePhpDocBlockForProperty(
128
129
array $ newPositionalParameterNames , // unused
129
130
): self
130
131
{
131
- return self ::resolvePhpDocBlockTree (
132
- $ docComment ,
133
- $ classReflection ,
134
- $ trait ,
132
+ $ docBlocksFromParents = self ::resolveParentPhpDocBlocks (
133
+ self ::getParentReflections ($ classReflection ),
135
134
$ propertyName ,
136
- $ file ,
137
135
'hasNativeProperty ' ,
138
136
'getNativeProperty ' ,
139
137
__FUNCTION__ ,
140
- $ explicit ,
141
- [],
142
- [],
138
+ $ explicit ?? $ docComment !== null ,
139
+ $ newPositionalParameterNames ,
140
+ );
141
+
142
+ return new self (
143
+ $ docComment ?? ResolvedPhpDocBlock::EMPTY_DOC_STRING ,
144
+ $ file ,
145
+ $ classReflection ,
146
+ $ trait ,
147
+ $ explicit ?? true ,
148
+ self ::remapParameterNames ($ originalPositionalParameterNames , $ newPositionalParameterNames ),
149
+ $ docBlocksFromParents ,
143
150
);
144
151
}
145
152
@@ -158,18 +165,24 @@ public static function resolvePhpDocBlockForConstant(
158
165
array $ newPositionalParameterNames , // unused
159
166
): self
160
167
{
161
- return self ::resolvePhpDocBlockTree (
162
- $ docComment ,
163
- $ classReflection ,
164
- null ,
168
+ $ docBlocksFromParents = self ::resolveParentPhpDocBlocks (
169
+ self ::getParentReflections ($ classReflection ),
165
170
$ constantName ,
166
- $ file ,
167
171
'hasConstant ' ,
168
172
'getConstant ' ,
169
173
__FUNCTION__ ,
170
- $ explicit ,
171
- [],
172
- [],
174
+ $ explicit ?? $ docComment !== null ,
175
+ $ newPositionalParameterNames ,
176
+ );
177
+
178
+ return new self (
179
+ $ docComment ?? ResolvedPhpDocBlock::EMPTY_DOC_STRING ,
180
+ $ file ,
181
+ $ classReflection ,
182
+ $ trait ,
183
+ $ explicit ?? true ,
184
+ self ::remapParameterNames ($ originalPositionalParameterNames , $ newPositionalParameterNames ),
185
+ $ docBlocksFromParents ,
173
186
);
174
187
}
175
188
@@ -188,45 +201,30 @@ public static function resolvePhpDocBlockForMethod(
188
201
array $ newPositionalParameterNames ,
189
202
): self
190
203
{
191
- return self ::resolvePhpDocBlockTree (
192
- $ docComment ,
193
- $ classReflection ,
194
- $ trait ,
204
+ $ parentReflections = self ::getParentReflections ($ classReflection );
205
+ foreach ($ classReflection ->getTraits (true ) as $ traitReflection ) {
206
+ if (!$ traitReflection ->hasNativeMethod ($ methodName )) {
207
+ continue ;
208
+ }
209
+ $ traitMethod = $ traitReflection ->getNativeMethod ($ methodName );
210
+ $ abstract = $ traitMethod ->isAbstract ();
211
+ if (is_bool ($ abstract )) {
212
+ if (!$ abstract ) {
213
+ continue ;
214
+ }
215
+ } elseif (!$ abstract ->yes ()) {
216
+ continue ;
217
+ }
218
+
219
+ $ parentReflections [] = $ traitReflection ;
220
+ }
221
+
222
+ $ docBlocksFromParents = self ::resolveParentPhpDocBlocks (
223
+ $ parentReflections ,
195
224
$ methodName ,
196
- $ file ,
197
225
'hasNativeMethod ' ,
198
226
'getNativeMethod ' ,
199
227
__FUNCTION__ ,
200
- $ explicit ,
201
- $ originalPositionalParameterNames ,
202
- $ newPositionalParameterNames ,
203
- );
204
- }
205
-
206
- /**
207
- * @param array<int, string> $originalPositionalParameterNames
208
- * @param array<int, string> $newPositionalParameterNames
209
- */
210
- private static function resolvePhpDocBlockTree (
211
- ?string $ docComment ,
212
- ClassReflection $ classReflection ,
213
- ?string $ trait ,
214
- string $ name ,
215
- ?string $ file ,
216
- string $ hasMethodName ,
217
- string $ getMethodName ,
218
- string $ resolveMethodName ,
219
- ?bool $ explicit ,
220
- array $ originalPositionalParameterNames ,
221
- array $ newPositionalParameterNames ,
222
- ): self
223
- {
224
- $ docBlocksFromParents = self ::resolveParentPhpDocBlocks (
225
- $ classReflection ,
226
- $ name ,
227
- $ hasMethodName ,
228
- $ getMethodName ,
229
- $ resolveMethodName ,
230
228
$ explicit ?? $ docComment !== null ,
231
229
$ newPositionalParameterNames ,
232
230
);
@@ -264,11 +262,12 @@ private static function remapParameterNames(
264
262
}
265
263
266
264
/**
265
+ * @param array<int, ClassReflection> $parentReflections
267
266
* @param array<int, string> $positionalParameterNames
268
267
* @return array<int, self>
269
268
*/
270
269
private static function resolveParentPhpDocBlocks (
271
- ClassReflection $ classReflection ,
270
+ array $ parentReflections ,
272
271
string $ name ,
273
272
string $ hasMethodName ,
274
273
string $ getMethodName ,
@@ -278,7 +277,6 @@ private static function resolveParentPhpDocBlocks(
278
277
): array
279
278
{
280
279
$ result = [];
281
- $ parentReflections = self ::getParentReflections ($ classReflection );
282
280
283
281
foreach ($ parentReflections as $ parentReflection ) {
284
282
$ oneResult = self ::resolvePhpDocBlockFromClass (
0 commit comments