fix child blocked property type

This commit is contained in:
TomasVotruba 2020-06-07 17:08:11 +02:00
parent ff655f3360
commit b98d937ffb
2 changed files with 55 additions and 2 deletions

View File

@ -10,6 +10,7 @@ use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Property;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\Node\AttributeKey;
use ReflectionProperty;
final class PropertyTypeVendorLockResolver extends AbstractNodeVendorLockResolver
{
@ -83,10 +84,19 @@ final class PropertyTypeVendorLockResolver extends AbstractNodeVendorLockResolve
}
$childrenClassNames = $this->getChildrenClassesByClass($classLike);
foreach ($childrenClassNames as $childClassName) {
if (property_exists($childClassName, $propertyName)) {
return true;
if (! property_exists($childClassName, $propertyName)) {
continue;
}
// ensure the property is not in the parent class
$reflectionProperty = new ReflectionProperty($childClassName, $propertyName);
if ($reflectionProperty->class !== $childClassName) {
continue;
}
return true;
}
return false;

View File

@ -0,0 +1,43 @@
<?php
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\SomeChildOfSomeParent;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\SomeParent;
class ChildClassHasAnotherProperty
{
/**
* @var SomeChildOfSomeParent
*/
public $someChildOfSomeParent;
}
final class ChildClass extends ChildClassHasAnotherProperty
{
/**
* @var SomeParent
*/
public $someParent;
}
?>
-----
<?php
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\SomeChildOfSomeParent;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\SomeParent;
class ChildClassHasAnotherProperty
{
public \Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\SomeChildOfSomeParent $someChildOfSomeParent;
}
final class ChildClass extends ChildClassHasAnotherProperty
{
public \Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\SomeParent $someParent;
}
?>