mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-22 02:36:52 +01:00
remove duplicated CompleteVarDocTypeConstantRector
This commit is contained in:
parent
08bc9355d7
commit
2c632b2b79
@ -1,6 +1,5 @@
|
||||
services:
|
||||
Rector\CodingStyle\Rector\If_\NullableCompareToNullRector: ~
|
||||
Rector\CodingStyle\Rector\ClassConst\CompleteVarDocTypeConstantRector: ~
|
||||
Rector\CodingStyle\Rector\FuncCall\SimpleArrayCallableToStringRector: ~
|
||||
Rector\CodingStyle\Rector\Identical\IdenticalFalseToBooleanNotRector: ~
|
||||
Rector\CodingStyle\Rector\Switch_\BinarySwitchToIfElseRector: ~
|
||||
@ -22,4 +21,5 @@ services:
|
||||
Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector: ~
|
||||
Rector\CodingStyle\Rector\Property\ArrayPropertyDefaultValueRector: ~
|
||||
Rector\CodingStyle\Rector\Assign\SplitDoubleAssignRector: ~
|
||||
|
||||
Rector\CodingStyle\Rector\ClassConst\VarConstantCommentRector: ~
|
||||
|
@ -1,88 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\CodingStyle\Rector\ClassConst;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassConst;
|
||||
use Rector\NodeTypeResolver\Node\NodeToStringTypeResolver;
|
||||
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockManipulator;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
final class CompleteVarDocTypeConstantRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var DocBlockManipulator
|
||||
*/
|
||||
private $docBlockManipulator;
|
||||
|
||||
/**
|
||||
* @var NodeToStringTypeResolver
|
||||
*/
|
||||
private $nodeToStringTypeResolver;
|
||||
|
||||
public function __construct(
|
||||
DocBlockManipulator $docBlockManipulator,
|
||||
NodeToStringTypeResolver $nodeToStringTypeResolver
|
||||
) {
|
||||
$this->docBlockManipulator = $docBlockManipulator;
|
||||
$this->nodeToStringTypeResolver = $nodeToStringTypeResolver;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('Complete constant `@var` annotations for missing one, yet known.', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
private const NUMBER = 5;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private const NUMBER = 5;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [ClassConst::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassConst $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if ($this->docBlockManipulator->hasTag($node, 'var')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// work only with single-constant
|
||||
if (count($node->consts) > 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$knownType = $this->nodeToStringTypeResolver->resolver($node->consts[0]->value);
|
||||
if ($knownType === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->docBlockManipulator->changeVarTag($node, $knownType);
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\ClassConst\CompleteVarDocTypeConstantRector;
|
||||
|
||||
use Rector\CodingStyle\Rector\ClassConst\CompleteVarDocTypeConstantRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
|
||||
final class CompleteVarDocTypeConstantRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
public function test(): void
|
||||
{
|
||||
$this->doTestFiles([__DIR__ . '/Fixture/fixture.php.inc']);
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return CompleteVarDocTypeConstantRector::class;
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\ClassConst\CompleteVarDocTypeConstantRector\Fixture;
|
||||
|
||||
final class SomeClass
|
||||
{
|
||||
private const NUMBER = 5;
|
||||
private const NUMBER_NEGATIVE = -5;
|
||||
const STRING = 'name';
|
||||
const ITEMs = [[self::STRING]];
|
||||
|
||||
private const A = false, B = 2.5;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\ClassConst\CompleteVarDocTypeConstantRector\Fixture;
|
||||
|
||||
final class SomeClass
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private const NUMBER = 5;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private const NUMBER_NEGATIVE = -5;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const STRING = 'name';
|
||||
/**
|
||||
* @var mixed[]
|
||||
*/
|
||||
const ITEMs = [[self::STRING]];
|
||||
|
||||
private const A = false, B = 2.5;
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user