diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 86d2b293fd..b9bf542f8f 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -2831,6 +2831,7 @@ public function enterClassMethod( new PhpMethodFromParserNodeReflection( $this->getClassReflection(), $classMethod, + $this->getFile(), $templateTypeMap, $this->getRealParameterTypes($classMethod), array_map(static function (Type $type): Type { @@ -2940,6 +2941,7 @@ public function enterFunction( return $this->enterFunctionLike( new PhpFunctionFromParserNodeReflection( $function, + $this->getFile(), $templateTypeMap, $this->getRealParameterTypes($function), array_map(static function (Type $type): Type { diff --git a/src/Reflection/FunctionReflection.php b/src/Reflection/FunctionReflection.php index 6520745366..5d4df99aeb 100644 --- a/src/Reflection/FunctionReflection.php +++ b/src/Reflection/FunctionReflection.php @@ -11,6 +11,8 @@ interface FunctionReflection public function getName(): string; + public function getFileName(): ?string; + /** * @return \PHPStan\Reflection\ParametersAcceptor[] */ diff --git a/src/Reflection/Native/NativeFunctionReflection.php b/src/Reflection/Native/NativeFunctionReflection.php index edda6f7c6a..6525a21173 100644 --- a/src/Reflection/Native/NativeFunctionReflection.php +++ b/src/Reflection/Native/NativeFunctionReflection.php @@ -46,6 +46,11 @@ public function getName(): string return $this->name; } + public function getFileName(): ?string + { + return null; + } + /** * @return \PHPStan\Reflection\ParametersAcceptor[] */ diff --git a/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php b/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php index a41d6eb572..9b3eaf48e2 100644 --- a/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php +++ b/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php @@ -19,6 +19,8 @@ class PhpFunctionFromParserNodeReflection implements \PHPStan\Reflection\Functio private \PhpParser\Node\FunctionLike $functionLike; + private string $fileName; + private \PHPStan\Type\Generic\TemplateTypeMap $templateTypeMap; /** @var \PHPStan\Type\Type[] */ @@ -66,6 +68,7 @@ class PhpFunctionFromParserNodeReflection implements \PHPStan\Reflection\Functio */ public function __construct( FunctionLike $functionLike, + string $fileName, TemplateTypeMap $templateTypeMap, array $realParameterTypes, array $phpDocParameterTypes, @@ -81,6 +84,7 @@ public function __construct( ) { $this->functionLike = $functionLike; + $this->fileName = $fileName; $this->templateTypeMap = $templateTypeMap; $this->realParameterTypes = $realParameterTypes; $this->phpDocParameterTypes = $phpDocParameterTypes; @@ -100,6 +104,11 @@ protected function getFunctionLike(): FunctionLike return $this->functionLike; } + public function getFileName(): string + { + return $this->fileName; + } + public function getName(): string { if ($this->functionLike instanceof ClassMethod) { diff --git a/src/Reflection/Php/PhpMethodFromParserNodeReflection.php b/src/Reflection/Php/PhpMethodFromParserNodeReflection.php index a0610af795..d1fdb0ca4f 100644 --- a/src/Reflection/Php/PhpMethodFromParserNodeReflection.php +++ b/src/Reflection/Php/PhpMethodFromParserNodeReflection.php @@ -40,6 +40,7 @@ class PhpMethodFromParserNodeReflection extends PhpFunctionFromParserNodeReflect public function __construct( ClassReflection $declaringClass, ClassMethod $classMethod, + string $fileName, TemplateTypeMap $templateTypeMap, array $realParameterTypes, array $phpDocParameterTypes, @@ -79,6 +80,7 @@ public function __construct( parent::__construct( $classMethod, + $fileName, $templateTypeMap, $realParameterTypes, $phpDocParameterTypes,