2019-10-13 05:59:52 +00:00
< ? php
2021-05-09 20:15:43 +00:00
declare ( strict_types = 1 );
2022-06-06 17:12:56 +00:00
namespace Rector\Privatization\Rector\Class_ ;
2019-04-06 22:18:23 +00:00
2022-06-06 17:12:56 +00:00
use PhpParser\Node ;
use PhpParser\Node\Stmt\Class_ ;
2024-01-02 02:40:38 +00:00
use Rector\Rector\AbstractRector ;
2022-06-07 09:18:30 +00:00
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample ;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition ;
2019-09-03 09:11:45 +00:00
/**
2024-01-31 21:40:00 +00:00
* @ deprecated This was deprecated , as its functionality caused bugs . Without knowing the full dependency tree , its very risky to use . Use https :// github . com / TomasVotruba / finalize instead as it runs with full context .
2019-09-03 09:11:45 +00:00
*/
2022-06-07 08:22:29 +00:00
final class FinalizeClassesWithoutChildrenRector extends AbstractRector
2019-04-06 22:18:23 +00:00
{
2021-04-23 19:32:59 +00:00
/**
2024-01-31 21:40:00 +00:00
* @ var bool
2021-04-23 19:32:59 +00:00
*/
2024-01-31 21:40:00 +00:00
private $hasWarned = \false ;
2022-06-07 08:22:29 +00:00
public function getRuleDefinition () : RuleDefinition
2019-04-06 22:18:23 +00:00
{
2022-06-07 08:22:29 +00:00
return new RuleDefinition ( 'Finalize every class that has no children' , [ new CodeSample ( <<< 'CODE_SAMPLE'
2024-01-02 21:38:33 +00:00
class FirstClass extends SecondClass
2019-04-06 22:18:23 +00:00
{
}
class SecondClass
{
}
2020-09-15 08:23:13 +00:00
CODE_SAMPLE
2021-05-09 20:15:43 +00:00
, <<< 'CODE_SAMPLE'
2024-01-02 21:38:33 +00:00
final class FirstClass extends SecondClass
2019-04-06 22:18:23 +00:00
{
}
class SecondClass
{
}
2020-09-15 08:23:13 +00:00
CODE_SAMPLE
2021-05-09 20:15:43 +00:00
)]);
2019-04-06 22:18:23 +00:00
}
/**
2021-02-27 00:06:15 +00:00
* @ return array < class - string < Node >>
2019-04-06 22:18:23 +00:00
*/
2021-05-09 20:15:43 +00:00
public function getNodeTypes () : array
2019-04-06 22:18:23 +00:00
{
2022-06-07 08:22:29 +00:00
return [ Class_ :: class ];
2019-04-06 22:18:23 +00:00
}
/**
2021-12-10 10:22:23 +00:00
* @ param Class_ $node
2019-04-06 22:18:23 +00:00
*/
2022-06-07 08:22:29 +00:00
public function refactor ( Node $node ) : ? Node
2019-04-06 22:18:23 +00:00
{
2024-01-31 21:40:00 +00:00
if ( $this -> hasWarned ) {
2019-04-06 22:18:23 +00:00
return null ;
}
2024-01-31 21:40:00 +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 ;
return null ;
2021-06-28 00:00:40 +00:00
}
2019-04-06 22:18:23 +00:00
}