Skip to content

Commit

Permalink
Remove CurrentFileProvider from ValueResolver, let type resolver hand…
Browse files Browse the repository at this point in the history
…le dir and filename (#6069)
  • Loading branch information
TomasVotruba authored Jun 28, 2024
1 parent a77b00d commit 27ca1f7
Showing 1 changed file with 0 additions and 34 deletions.
34 changes: 0 additions & 34 deletions src/PhpParser/Node/Value/ValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@
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;
use PHPStan\Type\Constant\ConstantArrayType;
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;
Expand All @@ -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
) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 27ca1f7

Please sign in to comment.