rector/rules/Php56/Rector/FuncCall/PowToExpRector.php
Tomas Votruba 1127b0c4e2 Updated Rector to commit bc9d2d48d5
bc9d2d48d5 [DX] Add MissedRectorDueVersionChecker (#465)
2021-07-21 09:35:57 +00:00

50 lines
1.7 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\Php56\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp\Pow;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\Php56\Rector\FuncCall\PowToExpRector\PowToExpRectorTest
*/
final class PowToExpRector extends \Rector\Core\Rector\AbstractRector implements \Rector\VersionBonding\Contract\MinPhpVersionInterface
{
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Changes pow(val, val2) to ** (exp) parameter', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample('pow(1, 2);', '1**2;')]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Expr\FuncCall::class];
}
/**
* @param FuncCall $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
if (!$this->isName($node, 'pow')) {
return null;
}
if (\count($node->args) !== 2) {
return null;
}
$firstArgument = $node->args[0]->value;
$secondArgument = $node->args[1]->value;
return new \PhpParser\Node\Expr\BinaryOp\Pow($firstArgument, $secondArgument);
}
public function provideMinPhpVersion() : int
{
return \Rector\Core\ValueObject\PhpVersionFeature::EXP_OPERATOR;
}
}