fix TypePropertyRector not to remove @var docs, cs should to that [closes #886]

This commit is contained in:
Tomas Votruba 2018-12-22 15:31:55 +01:00
parent 26b83be1f7
commit a0e4f65e3e
8 changed files with 73 additions and 8 deletions

View File

@ -107,8 +107,6 @@ CODE_SAMPLE
return null;
}
$this->docBlockAnalyzer->removeTagFromNode($node, 'var');
$node->setAttribute(self::PHP74_PROPERTY_TYPE, $varTypeInfo->getTypeNode());
// invoke the print, because only attribute has changed

View File

@ -22,6 +22,9 @@ use Rector\Php\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
final class ClassWithClassProperty
{
/**
* @var AnotherClass
*/
private AnotherClass $anotherClass;
}

View File

@ -88,6 +88,9 @@ final class DefaultValues
*/
private $name = 'not_a_bool';
/**
* @var bool
*/
private bool $isItRealName = false;
/**
@ -110,10 +113,19 @@ final class DefaultValues
*/
private $itemsB = null;
/**
* @var array|null
*/
private ?array $nullableItems = null;
/**
* @var float
*/
private float $a = 42.42;
/**
* @var float
*/
private float $b = 42;
/**
@ -126,10 +138,19 @@ final class DefaultValues
*/
private $e = 42.42;
/**
* @var int
*/
private int $f = 42;
/**
* @var array
*/
private array $g = [1, 2, 3];
/**
* @var iterable
*/
private iterable $h = [1, 2, 3];
}

View File

@ -63,24 +63,54 @@ namespace Rector\Php\Tests\Rector\Property\TypedPropertyRector\Fixture;
final class MatchTypes
{
/**
* @var bool
*/
private bool $a;
/**
* @var boolean
*/
private bool $b;
/**
* @var int
*/
private int $c;
/**
* @var integer
*/
private int $d;
/**
* @var float
*/
private float $e;
/**
* @var string
*/
private string $f;
/**
* @var object
*/
private object $g;
/**
* @var iterable
*/
private iterable $h;
/**
* @var self
*/
private self $i;
/**
* @var parent
*/
private parent $j;
}

View File

@ -27,8 +27,14 @@ use Rector\Php\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
final class ClassWithNullableProperty
{
/**
* @var AnotherClass|null
*/
private ?AnotherClass $anotherClass = null;
/**
* @var null|AnotherClass
*/
private ?AnotherClass $yetAnotherClass;
}

View File

@ -44,6 +44,9 @@ namespace Rector\Php\Tests\Rector\Property\TypedPropertyRector\Fixture;
final class ClassWithProperty
{
/**
* @var int
*/
private int $count;
/**
@ -52,6 +55,7 @@ final class ClassWithProperty
private $multiCount;
/**
* @var bool
* another comment
*/
private bool $isTrue = false;

View File

@ -22,6 +22,9 @@ use Rector\Php\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
final class ClassWithStaticProperty
{
/**
* @var iterable
*/
private static iterable $iterable;
}

View File

@ -10,12 +10,12 @@ final class TypedPropertyRectorTest extends AbstractRectorTestCase
public function test(): void
{
$this->doTestFiles([
__DIR__ . '/Fixture/ClassWithProperty.php.inc',
__DIR__ . '/Fixture/ClassWithClassProperty.php.inc',
__DIR__ . '/Fixture/ClassWithNullableProperty.php.inc',
__DIR__ . '/Fixture/ClassWithStaticProperty.php.inc',
__DIR__ . '/Fixture/DefaultValues.php.inc',
__DIR__ . '/Fixture/MatchTypes.php.inc',
__DIR__ . '/Fixture/property.php.inc',
__DIR__ . '/Fixture/class_property.php.inc',
__DIR__ . '/Fixture/nullable_property.php.inc',
__DIR__ . '/Fixture/static_property.php.inc',
__DIR__ . '/Fixture/default_values.php.inc',
__DIR__ . '/Fixture/match_types.php.inc',
]);
}