Skip to content

Commit

Permalink
[TypeDeclaration] Add Closure support on StrictStringParamConcatRector (
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Aug 3, 2023
1 parent 5965ddd commit 90f8714
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\StrictStringParamConcatRector\Fixture;

final class WithInnerClosure
{
public function resolve($item)
{
$result = $item * 100;

function ($item) {
return $item . ' world';
};

return $result;
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\StrictStringParamConcatRector\Fixture;

final class WithInnerClosure
{
public function resolve($item)
{
$result = $item * 100;

function (string $item) {
return $item . ' world';
};

return $result;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\AssignOp\Concat;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Identifier;
Expand Down Expand Up @@ -62,11 +63,11 @@ public function resolve(string $item)
*/
public function getNodeTypes(): array
{
return [ClassMethod::class, Function_::class];
return [ClassMethod::class, Function_::class, Closure::class];
}

/**
* @param ClassMethod|Function_ $node
* @param ClassMethod|Function_|Closure $node
*/
public function refactor(Node $node): ?Node
{
Expand Down Expand Up @@ -96,7 +97,7 @@ public function refactor(Node $node): ?Node
return null;
}

private function isParamConcatted(Param $param, ClassMethod|Function_ $functionLike): bool
private function isParamConcatted(Param $param, ClassMethod|Function_|Closure $functionLike): bool
{
if ($functionLike->stmts === null) {
return false;
Expand Down

0 comments on commit 90f8714

Please sign in to comment.