Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Reflection/ClassReflection.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,6 +89,9 @@ class ClassReflection implements ReflectionWithFilename
/** @var string|false|null */
private $filename;

/** @var string|false|null */
private $reflectionDocComment;

/**
* @param \PHPStan\Reflection\ReflectionProvider $reflectionProvider
* @param \PHPStan\Type\FileTypeMapper $fileTypeMapper
Expand DownExpand Up@@ -933,12 +936,15 @@ public function getResolvedPhpDoc(): ?ResolvedPhpDocBlock
return null;
}

$docComment = $this->reflection->getDocComment();
if ($docComment === false) {
if ($this->reflectionDocComment === null) {
$this->reflectionDocComment = $this->reflection->getDocComment();
}

if ($this->reflectionDocComment === false) {
return null;
}

return $this->fileTypeMapper->getResolvedPhpDoc($fileName, $this->getName(), null, null, $docComment);
return $this->fileTypeMapper->getResolvedPhpDoc($fileName, $this->getName(), null, null, $this->reflectionDocComment);
}

private function getFirstExtendsTag(): ?ExtendsTag
Expand Down
9 changes: 8 additions & 1 deletion src/Type/FileTypeMapper.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,6 +53,9 @@ class FileTypeMapper
/** @var array<string, bool> */
private array $alreadyProcessedDependentFiles = [];

/** @var array<string, string> */
private array $docKeys = [];

public function __construct(
ReflectionProviderProvider $reflectionProviderProvider,
Parser $phpParser,
Expand DownExpand Up@@ -518,7 +521,11 @@ private function getPhpDocKey(
string $docComment
): string
{
$docComment = \Nette\Utils\Strings::replace($docComment, '#\s+#', ' ');
$cacheKey = md5($docComment);
if (!isset($this->docKeys[$cacheKey])) {
$this->docKeys[$cacheKey] = \Nette\Utils\Strings::replace($docComment, '#\s+#', ' ');
}
$docComment = $this->docKeys[$cacheKey];

return md5(sprintf('%s-%s-%s-%s', $class, $trait, $function, $docComment));
}
Expand Down