2021-07-22 23:37:17 +00:00
< ? php
declare ( strict_types = 1 );
2022-06-06 17:12:56 +00:00
namespace Rector\Php81\Rector\ClassConst ;
2021-07-22 23:37:17 +00:00
2022-06-06 17:12:56 +00:00
use PhpParser\Node ;
use PhpParser\Node\Stmt\Class_ ;
2024-01-31 14:27:18 +00:00
use Rector\Rector\AbstractRector ;
2024-01-02 02:40:38 +00:00
use Rector\ValueObject\PhpVersionFeature ;
2022-06-06 17:12:56 +00:00
use Rector\VersionBonding\Contract\MinPhpVersionInterface ;
2022-06-07 09:18:30 +00:00
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample ;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition ;
2021-07-22 23:37:17 +00:00
/**
2024-01-31 14:27:18 +00:00
* @ deprecated This was deprecated , as its functionality caused bugs . Without knowing the full dependency tree , its risky to change
2021-07-22 23:37:17 +00:00
*/
2024-01-31 14:27:18 +00:00
final class FinalizePublicClassConstantRector extends AbstractRector implements MinPhpVersionInterface
2021-07-22 23:37:17 +00:00
{
2022-01-28 11:05:27 +00:00
/**
2024-01-31 14:27:18 +00:00
* @ var bool
2022-01-28 11:05:27 +00:00
*/
2024-01-31 14:27:18 +00:00
private $hasWarned = \false ;
2022-06-07 08:22:29 +00:00
public function getRuleDefinition () : RuleDefinition
2021-07-22 23:37:17 +00:00
{
2022-06-07 08:22:29 +00:00
return new RuleDefinition ( 'Add final to constants that does not have children' , [ new CodeSample ( <<< 'CODE_SAMPLE'
2021-07-22 23:37:17 +00:00
class SomeClass
{
public const NAME = 'value' ;
}
CODE_SAMPLE
, <<< 'CODE_SAMPLE'
class SomeClass
{
2022-05-18 10:48:11 +00:00
final public const NAME = 'value' ;
2021-07-22 23:37:17 +00:00
}
CODE_SAMPLE
)]);
}
/**
* @ return array < class - string < Node >>
*/
public function getNodeTypes () : array
{
2023-06-09 16:23:18 +00:00
return [ Class_ :: class ];
2021-07-22 23:37:17 +00:00
}
/**
2023-06-09 16:23:18 +00:00
* @ param Class_ $node
2021-07-22 23:37:17 +00:00
*/
2024-01-31 14:27:18 +00:00
public function refactor ( Node $node ) : ? Node
2021-07-22 23:37:17 +00:00
{
2024-01-31 14:27:18 +00:00
if ( $this -> hasWarned ) {
2021-07-22 23:37:17 +00:00
return null ;
}
2024-01-31 14:27:18 +00:00
\trigger_error ( \sprintf ( 'The "%s" rule was deprecated, as its functionality caused bugs. Without knowing the full dependency tree, its risky to change.' , self :: class ));
\sleep ( 3 );
$this -> hasWarned = \true ;
2023-06-09 16:23:18 +00:00
return null ;
2021-07-22 23:37:17 +00:00
}
2021-09-02 15:24:03 +00:00
public function provideMinPhpVersion () : int
{
2022-06-07 08:22:29 +00:00
return PhpVersionFeature :: FINAL_CLASS_CONSTANTS ;
2021-09-02 15:24:03 +00:00
}
2021-07-22 23:37:17 +00:00
}