From 27ca1f7b2d1e19b40cf235e1110fac8d582f7c0c Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 28 Jun 2024 17:27:29 +0200 Subject: [PATCH] Remove CurrentFileProvider from ValueResolver, let type resolver handle dir and filename (#6069) --- src/PhpParser/Node/Value/ValueResolver.php | 34 ---------------------- 1 file changed, 34 deletions(-) diff --git a/src/PhpParser/Node/Value/ValueResolver.php b/src/PhpParser/Node/Value/ValueResolver.php index 9653ff4d1cb..de2575f6f4e 100644 --- a/src/PhpParser/Node/Value/ValueResolver.php +++ b/src/PhpParser/Node/Value/ValueResolver.php @@ -12,8 +12,6 @@ use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Name; -use PhpParser\Node\Scalar\MagicConst\Dir; -use PhpParser\Node\Scalar\MagicConst\File; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\ReflectionProvider; @@ -21,7 +19,6 @@ use PHPStan\Type\ConstantScalarType; use PHPStan\Type\ConstantType; use PHPStan\Type\TypeWithClassName; -use Rector\Application\Provider\CurrentFileProvider; use Rector\Enum\ObjectReference; use Rector\Exception\ShouldNotHappenException; use Rector\NodeAnalyzer\ConstFetchAnalyzer; @@ -45,7 +42,6 @@ public function __construct( private readonly NodeTypeResolver $nodeTypeResolver, private readonly ConstFetchAnalyzer $constFetchAnalyzer, private readonly ReflectionProvider $reflectionProvider, - private readonly CurrentFileProvider $currentFileProvider, private readonly ReflectionResolver $reflectionResolver, private readonly ClassReflectionAnalyzer $classReflectionAnalyzer ) { @@ -179,16 +175,6 @@ private function getConstExprEvaluator(): ConstExprEvaluator } $this->constExprEvaluator = new ConstExprEvaluator(function (Expr $expr) { - if ($expr instanceof Dir) { - // __DIR__ - return $this->resolveDirConstant(); - } - - if ($expr instanceof File) { - // __FILE__ - return $this->resolveFileConstant($expr); - } - // resolve "SomeClass::SOME_CONST" if ($expr instanceof ClassConstFetch && $expr->class instanceof Name) { return $this->resolveClassConstFetch($expr); @@ -232,26 +218,6 @@ private function extractConstantArrayTypeValue(ConstantArrayType $constantArrayT return $values; } - private function resolveDirConstant(): string - { - $file = $this->currentFileProvider->getFile(); - if (! $file instanceof \Rector\ValueObject\Application\File) { - throw new ShouldNotHappenException(); - } - - return dirname($file->getFilePath()); - } - - private function resolveFileConstant(File $file): string - { - $file = $this->currentFileProvider->getFile(); - if (! $file instanceof \Rector\ValueObject\Application\File) { - throw new ShouldNotHappenException(); - } - - return $file->getFilePath(); - } - /** * @return string|mixed */