Skip to content

Commit

Permalink
[dx] remove direct assigns (#2617)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jul 3, 2022
1 parent 0660b21 commit b45066c
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 36 deletions.
3 changes: 1 addition & 2 deletions rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php
Expand Up @@ -277,8 +277,7 @@ private function addClassMethodParam(

$param = new Param(new Variable($argumentName), BuilderHelpers::normalizeValue($defaultValue));
if ($type !== null) {
$typeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::PARAM);
$param->type = $typeNode;
$param->type = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::PARAM);
}

$classMethod->params[$position] = $param;
Expand Down
3 changes: 1 addition & 2 deletions rules/CodeQuality/NodeAnalyzer/LocalPropertyAnalyzer.php
Expand Up @@ -85,8 +85,7 @@ public function resolveFetchedPropertiesToTypesFromClass(Class_ $class): array
return null;
}

$propertyFetchType = $this->resolvePropertyFetchType($node);
$fetchedLocalPropertyNameToTypes[$propertyName][] = $propertyFetchType;
$fetchedLocalPropertyNameToTypes[$propertyName][] = $this->resolvePropertyFetchType($node);

return null;
});
Expand Down
Expand Up @@ -99,13 +99,11 @@ private function refactorClassMethod(ClassMethod $classMethod): ?ClassMethod
return null;
}

$newParams = $this->argumentSorter->sortArgsByExpectedParamOrder(
$classMethod->params = $this->argumentSorter->sortArgsByExpectedParamOrder(
$classMethod->params,
$expectedArgOrParamOrder
);

$classMethod->params = $newParams;

return $classMethod;
}

Expand Down
1 change: 1 addition & 0 deletions rules/CodeQuality/Rector/For_/ForToForeachRector.php
Expand Up @@ -147,6 +147,7 @@ private function processForToForeach(For_ $for, string $iteratedVariable): ?Fore
{
$originalVariableSingle = $this->inflector->singularize($iteratedVariable);
$iteratedVariableSingle = $originalVariableSingle;

if ($iteratedVariableSingle === $iteratedVariable) {
$iteratedVariableSingle = 'single' . ucfirst($iteratedVariableSingle);
}
Expand Down
3 changes: 1 addition & 2 deletions rules/CodingStyle/ClassNameImport/ShortNameResolver.php
Expand Up @@ -138,8 +138,7 @@ private function resolveForStmts(array $stmts): array
return null;
}

$fullyQualifiedName = $this->nodeNameResolver->getName($node);
$shortNamesToFullyQualifiedNames[$originalName->toString()] = $fullyQualifiedName;
$shortNamesToFullyQualifiedNames[$originalName->toString()] = $this->nodeNameResolver->getName($node);

return null;
});
Expand Down
Expand Up @@ -180,8 +180,7 @@ private function createConstructParams(array $requiredPropertiesWithPhpDocInfos)
$propertyType = $propertyType->type;
}

$param = new Param(new Variable($propertyName), null, $propertyType, false, false, [], $property->flags);
$params[] = $param;
$params[] = new Param(new Variable($propertyName), null, $propertyType, false, false, [], $property->flags);

$propertyPhpDocInfo = $requiredPropertyWithPhpDocInfo->getPhpDocInfo();

Expand Down
3 changes: 1 addition & 2 deletions rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php
Expand Up @@ -73,8 +73,7 @@ public function refactor(Node $node)
return null;
}

$firstExpr = array_shift($livingCode);
$node->expr = $firstExpr;
$node->expr = array_shift($livingCode);

$newNodes = [];
foreach ($livingCode as $singleLivingCode) {
Expand Down
Expand Up @@ -128,11 +128,11 @@ public function refactor(Node $node): ?Node
if (! $nextStmt instanceof Return_) {
$afterStmts[] = $stmt->stmts[0];

$newStmts = array_merge(
$node->stmts = array_merge(
$newStmts,
$this->processReplaceIfs($stmt, $booleanAndConditions, new Return_(), $afterStmts)
);
$node->stmts = $newStmts;

return $node;
}

Expand All @@ -150,10 +150,9 @@ public function refactor(Node $node): ?Node
}

$changedStmts = $this->processReplaceIfs($stmt, $booleanAndConditions, $ifNextReturnClone, $afterStmts);
$changedStmts = array_merge($newStmts, $changedStmts);

// update stmts
$node->stmts = $changedStmts;
$node->stmts = array_merge($newStmts, $changedStmts);

return $node;
}
Expand Down
3 changes: 1 addition & 2 deletions rules/Php72/NodeManipulator/ClosureNestedUsesDecorator.php
Expand Up @@ -45,8 +45,7 @@ public function applyNestedUses(Closure $anonymousFunctionNode, Variable $useVar
}

$uses = array_merge($parent->uses, $uses);
$uses = $this->cleanClosureUses($uses);
$parent->uses = $uses;
$parent->uses = $this->cleanClosureUses($uses);

$parent = $this->betterNodeFinder->findParentType($parent, Closure::class);
}
Expand Down
Expand Up @@ -138,8 +138,8 @@ public function refactor(Node $node): ?Node
}

// property name has higher priority
$propertyName = $this->getName($property);
$param->var->name = $propertyName;
$param->var->name = $this->getName($property);

$param->flags = $property->flags;
// Copy over attributes of the "old" property
$param->attrGroups = $property->attrGroups;
Expand Down
Expand Up @@ -67,8 +67,7 @@ public function collectPropertyFetchByMethods(Class_ $class, array $propertyName
continue;
}

$classMethodName = $this->nodeNameResolver->getName($classMethod);
$propertyUsageByMethods[$propertyName][] = $classMethodName;
$propertyUsageByMethods[$propertyName][] = $this->nodeNameResolver->getName($classMethod);
}
}

Expand Down
Expand Up @@ -131,8 +131,7 @@ private function hasNeededAttributeAlready(Class_ $class): bool

private function addAllowDynamicPropertiesAttribute(Class_ $class): Class_
{
$attributeGroup = $this->phpAttributeGroupFactory->createFromClass(self::ATTRIBUTE);
$class->attrGroups[] = $attributeGroup;
$class->attrGroups[] = $this->phpAttributeGroupFactory->createFromClass(self::ATTRIBUTE);

return $class;
}
Expand Down
9 changes: 4 additions & 5 deletions rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php
Expand Up @@ -44,9 +44,7 @@ public function resolveStrictTypesFromCalls(array $calls): array
continue;
}

$argValueType = $this->resolveStrictArgValueType($arg);

$staticTypesByArgumentPosition[$position][] = $argValueType;
$staticTypesByArgumentPosition[$position][] = $this->resolveStrictArgValueType($arg);
}
}

Expand Down Expand Up @@ -82,9 +80,10 @@ private function unionToSingleType(array $staticTypesByArgumentPosition): array
$unionedType = $this->typeFactory->createMixedPassedOrUnionType($staticTypes);

// narrow parents to most child type
$unionedType = $this->narrowParentObjectTreeToSingleObjectChildType($unionedType);

$staticTypeByArgumentPosition[$position] = $unionedType;
$staticTypeByArgumentPosition[$position] = $this->narrowParentObjectTreeToSingleObjectChildType(
$unionedType
);
}

if (count($staticTypeByArgumentPosition) !== 1) {
Expand Down
Expand Up @@ -146,8 +146,7 @@ private function processClassMethodNodeWithTypehints(
return;
}

$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($newType, TypeKind::RETURN);
$classMethod->returnType = $returnTypeNode;
$classMethod->returnType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($newType, TypeKind::RETURN);

$this->hasChanged = true;
}
Expand Down
Expand Up @@ -110,8 +110,7 @@ public function refactor(Node $node): ?Node
}

$returnType = $this->typeFactory->createMixedPassedOrUnionType($newTypes);
$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($returnType, TypeKind::RETURN);
$node->returnType = $returnTypeNode;
$node->returnType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($returnType, TypeKind::RETURN);

return $node;
}
Expand Down
Expand Up @@ -134,8 +134,8 @@ public function refactor(Node $node): ?Node
if ($this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::UNION_TYPES)) {
/** @var PhpParserUnionType[] $returnedStrictTypes */
$unwrappedTypes = $this->typeNodeUnwrapper->unwrapNullableUnionTypes($returnedStrictTypes);
$returnType = new PhpParserUnionType($unwrappedTypes);
$node->returnType = $returnType;
$node->returnType = new PhpParserUnionType($unwrappedTypes);

return $node;
}

Expand Down

0 comments on commit b45066c

Please sign in to comment.