Skip to content

Commit

Permalink
Remove NEXT/PREV node usage from AlwaysStrictScalarExprAnalyzer (#3872)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 16, 2023
1 parent d42fd12 commit 02500aa
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 70 deletions.

This file was deleted.

8 changes: 4 additions & 4 deletions rules/Php70/NodeAnalyzer/BattleshipTernaryAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ private function evaluateGreater(Greater $greater, Ternary $ternary, ComparedExp
return $this->evaluateTernaryDesc($ternary);
}

if (!$this->nodeComparator->areNodesEqual($greater->right, $comparedExprs->getFirstExpr())) {
if (! $this->nodeComparator->areNodesEqual($greater->right, $comparedExprs->getFirstExpr())) {
return null;
}

if (!$this->nodeComparator->areNodesEqual($greater->left, $comparedExprs->getSecondExpr())) {
if (! $this->nodeComparator->areNodesEqual($greater->left, $comparedExprs->getSecondExpr())) {
return null;
}

Expand All @@ -88,11 +88,11 @@ private function evaluateSmaller(Smaller $smaller, Ternary $ternary, ComparedExp
return $this->evaluateTernaryAsc($ternary);
}

if (!$this->nodeComparator->areNodesEqual($smaller->right, $comparedExprs->getFirstExpr())) {
if (! $this->nodeComparator->areNodesEqual($smaller->right, $comparedExprs->getFirstExpr())) {
return null;
}

if (!$this->nodeComparator->areNodesEqual($smaller->left, $comparedExprs->getSecondExpr())) {
if (! $this->nodeComparator->areNodesEqual($smaller->left, $comparedExprs->getSecondExpr())) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@
namespace Rector\TypeDeclaration\TypeAnalyzer;

use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Expr\Cast;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar;
use PhpParser\Node\Scalar\DNumber;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\MagicConst;
use PhpParser\Node\Scalar\MagicConst\Line;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\Native\NativeFunctionReflection;
use PHPStan\Reflection\ReflectionProvider;
Expand All @@ -32,7 +26,6 @@
use PHPStan\Type\NullType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use Rector\Core\PhpParser\Comparing\NodeComparator;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper;
Expand All @@ -41,7 +34,6 @@ final class AlwaysStrictScalarExprAnalyzer
{
public function __construct(
private readonly ReflectionProvider $reflectionProvider,
private readonly NodeComparator $nodeComparator,
private readonly NodeTypeResolver $nodeTypeResolver
) {
}
Expand Down Expand Up @@ -77,7 +69,7 @@ public function matchStrictScalarExpr(Expr $expr): ?Type
return $this->resolveFuncCallType($expr);
}

return $this->resolveIndirectReturnType($expr);
return null;
}

private function resolveCastType(Cast $cast): ?Type
Expand All @@ -90,33 +82,6 @@ private function resolveCastType(Cast $cast): ?Type
return null;
}

private function resolveIndirectReturnType(Expr $expr): ?Type
{
if (! $expr instanceof Variable && ! $expr instanceof PropertyFetch && ! $expr instanceof StaticPropertyFetch) {
return null;
}

$parentNode = $expr->getAttribute(AttributeKey::PARENT_NODE);
if (! $parentNode instanceof Return_) {
return null;
}

$node = $parentNode->getAttribute(AttributeKey::PREVIOUS_NODE);
if (! $node instanceof Expression) {
return null;
}

if (! $node->expr instanceof Assign) {
return null;
}

if (! $this->nodeComparator->areNodesEqual($node->expr->var, $expr)) {
return null;
}

return $this->matchStrictScalarExpr($node->expr->expr);
}

private function isScalarType(Type $type): bool
{
if ($type->isString()->yes() && ! $type instanceof ConstantStringType) {
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/RectorKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class RectorKernel
/**
* @var string
*/
private const CACHE_KEY = 'v9';
private const CACHE_KEY = 'v10';

private ContainerInterface|null $container = null;

Expand Down

0 comments on commit 02500aa

Please sign in to comment.