rector/rules/Php73/Rector/FuncCall/SensitiveDefineRector.php

56 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2019-10-13 05:59:52 +00:00
<?php
declare (strict_types=1);
namespace Rector\Php73\Rector\FuncCall;
2018-10-12 05:03:37 +00:00
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
2018-10-12 05:03:37 +00:00
/**
2021-04-10 18:47:17 +00:00
* @changelog https://wiki.php.net/rfc/case_insensitive_constant_deprecation
*
* @see \Rector\Tests\Php73\Rector\FuncCall\SensitiveDefineRector\SensitiveDefineRectorTest
2018-10-12 05:03:37 +00:00
*/
final class SensitiveDefineRector extends AbstractRector implements MinPhpVersionInterface
2018-10-12 05:03:37 +00:00
{
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::DEPRECATE_INSENSITIVE_CONSTANT_DEFINE;
}
public function getRuleDefinition() : RuleDefinition
2018-10-12 05:03:37 +00:00
{
return new RuleDefinition('Changes case insensitive constants to sensitive ones.', [new CodeSample(<<<'CODE_SAMPLE'
define('FOO', 42, true);
CODE_SAMPLE
, <<<'CODE_SAMPLE'
define('FOO', 42);
CODE_SAMPLE
)]);
2018-10-12 05:03:37 +00:00
}
/**
* @return array<class-string<Node>>
2018-10-12 05:03:37 +00:00
*/
public function getNodeTypes() : array
2018-10-12 05:03:37 +00:00
{
return [FuncCall::class];
2018-10-12 05:03:37 +00:00
}
/**
* @param FuncCall $node
2018-10-12 05:03:37 +00:00
*/
public function refactor(Node $node) : ?Node
2018-10-12 05:03:37 +00:00
{
if (!$this->isName($node, 'define')) {
return null;
2018-10-12 05:03:37 +00:00
}
if (!isset($node->args[2])) {
return null;
2018-10-12 05:03:37 +00:00
}
unset($node->args[2]);
return $node;
2018-10-12 05:03:37 +00:00
}
}