Skip to content

Commit 73fdbb7

Browse files
committed
Replace static everywhere
1 parent e2f8f48 commit 73fdbb7

File tree

5 files changed

+352
-25
lines changed

5 files changed

+352
-25
lines changed

renderers/BaseRenderer.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -220,20 +220,20 @@ public function createTypeLink(
220220
} elseif ($type instanceof Type) {
221221
if ($type instanceof Compound) {
222222
$innerTypes = TypeHelper::getTypesByAggregatedType($type);
223-
$links[] = $this->createTypeLink($innerTypes, $context, $title, $options);
223+
$links[] = $this->createTypeLink($innerTypes, $context, $title, $options, $currentTypeDoc);
224224
continue;
225225
}
226226

227227
if ($type instanceof ConditionalForParameter || $type instanceof Conditional) {
228228
$possibleTypes = TypeHelper::getPossibleTypesByConditionalType($type);
229-
$links[] = $this->createTypeLink($possibleTypes, $context, $title, $options);
229+
$links[] = $this->createTypeLink($possibleTypes, $context, $title, $options, $currentTypeDoc);
230230
continue;
231231
}
232232

233233
if ($type instanceof Intersection) {
234234
$innerTypes = TypeHelper::getTypesByAggregatedType($type);
235235
$innerTypesLinks = array_map(
236-
fn(Type $innerType) => $this->createTypeLink($innerType, $context, $title, $options),
236+
fn(Type $innerType) => $this->createTypeLink($innerType, $context, $title, $options, $currentTypeDoc),
237237
$innerTypes
238238
);
239239
$links[] = implode('&', $innerTypesLinks);
@@ -247,7 +247,7 @@ public function createTypeLink(
247247
}
248248

249249
if ($type instanceof Array_ && substr((string) $type, -3, 3) === ')[]') {
250-
$arrayTypesLinks = $this->createTypeLink($type->getValueType(), $context, $title, $options);
250+
$arrayTypesLinks = $this->createTypeLink($type->getValueType(), $context, $title, $options, $currentTypeDoc);
251251
$links[] = "({$arrayTypesLinks})[]";
252252
continue;
253253
}
@@ -257,7 +257,7 @@ public function createTypeLink(
257257
if ($valueType instanceof Object_ && $valueType->getFqsen() !== null) {
258258
$templateType = $this->getTemplateType((string) $valueType->getFqsen(), $context);
259259
if ($templateType !== null) {
260-
$typeLink = $this->createTypeLink($templateType, $context, $title, $options);
260+
$typeLink = $this->createTypeLink($templateType, $context, $title, $options, $currentTypeDoc);
261261
$links[] = $templateType instanceof Compound ? "({$typeLink})[]" : "{$typeLink}[]";
262262
continue;
263263
}
@@ -268,14 +268,14 @@ public function createTypeLink(
268268
}
269269

270270
if ($type instanceof ArrayShape) {
271-
$itemsLinks = $this->createLinksByShapeItems($type->getItems(), $context, $title, $options);
271+
$itemsLinks = $this->createLinksByShapeItems($type->getItems(), $context, $title, $options, $currentTypeDoc);
272272
$mainTypeLink = $this->generateLink('array', self::PHPSTAN_TYPE_BASE_URL . 'array-shapes', $options);
273273
$links[] = $mainTypeLink . '{' . implode(', ', $itemsLinks) . '}';
274274
continue;
275275
}
276276

277277
if ($type instanceof ObjectShape) {
278-
$itemsLinks = $this->createLinksByShapeItems($type->getItems(), $context, $title, $options);
278+
$itemsLinks = $this->createLinksByShapeItems($type->getItems(), $context, $title, $options, $currentTypeDoc);
279279
$mainTypeLink = $this->generateLink('object', self::PHPSTAN_TYPE_BASE_URL . 'object-shapes', $options);
280280
$links[] = $mainTypeLink . '{' . implode(', ', $itemsLinks) . '}';
281281
continue;
@@ -291,7 +291,7 @@ public function createTypeLink(
291291
continue;
292292
}
293293

294-
if (($link = $this->createLinkByTypeWithGenerics($type, $context, $title, $options)) !== null) {
294+
if (($link = $this->createLinkByTypeWithGenerics($type, $context, $title, $options, $currentTypeDoc)) !== null) {
295295
$links[] = $link;
296296
continue;
297297
}
@@ -306,7 +306,7 @@ public function createTypeLink(
306306
}
307307

308308
if (($templateType = $this->getTemplateType($fqsen, $context)) !== null) {
309-
$links[] = $this->createTypeLink($templateType, $context, $title, $options);
309+
$links[] = $this->createTypeLink($templateType, $context, $title, $options, $currentTypeDoc);
310310
continue;
311311
}
312312

@@ -607,8 +607,13 @@ private function getTypeDocByQualifiedClassName(string $className, ?BaseDoc $con
607607
* @param ShapeItem[] $items
608608
* @return string[]
609609
*/
610-
private function createLinksByShapeItems(array $items, ?BaseDoc $context, ?string $title, array $options): array
611-
{
610+
private function createLinksByShapeItems(
611+
array $items,
612+
?BaseDoc $context,
613+
?string $title,
614+
array $options,
615+
?TypeDoc $currentTypeDoc
616+
): array {
612617
$links = [];
613618

614619
foreach ($items as $item) {
@@ -618,10 +623,10 @@ private function createLinksByShapeItems(array $items, ?BaseDoc $context, ?strin
618623
'%s%s: %s',
619624
$itemKey,
620625
$item->isOptional() ? '?' : '',
621-
$this->createTypeLink($item->getValue(), $context, $title, $options)
626+
$this->createTypeLink($item->getValue(), $context, $title, $options, $currentTypeDoc)
622627
);
623628
} else {
624-
$links[] = $this->createTypeLink($item->getValue(), $context, $title, $options);
629+
$links[] = $this->createTypeLink($item->getValue(), $context, $title, $options, $currentTypeDoc);
625630
}
626631
}
627632

@@ -635,15 +640,21 @@ private function createLinkByTypeWithGenerics(
635640
Type $type,
636641
?BaseDoc $context,
637642
?string $title,
638-
array $options
643+
array $options,
644+
?TypeDoc $currentTypeDoc
639645
): ?string {
640646
/**
641647
* @param Type[] $genericTypes
642648
*/
643-
$generateLink = function (Type $mainType, array $genericTypes) use ($context, $title, $options): string {
649+
$generateLink = function (Type $mainType, array $genericTypes) use (
650+
$context,
651+
$title,
652+
$options,
653+
$currentTypeDoc
654+
): string {
644655
$genericTypesLinks = $this->createTypeLinksByTypes($genericTypes, $context, $title, $options);
645656
$mainTypeLinkOptions = array_merge($options, ['forcePhpStanLink' => true]);
646-
$mainTypeLink = $this->createTypeLink($mainType, $context, $title, $mainTypeLinkOptions);
657+
$mainTypeLink = $this->createTypeLink($mainType, $context, $title, $mainTypeLinkOptions, $currentTypeDoc);
647658
return "{$mainTypeLink}<" . implode(', ', $genericTypesLinks) . '>';
648659
};
649660

tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__18.txt

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,55 +288,90 @@ Array
288288
)
289289

290290
[41] => Array
291+
(
292+
[line] => 93
293+
[file] => /tests/data/api/animal/Dog.php
294+
[message] => No short description for Method 'getArrayWithStaticGeneric'
295+
)
296+
297+
[42] => Array
298+
(
299+
[line] => 100
300+
[file] => /tests/data/api/animal/Dog.php
301+
[message] => No short description for Method 'getIterableWithStaticGeneric'
302+
)
303+
304+
[43] => Array
305+
(
306+
[line] => 107
307+
[file] => /tests/data/api/animal/Dog.php
308+
[message] => No short description for Method 'getArrayShapeWithStaticGeneric'
309+
)
310+
311+
[44] => Array
312+
(
313+
[line] => 114
314+
[file] => /tests/data/api/animal/Dog.php
315+
[message] => No short description for Method 'getObjectShapeWithStaticGeneric'
316+
)
317+
318+
[45] => Array
319+
(
320+
[line] => 121
321+
[file] => /tests/data/api/animal/Dog.php
322+
[message] => No short description for Method 'getStaticOrNull'
323+
)
324+
325+
[46] => Array
291326
(
292327
[line] => 11
293328
[file] => /tests/data/api/base/Component.php
294329
[message] => No docblock for element 'yiiunit\apidoc\data\api\base\Component'
295330
)
296331

297-
[42] => Array
332+
[47] => Array
298333
(
299334
[line] => 24
300335
[file] => /tests/data/api/db/ActiveQuery.php
301336
[message] => No short description for Method 'one'
302337
)
303338

304-
[43] => Array
339+
[48] => Array
305340
(
306341
[line] => 31
307342
[file] => /tests/data/api/db/ActiveQuery.php
308343
[message] => No short description for Method 'all'
309344
)
310345

311-
[44] => Array
346+
[49] => Array
312347
(
313348
[line] => 11
314349
[file] => /tests/data/api/db/ActiveQueryInterface.php
315350
[message] => No docblock for element 'yiiunit\apidoc\data\api\db\ActiveQueryInterface'
316351
)
317352

318-
[45] => Array
353+
[50] => Array
319354
(
320355
[line] => 13
321356
[file] => /tests/data/api/db/ActiveQueryInterface.php
322357
[message] => No docblock for element 'one'
323358
)
324359

325-
[46] => Array
360+
[51] => Array
326361
(
327362
[line] => 14
328363
[file] => /tests/data/api/db/ActiveQueryInterface.php
329364
[message] => No docblock for element 'all'
330365
)
331366

332-
[47] => Array
367+
[52] => Array
333368
(
334369
[line] => 11
335370
[file] => /tests/data/api/db/ActiveRecord.php
336371
[message] => No docblock for element 'yiiunit\apidoc\data\api\db\ActiveRecord'
337372
)
338373

339-
[48] => Array
374+
[53] => Array
340375
(
341376
[line] => 11
342377
[file] => /tests/data/api/db/ActiveRecordInterface.php

0 commit comments

Comments
 (0)