mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 18:00:50 +00:00
a3e534ff19
db2e76b99c
load stubs in config
59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Php81\Rector\ClassConst;
|
|
|
|
use PhpParser\Node;
|
|
use PhpParser\Node\Stmt\ClassConst;
|
|
use Rector\Core\Rector\AbstractRector;
|
|
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|
/**
|
|
* @changelog https://php.watch/versions/8.1/final-class-const
|
|
*
|
|
* @see \Rector\Tests\Php81\Rector\ClassConst\FinalizePublicClassConstantRector\FinalizePublicClassConstantRectorTest
|
|
*/
|
|
final class FinalizePublicClassConstantRector extends \Rector\Core\Rector\AbstractRector
|
|
{
|
|
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
|
{
|
|
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Add final to constants that', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
|
|
class SomeClass
|
|
{
|
|
public const NAME = 'value';
|
|
}
|
|
CODE_SAMPLE
|
|
, <<<'CODE_SAMPLE'
|
|
class SomeClass
|
|
{
|
|
public final const NAME = 'value';
|
|
}
|
|
CODE_SAMPLE
|
|
)]);
|
|
}
|
|
/**
|
|
* @return array<class-string<Node>>
|
|
*/
|
|
public function getNodeTypes() : array
|
|
{
|
|
return [\PhpParser\Node\Stmt\ClassConst::class];
|
|
}
|
|
/**
|
|
* @param ClassConst $node
|
|
*/
|
|
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
|
{
|
|
if ($node->isPrivate()) {
|
|
return null;
|
|
}
|
|
if ($node->isProtected()) {
|
|
return null;
|
|
}
|
|
if ($node->isFinal()) {
|
|
return null;
|
|
}
|
|
$this->visibilityManipulator->makeFinal($node);
|
|
return $node;
|
|
}
|
|
}
|