mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-20 23:18:20 +01:00
fix child blocked property type
This commit is contained in:
parent
ff655f3360
commit
b98d937ffb
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user