-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86682e4
commit 81f3299
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\NodeAnalyzer; | ||
|
||
use PhpParser\Node\Expr\BinaryOp; | ||
use PhpParser\Node\Expr\FuncCall; | ||
use Rector\Core\ValueObject\FuncCallAndExpr; | ||
use Rector\NodeNameResolver\NodeNameResolver; | ||
|
||
final class BinaryOpAnalyzer | ||
{ | ||
public function __construct( | ||
private readonly NodeNameResolver $nodeNameResolver | ||
) { | ||
} | ||
|
||
public function matchFuncCallAndOtherExpr(BinaryOp $binaryOp, string $funcCallName): ?FuncCallAndExpr | ||
{ | ||
if ($binaryOp->left instanceof FuncCall) { | ||
if (! $this->nodeNameResolver->isName($binaryOp->left, $funcCallName)) { | ||
return null; | ||
} | ||
|
||
return new FuncCallAndExpr($binaryOp->left, $binaryOp->right); | ||
} | ||
|
||
if ($binaryOp->right instanceof FuncCall) { | ||
if (! $this->nodeNameResolver->isName($binaryOp->right, $funcCallName)) { | ||
return null; | ||
} | ||
|
||
return new FuncCallAndExpr($binaryOp->right, $binaryOp->left); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\ValueObject; | ||
|
||
use PhpParser\Node\Expr; | ||
use PhpParser\Node\Expr\FuncCall; | ||
|
||
final class FuncCallAndExpr | ||
{ | ||
public function __construct( | ||
private readonly FuncCall $funcCall, | ||
private readonly Expr $expr | ||
) { | ||
} | ||
|
||
public function getFuncCall(): FuncCall | ||
{ | ||
return $this->funcCall; | ||
} | ||
|
||
public function getExpr(): Expr | ||
{ | ||
return $this->expr; | ||
} | ||
} |