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\Php52\Rector\Property;
|
2019-02-19 07:22:45 +00:00
|
|
|
|
2022-06-06 17:12:56 +00:00
|
|
|
use PhpParser\Node;
|
|
|
|
use PhpParser\Node\Stmt\Property;
|
|
|
|
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
|
2024-01-02 02:40:38 +00:00
|
|
|
use Rector\Rector\AbstractRector;
|
|
|
|
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;
|
2019-09-03 09:11:45 +00:00
|
|
|
/**
|
2021-03-12 22:20:25 +00:00
|
|
|
* @see \Rector\Tests\Php52\Rector\Property\VarToPublicPropertyRector\VarToPublicPropertyRectorTest
|
2019-09-03 09:11:45 +00:00
|
|
|
*/
|
2022-06-07 08:22:29 +00:00
|
|
|
final class VarToPublicPropertyRector extends AbstractRector implements MinPhpVersionInterface
|
2019-02-19 07:22:45 +00:00
|
|
|
{
|
2021-11-24 11:00:16 +00:00
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2021-11-24 11:00:16 +00:00
|
|
|
* @var \Rector\Privatization\NodeManipulator\VisibilityManipulator
|
|
|
|
*/
|
|
|
|
private $visibilityManipulator;
|
2022-06-07 08:22:29 +00:00
|
|
|
public function __construct(VisibilityManipulator $visibilityManipulator)
|
2021-11-24 11:00:16 +00:00
|
|
|
{
|
|
|
|
$this->visibilityManipulator = $visibilityManipulator;
|
|
|
|
}
|
2021-09-24 14:11:08 +00:00
|
|
|
public function provideMinPhpVersion() : int
|
|
|
|
{
|
2022-06-07 08:22:29 +00:00
|
|
|
return PhpVersionFeature::PROPERTY_MODIFIER;
|
2021-09-24 14:11:08 +00:00
|
|
|
}
|
2022-06-07 08:22:29 +00:00
|
|
|
public function getRuleDefinition() : RuleDefinition
|
2019-02-19 07:22:45 +00:00
|
|
|
{
|
2022-06-07 08:22:29 +00:00
|
|
|
return new RuleDefinition('Change property modifier from `var` to `public`', [new CodeSample(<<<'CODE_SAMPLE'
|
2019-02-19 07:22:45 +00:00
|
|
|
final class SomeController
|
|
|
|
{
|
|
|
|
var $name = 'Tom';
|
|
|
|
}
|
2020-09-15 08:23:13 +00:00
|
|
|
CODE_SAMPLE
|
2021-05-09 20:15:43 +00:00
|
|
|
, <<<'CODE_SAMPLE'
|
2019-02-19 07:22:45 +00:00
|
|
|
final class SomeController
|
|
|
|
{
|
|
|
|
public $name = 'Tom';
|
|
|
|
}
|
2020-09-15 08:23:13 +00:00
|
|
|
CODE_SAMPLE
|
2021-05-09 20:15:43 +00:00
|
|
|
)]);
|
2019-02-19 07:22:45 +00:00
|
|
|
}
|
|
|
|
/**
|
2021-02-27 00:06:15 +00:00
|
|
|
* @return array<class-string<Node>>
|
2019-02-19 07:22:45 +00:00
|
|
|
*/
|
2021-05-09 20:15:43 +00:00
|
|
|
public function getNodeTypes() : array
|
2019-02-19 07:22:45 +00:00
|
|
|
{
|
2022-06-07 08:22:29 +00:00
|
|
|
return [Property::class];
|
2019-02-19 07:22:45 +00:00
|
|
|
}
|
|
|
|
/**
|
2021-12-10 10:22:23 +00:00
|
|
|
* @param Property $node
|
2019-02-19 07:22:45 +00:00
|
|
|
*/
|
2022-06-07 08:22:29 +00:00
|
|
|
public function refactor(Node $node) : ?Node
|
2019-02-19 07:22:45 +00:00
|
|
|
{
|
2019-09-04 12:10:29 +00:00
|
|
|
// explicitly public
|
2019-02-19 07:22:45 +00:00
|
|
|
if ($node->flags !== 0) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-01-30 21:41:25 +00:00
|
|
|
$this->visibilityManipulator->makePublic($node);
|
2019-02-19 07:22:45 +00:00
|
|
|
return $node;
|
|
|
|
}
|
|
|
|
}
|