| Subject |
Details |
| Rector version |
v0.6.3 |
| PHP version |
PHP 7.4 |
| Full Command |
vendor/bin/rector process --dry-run file.php |
Problem
There is a problem with TypedPropertyRector. When Child extends VendorParent (package coming from Composer) and overwrites a property with a default value, Rector will try to apply the string property type.
When running the code, this fails:
Compile Error: Type of Child::$name must not be defined (as in class VendorParent)
The reason is that the parent is not changed, so the parent has no type, but the child introduces a type. That's not allowed in PHP 7.4.
Failing test scenario:
vendor/rector/rector/packages/Php74/tests/Rector/Property/TypedPropertyRector/Fixture/parent_has_untyped_property.php.inc:
<?php
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
class VendorParent
{
/**
* @var string
*/
protected $name;
}
final class Child extends VendorParent
{
/**
* @var string
*/
protected $name = 'child';
}
?>
-----
<?php
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
class VendorParent
{
/**
* @var string
*/
protected $name;
}
final class Child extends VendorParent
{
/**
* @var string
*/
protected $name = 'child';
}
?>
result:
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
/**
* @var string
*/
- protected $name;
+ protected string $name;
}
final class Child extends VendorParent
@@ @@
/**
* @var string
*/
- protected $name = 'child';
+ protected string $name = 'child';
}
?>
(it also tries to update the VendorParent, but that's because I didn't exclude this one. Should propably be done in the test somewhere, not sure where).
Problem
There is a problem with TypedPropertyRector. When
ChildextendsVendorParent(package coming from Composer) and overwrites a property with a default value, Rector will try to apply thestringproperty type.When running the code, this fails:
The reason is that the parent is not changed, so the parent has no type, but the child introduces a type. That's not allowed in PHP 7.4.
Failing test scenario:
vendor/rector/rector/packages/Php74/tests/Rector/Property/TypedPropertyRector/Fixture/parent_has_untyped_property.php.inc:
result:
(it also tries to update the VendorParent, but that's because I didn't exclude this one. Should propably be done in the test somewhere, not sure where).