mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-28 23:10:51 +00:00
1127b0c4e2
bc9d2d48d5
[DX] Add MissedRectorDueVersionChecker (#465)
50 lines
1.7 KiB
PHP
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;
|
|
}
|
|
}
|