Skip to content

Commit

Permalink
Tiny static fixes (#4543)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jul 19, 2023
1 parent a0af8a1 commit 8cd0044
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
9 changes: 1 addition & 8 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ parameters:
- '#Cognitive complexity for "Rector\\Core\\PhpParser\\Node\\Value\\ValueResolver\:\:getValue\(\)" is \d+, keep it under 11#'
- '#Cognitive complexity for "Rector\\DeadCode\\NodeManipulator\\LivingCodeManipulator\:\:keepLivingCodeFromExpr\(\)" is \d+, keep it under 11#'

# known value
- '#Property PhpParser\\Node\\Stmt\\Foreach_\:\:\$valueVar \(PhpParser\\Node\\Expr\) does not accept PhpParser\\Node\\Expr\|null#'

# is nested expr
-
message: '#Access to an undefined property PhpParser\\Node\\Expr\:\:\$expr#'
Expand All @@ -88,6 +85,7 @@ parameters:
- rules/Php56/NodeAnalyzer/UndefinedVariableResolver.php
- rules/Php70/EregToPcreTransformer.php

# lack of generic array in nikic/php-parser
- '#Method (.*?) should return array<PhpParser\\Node\\(.*?)\> but returns array<PhpParser\\Node\>#'

-
Expand Down Expand Up @@ -356,11 +354,6 @@ parameters:
message: '#@\\ini_set\(.*\)" is forbidden to use#'
path: bin/rector.php

# should be fixed in symplify next
-
message: '#New objects with "\$arrayItem" name are overridden\. This can lead to unwanted bugs, please pick a different name to avoid it#'
path: src/PhpParser/Node/NodeFactory.php

# faking node to invoke scope callable on attribute
-
message: '#New objects with "\$node" name are overridden\. This can lead to unwanted bugs, please pick a different name to avoid it#'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Rector\CodeQuality\Rector\Class_;

use PhpParser\Node\Expr;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Stmt\Class_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function refactor(Node $node): ?Node
return null;
}

$this->removeForeachValueAndUseArrayKeys($node);
$this->removeForeachValueAndUseArrayKeys($node, $node->keyVar);

return $node;
}
Expand Down Expand Up @@ -170,10 +170,10 @@ private function isVariableUsedInForeach(Variable $variable, Foreach_ $foreach):
);
}

private function removeForeachValueAndUseArrayKeys(Foreach_ $foreach): void
private function removeForeachValueAndUseArrayKeys(Foreach_ $foreach, Expr $keyVarExpr): void
{
// remove key value
$foreach->valueVar = $foreach->keyVar;
$foreach->valueVar = $keyVarExpr;
$foreach->keyVar = null;

$foreach->expr = $this->nodeFactory->createFuncCall('array_keys', [$foreach->expr]);
Expand Down
8 changes: 2 additions & 6 deletions src/PhpParser/Node/NodeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,10 @@ private function createArrayItem(mixed $item, string | int | null $key = null):
$arrayItem = new ArrayItem($itemValue);
} elseif (is_array($item)) {
$arrayItem = new ArrayItem($this->createArray($item));
}

if ($item === null || $item instanceof ClassConstFetch) {
} elseif ($item === null || $item instanceof ClassConstFetch) {
$itemValue = BuilderHelpers::normalizeValue($item);
$arrayItem = new ArrayItem($itemValue);
}

if ($item instanceof Arg) {
} elseif ($item instanceof Arg) {
$arrayItem = new ArrayItem($item->value);
}

Expand Down

0 comments on commit 8cd0044

Please sign in to comment.