mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit 9df1445de8c8cb5eed5a85446628226f9b03ed76
9df1445de8
[DX] Remove SimplifyForeachToArrayFilterRector as it turns typed functions to string and make code worse (#4424)
This commit is contained in:
parent
8c7b0e1592
commit
4ded5a660a
|
@ -24,7 +24,6 @@ use Rector\CodeQuality\Rector\Expression\TernaryFalseExpressionToIfRector;
|
|||
use Rector\CodeQuality\Rector\For_\ForRepeatedCountToOwnVariableRector;
|
||||
use Rector\CodeQuality\Rector\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector;
|
||||
use Rector\CodeQuality\Rector\Foreach_\ForeachToInArrayRector;
|
||||
use Rector\CodeQuality\Rector\Foreach_\SimplifyForeachToArrayFilterRector;
|
||||
use Rector\CodeQuality\Rector\Foreach_\SimplifyForeachToCoalescingRector;
|
||||
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
|
||||
use Rector\CodeQuality\Rector\FuncCall\ArrayMergeOfNonArraysToSimpleArrayRector;
|
||||
|
@ -109,5 +108,5 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
'mbstrrpos' => 'mb_strrpos',
|
||||
'mbsubstr' => 'mb_substr',
|
||||
]);
|
||||
$rectorConfig->rules([CombinedAssignRector::class, SimplifyEmptyArrayCheckRector::class, ReplaceMultipleBooleanNotRector::class, ForeachToInArrayRector::class, SimplifyForeachToCoalescingRector::class, SimplifyFuncGetArgsCountRector::class, SimplifyInArrayValuesRector::class, SimplifyStrposLowerRector::class, GetClassToInstanceOfRector::class, SimplifyArraySearchRector::class, SimplifyConditionsRector::class, SimplifyIfNotNullReturnRector::class, SimplifyIfReturnBoolRector::class, SimplifyUselessVariableRector::class, UnnecessaryTernaryExpressionRector::class, RemoveExtraParametersRector::class, SimplifyDeMorganBinaryRector::class, SimplifyTautologyTernaryRector::class, SimplifyForeachToArrayFilterRector::class, SingleInArrayToCompareRector::class, SimplifyIfElseToTernaryRector::class, JoinStringConcatRector::class, ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class, ExplicitBoolCompareRector::class, CombineIfRector::class, UseIdenticalOverEqualWithSameTypeRector::class, SimplifyBoolIdenticalTrueRector::class, SimplifyRegexPatternRector::class, BooleanNotIdenticalToNotIdenticalRector::class, StrvalToTypeCastRector::class, FloatvalToTypeCastRector::class, CallableThisArrayToAnonymousFunctionRector::class, AndAssignsToSeparateLinesRector::class, CompactToVariablesRector::class, CompleteDynamicPropertiesRector::class, IsAWithStringWithThirdArgumentRector::class, StrlenZeroToIdenticalEmptyStringRector::class, ThrowWithPreviousExceptionRector::class, RemoveSoleValueSprintfRector::class, ShortenElseIfRector::class, ArrayMergeOfNonArraysToSimpleArrayRector::class, IntvalToTypeCastRector::class, BoolvalToTypeCastRector::class, ArrayKeyExistsTernaryThenValueToCoalescingRector::class, AbsolutizeRequireAndIncludePathRector::class, ChangeArrayPushToArrayAssignRector::class, ForRepeatedCountToOwnVariableRector::class, ForeachItemsAssignToEmptyArrayToAssignRector::class, InlineIfToExplicitIfRector::class, UnusedForeachValueToArrayKeysRector::class, CommonNotEqualRector::class, SetTypeToCastRector::class, LogicalToBooleanRector::class, VarToPublicPropertyRector::class, IssetOnPropertyObjectToPropertyExistsRector::class, NewStaticToNewSelfRector::class, UnwrapSprintfOneArgumentRector::class, SwitchNegatedTernaryRector::class, SingularSwitchToIfRector::class, SimplifyIfNullableReturnRector::class, FuncGetArgsToVariadicParamRector::class, CallUserFuncToMethodCallRector::class, CallUserFuncWithArrowFunctionToInlineRector::class, CountArrayToEmptyArrayComparisonRector::class, FlipTypeControlToUseExclusiveTypeRector::class, InlineArrayReturnAssignRector::class, InlineIsAInstanceOfRector::class, TernaryFalseExpressionToIfRector::class, InlineConstructorDefaultToPropertyRector::class, ReturnTypeFromStrictScalarReturnExprRector::class, TernaryEmptyArrayArrayDimFetchToCoalesceRector::class, OptionalParametersAfterRequiredRector::class, SimplifyEmptyCheckOnEmptyArrayRector::class, SwitchTrueToIfRector::class, CleanupUnneededNullsafeOperatorRector::class, DisallowedEmptyRuleFixerRector::class, ConvertStaticPrivateConstantToSelfRector::class, LocallyCalledStaticMethodToNonStaticRector::class]);
|
||||
$rectorConfig->rules([CombinedAssignRector::class, SimplifyEmptyArrayCheckRector::class, ReplaceMultipleBooleanNotRector::class, ForeachToInArrayRector::class, SimplifyForeachToCoalescingRector::class, SimplifyFuncGetArgsCountRector::class, SimplifyInArrayValuesRector::class, SimplifyStrposLowerRector::class, GetClassToInstanceOfRector::class, SimplifyArraySearchRector::class, SimplifyConditionsRector::class, SimplifyIfNotNullReturnRector::class, SimplifyIfReturnBoolRector::class, SimplifyUselessVariableRector::class, UnnecessaryTernaryExpressionRector::class, RemoveExtraParametersRector::class, SimplifyDeMorganBinaryRector::class, SimplifyTautologyTernaryRector::class, SingleInArrayToCompareRector::class, SimplifyIfElseToTernaryRector::class, JoinStringConcatRector::class, ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class, ExplicitBoolCompareRector::class, CombineIfRector::class, UseIdenticalOverEqualWithSameTypeRector::class, SimplifyBoolIdenticalTrueRector::class, SimplifyRegexPatternRector::class, BooleanNotIdenticalToNotIdenticalRector::class, StrvalToTypeCastRector::class, FloatvalToTypeCastRector::class, CallableThisArrayToAnonymousFunctionRector::class, AndAssignsToSeparateLinesRector::class, CompactToVariablesRector::class, CompleteDynamicPropertiesRector::class, IsAWithStringWithThirdArgumentRector::class, StrlenZeroToIdenticalEmptyStringRector::class, ThrowWithPreviousExceptionRector::class, RemoveSoleValueSprintfRector::class, ShortenElseIfRector::class, ArrayMergeOfNonArraysToSimpleArrayRector::class, IntvalToTypeCastRector::class, BoolvalToTypeCastRector::class, ArrayKeyExistsTernaryThenValueToCoalescingRector::class, AbsolutizeRequireAndIncludePathRector::class, ChangeArrayPushToArrayAssignRector::class, ForRepeatedCountToOwnVariableRector::class, ForeachItemsAssignToEmptyArrayToAssignRector::class, InlineIfToExplicitIfRector::class, UnusedForeachValueToArrayKeysRector::class, CommonNotEqualRector::class, SetTypeToCastRector::class, LogicalToBooleanRector::class, VarToPublicPropertyRector::class, IssetOnPropertyObjectToPropertyExistsRector::class, NewStaticToNewSelfRector::class, UnwrapSprintfOneArgumentRector::class, SwitchNegatedTernaryRector::class, SingularSwitchToIfRector::class, SimplifyIfNullableReturnRector::class, FuncGetArgsToVariadicParamRector::class, CallUserFuncToMethodCallRector::class, CallUserFuncWithArrowFunctionToInlineRector::class, CountArrayToEmptyArrayComparisonRector::class, FlipTypeControlToUseExclusiveTypeRector::class, InlineArrayReturnAssignRector::class, InlineIsAInstanceOfRector::class, TernaryFalseExpressionToIfRector::class, InlineConstructorDefaultToPropertyRector::class, ReturnTypeFromStrictScalarReturnExprRector::class, TernaryEmptyArrayArrayDimFetchToCoalesceRector::class, OptionalParametersAfterRequiredRector::class, SimplifyEmptyCheckOnEmptyArrayRector::class, SwitchTrueToIfRector::class, CleanupUnneededNullsafeOperatorRector::class, DisallowedEmptyRuleFixerRector::class, ConvertStaticPrivateConstantToSelfRector::class, LocallyCalledStaticMethodToNonStaticRector::class]);
|
||||
};
|
||||
|
|
|
@ -255,6 +255,14 @@ final class PHPStanNodeScopeResolver
|
|||
};
|
||||
return $this->processNodesWithDependentFiles($filePath, $stmts, $scope, $nodeCallback);
|
||||
}
|
||||
public function hasUnreachableStatementNode() : bool
|
||||
{
|
||||
return $this->hasUnreachableStatementNode;
|
||||
}
|
||||
public function resetHasUnreachableStatementNode() : void
|
||||
{
|
||||
$this->hasUnreachableStatementNode = \false;
|
||||
}
|
||||
private function processCallike(CallLike $callLike, MutatingScope $mutatingScope) : void
|
||||
{
|
||||
if ($callLike instanceof StaticCall) {
|
||||
|
@ -338,14 +346,6 @@ final class PHPStanNodeScopeResolver
|
|||
$this->processNodes([$originalStmt], $filePath, $mutatingScope);
|
||||
$this->hasUnreachableStatementNode = \true;
|
||||
}
|
||||
public function hasUnreachableStatementNode() : bool
|
||||
{
|
||||
return $this->hasUnreachableStatementNode;
|
||||
}
|
||||
public function resetHasUnreachableStatementNode() : void
|
||||
{
|
||||
$this->hasUnreachableStatementNode = \false;
|
||||
}
|
||||
private function processProperty(Property $property, MutatingScope $mutatingScope) : void
|
||||
{
|
||||
foreach ($property->props as $propertyProperty) {
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\CodeQuality\NodeFactory;
|
||||
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\ArrowFunction;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\ClosureUse;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Foreach_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\Core\Php\PhpVersionProvider;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
final class ArrayFilterFactory
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Php\PhpVersionProvider
|
||||
*/
|
||||
private $phpVersionProvider;
|
||||
public function __construct(PhpVersionProvider $phpVersionProvider)
|
||||
{
|
||||
$this->phpVersionProvider = $phpVersionProvider;
|
||||
}
|
||||
public function createSimpleFuncCallAssign(Foreach_ $foreach, string $funcName, ArrayDimFetch $arrayDimFetch) : Assign
|
||||
{
|
||||
$string = new String_($funcName);
|
||||
$args = [new Arg($foreach->expr), new Arg($string)];
|
||||
$arrayFilterFuncCall = new FuncCall(new Name('array_filter'), $args);
|
||||
return new Assign($arrayDimFetch->var, $arrayFilterFuncCall);
|
||||
}
|
||||
/**
|
||||
* @param Variable[] $uses
|
||||
*/
|
||||
public function createWithClosure(ArrayDimFetch $arrayDimFetch, Variable $valueVariable, Expr $condExpr, Foreach_ $foreach, array $uses) : Assign
|
||||
{
|
||||
$filterFunction = $this->createClosure($valueVariable, $condExpr, $uses);
|
||||
$args = [new Arg($foreach->expr), new Arg($filterFunction)];
|
||||
$arrayFilterFuncCall = new FuncCall(new Name('array_filter'), $args);
|
||||
return new Assign($arrayDimFetch->var, $arrayFilterFuncCall);
|
||||
}
|
||||
/**
|
||||
* @param Variable[] $uses
|
||||
* @return \PhpParser\Node\Expr\ArrowFunction|\PhpParser\Node\Expr\Closure
|
||||
*/
|
||||
private function createClosure(Variable $valueVariable, Expr $condExpr, array $uses)
|
||||
{
|
||||
$params = [new Param($valueVariable)];
|
||||
if ($this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ARROW_FUNCTION)) {
|
||||
return new ArrowFunction(['params' => $params, 'expr' => $condExpr]);
|
||||
}
|
||||
return new Closure(['params' => $params, 'stmts' => [new Return_($condExpr)], 'uses' => \array_map(static function (Variable $variable) : ClosureUse {
|
||||
return new ClosureUse($variable);
|
||||
}, $uses)]);
|
||||
}
|
||||
}
|
|
@ -1,255 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\CodeQuality\Rector\Foreach_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Else_;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Foreach_;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\CodeQuality\NodeFactory\ArrayFilterFactory;
|
||||
use Rector\Core\Php\PhpVersionProvider;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\DeadCode\NodeAnalyzer\ExprUsedInNodeAnalyzer;
|
||||
use Rector\ReadWrite\NodeAnalyzer\ReadExprAnalyzer;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\CodeQuality\Rector\Foreach_\SimplifyForeachToArrayFilterRector\SimplifyForeachToArrayFilterRectorTest
|
||||
*/
|
||||
final class SimplifyForeachToArrayFilterRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\CodeQuality\NodeFactory\ArrayFilterFactory
|
||||
*/
|
||||
private $arrayFilterFactory;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\DeadCode\NodeAnalyzer\ExprUsedInNodeAnalyzer
|
||||
*/
|
||||
private $exprUsedInNodeAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\ReadWrite\NodeAnalyzer\ReadExprAnalyzer
|
||||
*/
|
||||
private $readExprAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Php\PhpVersionProvider
|
||||
*/
|
||||
private $phpVersionProvider;
|
||||
public function __construct(ArrayFilterFactory $arrayFilterFactory, ExprUsedInNodeAnalyzer $exprUsedInNodeAnalyzer, ReadExprAnalyzer $readExprAnalyzer, PhpVersionProvider $phpVersionProvider)
|
||||
{
|
||||
$this->arrayFilterFactory = $arrayFilterFactory;
|
||||
$this->exprUsedInNodeAnalyzer = $exprUsedInNodeAnalyzer;
|
||||
$this->readExprAnalyzer = $readExprAnalyzer;
|
||||
$this->phpVersionProvider = $phpVersionProvider;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Simplify foreach with function filtering to array filter', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
$directories = [];
|
||||
|
||||
$possibleDirectories = [];
|
||||
foreach ($possibleDirectories as $possibleDirectory) {
|
||||
if (file_exists($possibleDirectory)) {
|
||||
$directories[] = $possibleDirectory;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
$possibleDirectories = [];
|
||||
$directories = array_filter($possibleDirectories, 'file_exists');
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Foreach_::class];
|
||||
}
|
||||
/**
|
||||
* @param Foreach_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if ($this->shouldSkip($node)) {
|
||||
return null;
|
||||
}
|
||||
$foreachValueVar = $node->valueVar;
|
||||
if (!$foreachValueVar instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
/** @var If_ $ifNode */
|
||||
$ifNode = $node->stmts[0];
|
||||
$condExpr = $ifNode->cond;
|
||||
$foreachKeyVar = $node->keyVar;
|
||||
if ($foreachKeyVar instanceof Expr && $this->shouldSkipForeachKeyUsage($ifNode, $foreachKeyVar)) {
|
||||
return null;
|
||||
}
|
||||
if ($condExpr instanceof FuncCall) {
|
||||
return $this->refactorFuncCall($ifNode, $condExpr, $node, $foreachValueVar);
|
||||
}
|
||||
$onlyStmt = $ifNode->stmts[0];
|
||||
if ($onlyStmt instanceof Expression) {
|
||||
return $this->refactorAssign($onlyStmt, $foreachValueVar, $node, $condExpr);
|
||||
}
|
||||
// another condition - not supported yet
|
||||
return null;
|
||||
}
|
||||
private function shouldSkip(Foreach_ $foreach) : bool
|
||||
{
|
||||
if (\count($foreach->stmts) !== 1) {
|
||||
return \true;
|
||||
}
|
||||
if (!$foreach->stmts[0] instanceof If_) {
|
||||
return \true;
|
||||
}
|
||||
/** @var If_ $ifNode */
|
||||
$ifNode = $foreach->stmts[0];
|
||||
if ($ifNode->else instanceof Else_) {
|
||||
return \true;
|
||||
}
|
||||
if ($ifNode->elseifs !== []) {
|
||||
return \true;
|
||||
}
|
||||
$type = $this->getType($foreach->expr);
|
||||
return !$type->isArray()->yes();
|
||||
}
|
||||
private function shouldSkipForeachKeyUsage(If_ $if, Expr $expr) : bool
|
||||
{
|
||||
if (!$expr instanceof Variable) {
|
||||
return \false;
|
||||
}
|
||||
/** @var Variable[] $keyVarUsage */
|
||||
$keyVarUsage = $this->betterNodeFinder->find($if, function (Node $node) use($expr) : bool {
|
||||
return $this->exprUsedInNodeAnalyzer->isUsed($node, $expr);
|
||||
});
|
||||
$keyVarUsageCount = \count($keyVarUsage);
|
||||
if ($keyVarUsageCount === 1) {
|
||||
/** @var Variable $currentVarUsage */
|
||||
$currentVarUsage = \current($keyVarUsage);
|
||||
return !$this->readExprAnalyzer->isExprRead($currentVarUsage);
|
||||
}
|
||||
return $keyVarUsageCount !== 0;
|
||||
}
|
||||
private function isArrayDimFetchInForLoop(Foreach_ $foreach, ArrayDimFetch $arrayDimFetch) : bool
|
||||
{
|
||||
$loopVar = $foreach->expr;
|
||||
if (!$loopVar instanceof Variable) {
|
||||
return \false;
|
||||
}
|
||||
$varThatIsModified = $arrayDimFetch->var;
|
||||
if (!$varThatIsModified instanceof Variable) {
|
||||
return \false;
|
||||
}
|
||||
return $loopVar->name !== $varThatIsModified->name;
|
||||
}
|
||||
private function isSimpleFuncCallOnForeachedVariables(FuncCall $funcCall, Variable $foreachVariable) : bool
|
||||
{
|
||||
if (\count($funcCall->args) !== 1) {
|
||||
return \false;
|
||||
}
|
||||
return $this->nodeComparator->areNodesEqual($funcCall->args[0], $foreachVariable);
|
||||
}
|
||||
private function refactorFuncCall(If_ $if, FuncCall $funcCall, Foreach_ $foreach, Variable $foreachVariable) : ?Assign
|
||||
{
|
||||
if (\count($if->stmts) !== 1) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isSimpleFuncCallOnForeachedVariables($funcCall, $foreachVariable)) {
|
||||
return null;
|
||||
}
|
||||
if (!$if->stmts[0] instanceof Expression) {
|
||||
return null;
|
||||
}
|
||||
$onlyNodeInIf = $if->stmts[0]->expr;
|
||||
if (!$onlyNodeInIf instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
$arrayDimFetch = $onlyNodeInIf->var;
|
||||
if (!$arrayDimFetch instanceof ArrayDimFetch) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeComparator->areNodesEqual($onlyNodeInIf->expr, $foreachVariable)) {
|
||||
return null;
|
||||
}
|
||||
$funcName = $this->getName($funcCall);
|
||||
if ($funcName === null) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isArrayDimFetchInForLoop($foreach, $arrayDimFetch)) {
|
||||
return null;
|
||||
}
|
||||
return $this->arrayFilterFactory->createSimpleFuncCallAssign($foreach, $funcName, $arrayDimFetch);
|
||||
}
|
||||
private function refactorAssign(Expression $expression, Variable $variable, Foreach_ $foreach, Expr $condExpr) : ?Assign
|
||||
{
|
||||
if (!$expression->expr instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
$assign = $expression->expr;
|
||||
// only the array dim fetch with key is allowed
|
||||
if (!$assign->var instanceof ArrayDimFetch) {
|
||||
return null;
|
||||
}
|
||||
$arrayDimFetch = $assign->var;
|
||||
$arrayDimVariableType = $this->getType($arrayDimFetch->var);
|
||||
$arrayType = new ArrayType(new MixedType(), new MixedType());
|
||||
if ($arrayType->isSuperTypeOf($arrayDimVariableType)->no()) {
|
||||
return null;
|
||||
}
|
||||
// must be array type
|
||||
if (!$arrayDimVariableType instanceof ArrayType) {
|
||||
return null;
|
||||
}
|
||||
// two different types, probably not empty array
|
||||
if ($arrayDimVariableType->getItemType() instanceof UnionType) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeComparator->areNodesEqual($variable, $assign->expr)) {
|
||||
return null;
|
||||
}
|
||||
// the keyvar must be variable in array dim fetch
|
||||
$keyVar = $foreach->keyVar;
|
||||
if (!$keyVar instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeComparator->areNodesEqual($arrayDimFetch->dim, $foreach->keyVar)) {
|
||||
return null;
|
||||
}
|
||||
return $this->arrayFilterFactory->createWithClosure($assign->var, $variable, $condExpr, $foreach, $this->getUsedVariablesForClosure($keyVar, $variable, $condExpr));
|
||||
}
|
||||
/**
|
||||
* @return Variable[]
|
||||
*/
|
||||
private function getUsedVariablesForClosure(Variable $keyVar, Variable $valueVar, Expr $condExpr) : array
|
||||
{
|
||||
if ($this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ARROW_FUNCTION)) {
|
||||
return [];
|
||||
}
|
||||
/** @var Variable[] $filteredVariables */
|
||||
$filteredVariables = $this->betterNodeFinder->find($condExpr, function (Node $node) use($keyVar, $valueVar) : bool {
|
||||
return $node instanceof Variable && !$this->nodeComparator->areNodesEqual($keyVar, $node) && !$this->nodeComparator->areNodesEqual($valueVar, $node) && !$this->nodeNameResolver->isName($node, 'this');
|
||||
});
|
||||
$uniqueVariables = [];
|
||||
foreach ($filteredVariables as $filteredVariable) {
|
||||
$variableName = $this->nodeNameResolver->getName($filteredVariable);
|
||||
$uniqueVariables[$variableName] = $filteredVariable;
|
||||
}
|
||||
return \array_values($uniqueVariables);
|
||||
}
|
||||
}
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '14790b408cc616842ab25084c23c91cdd83559a1';
|
||||
public const PACKAGE_VERSION = '9df1445de8c8cb5eed5a85446628226f9b03ed76';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-07-05 19:29:41';
|
||||
public const RELEASE_DATE = '2023-07-05 16:27:26';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit1e258d574d17afc92dd0423ee596814b::getLoader();
|
||||
return ComposerAutoloaderInit47398a985bdc9009b693bfff9f0eb9a1::getLoader();
|
||||
|
|
|
@ -1360,7 +1360,6 @@ return array(
|
|||
'Rector\\CodeQuality\\NodeAnalyzer\\LocalPropertyAnalyzer' => $baseDir . '/rules/CodeQuality/NodeAnalyzer/LocalPropertyAnalyzer.php',
|
||||
'Rector\\CodeQuality\\NodeAnalyzer\\VariableDimFetchAssignResolver' => $baseDir . '/rules/CodeQuality/NodeAnalyzer/VariableDimFetchAssignResolver.php',
|
||||
'Rector\\CodeQuality\\NodeAnalyzer\\VariableNameUsedNextAnalyzer' => $baseDir . '/rules/CodeQuality/NodeAnalyzer/VariableNameUsedNextAnalyzer.php',
|
||||
'Rector\\CodeQuality\\NodeFactory\\ArrayFilterFactory' => $baseDir . '/rules/CodeQuality/NodeFactory/ArrayFilterFactory.php',
|
||||
'Rector\\CodeQuality\\NodeFactory\\MissingPropertiesFactory' => $baseDir . '/rules/CodeQuality/NodeFactory/MissingPropertiesFactory.php',
|
||||
'Rector\\CodeQuality\\NodeFactory\\PropertyTypeDecorator' => $baseDir . '/rules/CodeQuality/NodeFactory/PropertyTypeDecorator.php',
|
||||
'Rector\\CodeQuality\\NodeManipulator\\ExprBoolCaster' => $baseDir . '/rules/CodeQuality/NodeManipulator/ExprBoolCaster.php',
|
||||
|
@ -1385,7 +1384,6 @@ return array(
|
|||
'Rector\\CodeQuality\\Rector\\For_\\ForRepeatedCountToOwnVariableRector' => $baseDir . '/rules/CodeQuality/Rector/For_/ForRepeatedCountToOwnVariableRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\Foreach_\\ForeachItemsAssignToEmptyArrayToAssignRector' => $baseDir . '/rules/CodeQuality/Rector/Foreach_/ForeachItemsAssignToEmptyArrayToAssignRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\Foreach_\\ForeachToInArrayRector' => $baseDir . '/rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\Foreach_\\SimplifyForeachToArrayFilterRector' => $baseDir . '/rules/CodeQuality/Rector/Foreach_/SimplifyForeachToArrayFilterRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\Foreach_\\SimplifyForeachToCoalescingRector' => $baseDir . '/rules/CodeQuality/Rector/Foreach_/SimplifyForeachToCoalescingRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\Foreach_\\UnusedForeachValueToArrayKeysRector' => $baseDir . '/rules/CodeQuality/Rector/Foreach_/UnusedForeachValueToArrayKeysRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\FuncCall\\ArrayMergeOfNonArraysToSimpleArrayRector' => $baseDir . '/rules/CodeQuality/Rector/FuncCall/ArrayMergeOfNonArraysToSimpleArrayRector.php',
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit1e258d574d17afc92dd0423ee596814b
|
||||
class ComposerAutoloaderInit47398a985bdc9009b693bfff9f0eb9a1
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit1e258d574d17afc92dd0423ee596814b
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit1e258d574d17afc92dd0423ee596814b', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit47398a985bdc9009b693bfff9f0eb9a1', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit1e258d574d17afc92dd0423ee596814b', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit47398a985bdc9009b693bfff9f0eb9a1', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit1e258d574d17afc92dd0423ee596814b::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit47398a985bdc9009b693bfff9f0eb9a1::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit1e258d574d17afc92dd0423ee596814b::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit47398a985bdc9009b693bfff9f0eb9a1::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit1e258d574d17afc92dd0423ee596814b
|
||||
class ComposerStaticInit47398a985bdc9009b693bfff9f0eb9a1
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -1612,7 +1612,6 @@ class ComposerStaticInit1e258d574d17afc92dd0423ee596814b
|
|||
'Rector\\CodeQuality\\NodeAnalyzer\\LocalPropertyAnalyzer' => __DIR__ . '/../..' . '/rules/CodeQuality/NodeAnalyzer/LocalPropertyAnalyzer.php',
|
||||
'Rector\\CodeQuality\\NodeAnalyzer\\VariableDimFetchAssignResolver' => __DIR__ . '/../..' . '/rules/CodeQuality/NodeAnalyzer/VariableDimFetchAssignResolver.php',
|
||||
'Rector\\CodeQuality\\NodeAnalyzer\\VariableNameUsedNextAnalyzer' => __DIR__ . '/../..' . '/rules/CodeQuality/NodeAnalyzer/VariableNameUsedNextAnalyzer.php',
|
||||
'Rector\\CodeQuality\\NodeFactory\\ArrayFilterFactory' => __DIR__ . '/../..' . '/rules/CodeQuality/NodeFactory/ArrayFilterFactory.php',
|
||||
'Rector\\CodeQuality\\NodeFactory\\MissingPropertiesFactory' => __DIR__ . '/../..' . '/rules/CodeQuality/NodeFactory/MissingPropertiesFactory.php',
|
||||
'Rector\\CodeQuality\\NodeFactory\\PropertyTypeDecorator' => __DIR__ . '/../..' . '/rules/CodeQuality/NodeFactory/PropertyTypeDecorator.php',
|
||||
'Rector\\CodeQuality\\NodeManipulator\\ExprBoolCaster' => __DIR__ . '/../..' . '/rules/CodeQuality/NodeManipulator/ExprBoolCaster.php',
|
||||
|
@ -1637,7 +1636,6 @@ class ComposerStaticInit1e258d574d17afc92dd0423ee596814b
|
|||
'Rector\\CodeQuality\\Rector\\For_\\ForRepeatedCountToOwnVariableRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/For_/ForRepeatedCountToOwnVariableRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\Foreach_\\ForeachItemsAssignToEmptyArrayToAssignRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/Foreach_/ForeachItemsAssignToEmptyArrayToAssignRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\Foreach_\\ForeachToInArrayRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\Foreach_\\SimplifyForeachToArrayFilterRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/Foreach_/SimplifyForeachToArrayFilterRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\Foreach_\\SimplifyForeachToCoalescingRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/Foreach_/SimplifyForeachToCoalescingRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\Foreach_\\UnusedForeachValueToArrayKeysRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/Foreach_/UnusedForeachValueToArrayKeysRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\FuncCall\\ArrayMergeOfNonArraysToSimpleArrayRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/FuncCall/ArrayMergeOfNonArraysToSimpleArrayRector.php',
|
||||
|
@ -3100,9 +3098,9 @@ class ComposerStaticInit1e258d574d17afc92dd0423ee596814b
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit1e258d574d17afc92dd0423ee596814b::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit1e258d574d17afc92dd0423ee596814b::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit1e258d574d17afc92dd0423ee596814b::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit47398a985bdc9009b693bfff9f0eb9a1::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit47398a985bdc9009b693bfff9f0eb9a1::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit47398a985bdc9009b693bfff9f0eb9a1::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
|
@ -976,17 +976,17 @@
|
|||
},
|
||||
{
|
||||
"name": "phpstan\/phpstan",
|
||||
"version": "1.10.23",
|
||||
"version_normalized": "1.10.23.0",
|
||||
"version": "1.10.24",
|
||||
"version_normalized": "1.10.24.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/phpstan\/phpstan.git",
|
||||
"reference": "65ab678d1248a8bc6fde456f0d7ff3562a61a4cd"
|
||||
"reference": "360ecc90569e9a60c2954ee209ec04fa0d958e14"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpstan\/zipball\/65ab678d1248a8bc6fde456f0d7ff3562a61a4cd",
|
||||
"reference": "65ab678d1248a8bc6fde456f0d7ff3562a61a4cd",
|
||||
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpstan\/zipball\/360ecc90569e9a60c2954ee209ec04fa0d958e14",
|
||||
"reference": "360ecc90569e9a60c2954ee209ec04fa0d958e14",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -995,7 +995,7 @@
|
|||
"conflict": {
|
||||
"phpstan\/phpstan-shim": "*"
|
||||
},
|
||||
"time": "2023-07-04T13:32:44+00:00",
|
||||
"time": "2023-07-05T12:32:13+00:00",
|
||||
"bin": [
|
||||
"phpstan",
|
||||
"phpstan.phar"
|
||||
|
|
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -1,16 +1,16 @@
|
|||
-----BEGIN PGP SIGNATURE-----
|
||||
|
||||
iQIzBAABCgAdFiEEynwsejDI6OEnSoR2UcZzBf/C5cAFAmSkH2EACgkQUcZzBf/C
|
||||
5cDvQQ/+LEvYOmnhmdSrY2zeHf/6VvIGZF7pfL2XlWz5Co0QMx3CnO4jAHkFSPYm
|
||||
W6GLPkbhI+5mDaBNVwGanFvKQTtiRcy50eeAkEG9yW3BlSWY5fjmOXFBwjW9wxgN
|
||||
iz754WDM2eokWASomLsmrfOceBxA2X4imqN7g6sQptb1BKayovxmS7cZRxdffKO2
|
||||
hZ+2BCCtS+GtWEkxXODhWiIKyfq+3vdi5dUOfjRF78u8ccz3V1K9UXsRAZpUoZ4/
|
||||
1MwtkxzuD6WpdzYWGo4wosYN5prZL8rx5DD/Oj/s+HGkpeMmjQet5kK6nxjeRuMp
|
||||
rn6OlU5Q7AWARp6j6ew0D8RsRa/VeFiJRISIS8hWGvjd4V48iN64TG12SDMap9Np
|
||||
kMeghD9CX8EIDwqEeqsFIywuzr6iPhmWI5r1ovhhYQqjLLu5fHrsriQDTk/bOaKZ
|
||||
r5HPFCJtFUfRED3sszDAQTIL+s/LoOJJmt2AmL39yI5m+mqluoyEm+XigneR2fFT
|
||||
yxQvHNCiu8v0F5mtOtUhB9yJppNCOY/zkYepQmr4IAflyLLRtcegjZirfLOSDj9F
|
||||
5Xd+Ckk0yocNoR+MXRg94AwcfpG8Tucbgt6FlFtVde6dCQ9I7xFA7J0KO8voeyUB
|
||||
xPYFY5tODjb/E3UrEt+jr8Kc/LqFzQFqjlmif+TkaA9d0GCyseg=
|
||||
=xt3g
|
||||
iQIzBAABCgAdFiEEynwsejDI6OEnSoR2UcZzBf/C5cAFAmSlYrEACgkQUcZzBf/C
|
||||
5cCRthAAjDil+k8ylPKcHwPDtCro+FEFnBy5Y5ZTehg3MwNTsIhVsWyGm7Jt3giY
|
||||
M9BgGGKSa8THJ1qfSygM/OkQv9RjDkVAzUuAvUmBNW3u0zXLDi/+Q7q+bBk+Dk6+
|
||||
T2ex1t4AtiZHr6vOeSd7oXeGDjFfuvKpEf4bkaefiZzBleQgltzzmxMVJc8RPVN6
|
||||
lfqYY/FQd843zaEqhxDRMTert3tlhzX1h8GUWxg7UGDCayl69XOG+IMqYn5+5BX7
|
||||
1OzaRiRfgneD+YNYMdzrVp1muRzi3waAcE5Z9fHWYKexe4/YDlyop4g/m1SbWGcV
|
||||
MEstQnKvAEmP5BzDEYmPYBjXEwBp5ILSTkcz89EXqE2t9d/sYNzy1bUKe+DOFSff
|
||||
V+rXYh3NeKxLs5NUxT4U5A1Hc5oNqL995KGHezxlWevxlucppYMt6pWSTZmn8HxT
|
||||
VfqHk1PSfC1tNEBhS6Bo872xP0f1NseeBh2BW/pPq7Ut5jJYAImytRDBfMhmexgQ
|
||||
lUn5asMPtMgwwPHaNa+adrE7qw5qGX0s3V71FI9jc7FLOsI+aygOOr8Jah/eHY9P
|
||||
J/+vPMi9XyL+Q3uxfDADw9ObIYzgyHpr3MylPD7KokuL6e9wClHMlN0fg9J4zIic
|
||||
uT2Iut02gDbYCYIxNy5riMjoaa4Wko66qUAfZihOudOf/p8Y33o=
|
||||
=1Rj1
|
||||
-----END PGP SIGNATURE-----
|
||||
|
|
Loading…
Reference in New Issue