Skip to content

Commit edb696e

Browse files
committed
Revert "Further optimize FileTypeMapper"
This reverts commit 4ff0a4c.
1 parent d18dbc2 commit edb696e

2 files changed

Lines changed: 15 additions & 60 deletions

File tree

src/PhpDoc/FileTypeMapperPhpDocNodeMap.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/Type/FileTypeMapper.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPStan\Broker\AnonymousClassNameHelper;
1010
use PHPStan\File\FileHelper;
1111
use PHPStan\Parser\Parser;
12-
use PHPStan\PhpDoc\FileTypeMapperPhpDocNodeMap;
1312
use PHPStan\PhpDoc\PhpDocNodeResolver;
1413
use PHPStan\PhpDoc\PhpDocStringResolver;
1514
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
@@ -215,10 +214,11 @@ private function createResolvedPhpDocMap(string $fileName): array
215214

216215
/**
217216
* @param array<string, string> $traitMethodAliases
217+
* @return array<string, PhpDocNode>
218218
*/
219-
private function createPhpDocNodeMap(string $fileName, ?string $lookForTrait, ?string $traitUseClass, array $traitMethodAliases, string $originalClassFileName): FileTypeMapperPhpDocNodeMap
219+
private function createPhpDocNodeMap(string $fileName, ?string $lookForTrait, ?string $traitUseClass, array $traitMethodAliases, string $originalClassFileName): array
220220
{
221-
/** @var array<string, callable(): PhpDocNode> $phpDocNodeMap */
221+
/** @var array<string, PhpDocNode> $phpDocNodeMap */
222222
$phpDocNodeMap = [];
223223

224224
/** @var string[] $classStack */
@@ -285,7 +285,7 @@ function (Node $node) use ($fileName, $lookForTrait, &$traitFound, $traitMethodA
285285
$docComment = GetLastDocComment::forNode($node);
286286
if ($docComment !== null) {
287287
$nameScopeKey = $this->getNameScopeKey($originalClassFileName, $className, $lookForTrait, $functionName);
288-
$phpDocNodeMap[$nameScopeKey] = fn (): PhpDocNode => $this->phpDocStringResolver->resolve($docComment);
288+
$phpDocNodeMap[$nameScopeKey] = $this->phpDocStringResolver->resolve($docComment);
289289
}
290290

291291
return null;
@@ -347,7 +347,7 @@ function (Node $node) use ($fileName, $lookForTrait, &$traitFound, $traitMethodA
347347
$className,
348348
$traitMethodAliases[$traitName] ?? [],
349349
$originalClassFileName,
350-
)->getMap());
350+
));
351351
}
352352
}
353353

@@ -377,11 +377,12 @@ static function (Node $node) use (&$namespace, &$functionStack, &$classStack): v
377377
},
378378
);
379379

380-
return new FileTypeMapperPhpDocNodeMap($phpDocNodeMap);
380+
return $phpDocNodeMap;
381381
}
382382

383383
/**
384384
* @param array<string, string> $traitMethodAliases
385+
* @param array<string, PhpDocNode> $phpDocNodeMap
385386
* @return (callable(): NameScope)[]
386387
*/
387388
private function createNameScopeMap(
@@ -390,7 +391,7 @@ private function createNameScopeMap(
390391
?string $traitUseClass,
391392
array $traitMethodAliases,
392393
string $originalClassFileName,
393-
FileTypeMapperPhpDocNodeMap $phpDocNodeMap,
394+
array $phpDocNodeMap,
394395
): array
395396
{
396397
/** @var (callable(): NameScope)[] $nameScopeMap */
@@ -434,8 +435,8 @@ function (Node $node) use ($fileName, $lookForTrait, $phpDocNodeMap, &$traitFoun
434435

435436
$traitFound = true;
436437
$traitNameScopeKey = $this->getNameScopeKey($originalClassFileName, $classStack[count($classStack) - 1] ?? null, $lookForTrait, null);
437-
if ($phpDocNodeMap->has($traitNameScopeKey)) {
438-
$typeAliasStack[] = $this->getTypeAliasesMap($phpDocNodeMap->get($traitNameScopeKey));
438+
if (array_key_exists($traitNameScopeKey, $phpDocNodeMap)) {
439+
$typeAliasStack[] = $this->getTypeAliasesMap($phpDocNodeMap[$traitNameScopeKey]);
439440
} else {
440441
$typeAliasStack[] = [];
441442
}
@@ -457,8 +458,8 @@ function (Node $node) use ($fileName, $lookForTrait, $phpDocNodeMap, &$traitFoun
457458
}
458459
$classStack[] = $className;
459460
$classNameScopeKey = $this->getNameScopeKey($originalClassFileName, $className, $lookForTrait, null);
460-
if ($phpDocNodeMap->has($classNameScopeKey)) {
461-
$typeAliasStack[] = $this->getTypeAliasesMap($phpDocNodeMap->get($classNameScopeKey));
461+
if (array_key_exists($classNameScopeKey, $phpDocNodeMap)) {
462+
$typeAliasStack[] = $this->getTypeAliasesMap($phpDocNodeMap[$classNameScopeKey]);
462463
} else {
463464
$typeAliasStack[] = [];
464465
}
@@ -479,8 +480,8 @@ function (Node $node) use ($fileName, $lookForTrait, $phpDocNodeMap, &$traitFoun
479480
$nameScopeKey = $this->getNameScopeKey($originalClassFileName, $className, $lookForTrait, $functionName);
480481

481482
if ($node instanceof Node\Stmt\ClassLike || $node instanceof Node\Stmt\ClassMethod || $node instanceof Node\Stmt\Function_) {
482-
if ($phpDocNodeMap->has($nameScopeKey)) {
483-
$phpDocNode = $phpDocNodeMap->get($nameScopeKey);
483+
if (array_key_exists($nameScopeKey, $phpDocNodeMap)) {
484+
$phpDocNode = $phpDocNodeMap[$nameScopeKey];
484485
$typeMapStack[] = function () use ($namespace, $uses, $className, $lookForTrait, $functionName, $phpDocNode, $typeMapStack, $typeAliasStack, $constUses): TemplateTypeMap {
485486
$typeMapCb = $typeMapStack[count($typeMapStack) - 1] ?? null;
486487
$currentTypeMap = $typeMapCb !== null ? $typeMapCb() : null;
@@ -535,7 +536,7 @@ function (Node $node) use ($fileName, $lookForTrait, $phpDocNodeMap, &$traitFoun
535536
}
536537

537538
if ($node instanceof Node\Stmt\ClassLike || $node instanceof Node\Stmt\ClassMethod || $node instanceof Node\Stmt\Function_) {
538-
if ($phpDocNodeMap->has($nameScopeKey)) {
539+
if (array_key_exists($nameScopeKey, $phpDocNodeMap)) {
539540
return self::POP_TYPE_MAP_STACK;
540541
}
541542

0 commit comments

Comments
 (0)