Skip to content

Commit

Permalink
[ci-review] Rector Rectify
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizen-ci committed Mar 1, 2021
1 parent 00e90cb commit 24ccbed
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion rules/naming/src/Matcher/ForeachMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Naming\Matcher;

use Closure;
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
Expand Down Expand Up @@ -44,7 +45,7 @@ public function match(Foreach_ $foreach): ?VariableAndCallForeach
}

$functionLike = $this->getFunctionLike($foreach);
if ($functionLike === null) {
if (! $functionLike instanceof FunctionLike) {
return null;
}

Expand Down
5 changes: 3 additions & 2 deletions rules/naming/src/Matcher/VariableAndCallAssignMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Naming\Matcher;

use Closure;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Variable;
Expand Down Expand Up @@ -32,7 +33,7 @@ public function __construct(CallMatcher $callMatcher, NodeNameResolver $nodeName
$this->nodeNameResolver = $nodeNameResolver;
}

public function match(Assign $assign)
public function match(Assign $assign): ?VariableAndCallAssign
{
$call = $this->callMatcher->matchCall($assign);
if ($call === null) {
Expand All @@ -49,7 +50,7 @@ public function match(Assign $assign)
}

$functionLike = $this->getFunctionLike($assign);
if ($functionLike === null) {
if (! $functionLike instanceof FunctionLike) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,25 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$variableAndCallAssign = $this->varValueAndCallForeachMatcher->match($node);
$variableAndCallForeach = $this->varValueAndCallForeachMatcher->match($node);

if (! $variableAndCallAssign instanceof VariableAndCallForeach) {
if (! $variableAndCallForeach instanceof VariableAndCallForeach) {
return null;
}

$expectedName = $this->expectedNameResolver->resolveForForeach($variableAndCallAssign->getCall());
$expectedName = $this->expectedNameResolver->resolveForForeach($variableAndCallForeach->getCall());
if ($expectedName === null) {
return null;
}
if ($this->isName($variableAndCallAssign->getVariable(), $expectedName)) {
if ($this->isName($variableAndCallForeach->getVariable(), $expectedName)) {
return null;
}

if ($this->shouldSkip($variableAndCallAssign, $expectedName)) {
if ($this->shouldSkip($variableAndCallForeach, $expectedName)) {
return null;
}

$this->renameVariable($variableAndCallAssign, $expectedName);
$this->renameVariable($variableAndCallForeach, $expectedName);

return $node;
}
Expand Down

0 comments on commit 24ccbed

Please sign in to comment.