Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Cache reflection filename
  • Loading branch information
lookyman committed Jan 5, 2020
commit da873540b1cdc392893a02dd5ad1c8f8a53c74bd
15 changes: 11 additions & 4 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class ClassReflection implements ReflectionWithFilename
/** @var array<string, bool> */
private $subclasses = [];

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

/**
* @param \PHPStan\Reflection\ReflectionProvider $reflectionProvider
* @param \PHPStan\Type\FileTypeMapper $fileTypeMapper
Expand Down Expand Up @@ -127,19 +130,23 @@ public function getNativeReflection(): \ReflectionClass
*/
public function getFileName()
{
if (isset($this->filename)) {
return $this->filename;
}

if ($this->anonymousFilename !== null) {
return $this->anonymousFilename;
return $this->filename = $this->anonymousFilename;
}
$fileName = $this->reflection->getFileName();
if ($fileName === false) {
return false;
return $this->filename = false;
}

if (!file_exists($fileName)) {
return false;
return $this->filename = false;
}

return $fileName;
return $this->filename = $fileName;
}

public function getFileNameWithPhpDocs(): ?string
Expand Down