mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 09:50:49 +00:00
[Php81] Skip has unset property fetch on ReadOnlyPropertyRector (#1953)
Co-authored-by: Bertrand <bertrand.jamin@gmail.com> Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
a0178a72d4
commit
e7c028396b
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Php81\Rector\Property\ReadOnlyPropertyRector\Fixture;
|
||||
|
||||
final class SkipUnsetPropertyFetch
|
||||
{
|
||||
public function __construct(private array $data) {}
|
||||
|
||||
public function run()
|
||||
{
|
||||
unset($this->data['item']);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -25,6 +25,7 @@ use PhpParser\Node\Stmt\ClassLike;
|
|||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\Unset_;
|
||||
use PHPStan\Reflection\ParametersAcceptorSelector;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
|
@ -167,16 +168,18 @@ final class PropertyManipulator
|
|||
|
||||
// skip for constructor? it is allowed to set value in constructor method
|
||||
$classMethod = $this->betterNodeFinder->findParentType($propertyFetch, ClassMethod::class);
|
||||
if ($classMethod instanceof ClassMethod && $this->isInlineStmtWithConstructMethod(
|
||||
$propertyFetch,
|
||||
$classMethod
|
||||
)) {
|
||||
if ($this->isInlineStmtWithConstructMethod($propertyFetch, $classMethod)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->assignManipulator->isLeftPartOfAssign($propertyFetch)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$isInUnset = (bool) $this->betterNodeFinder->findParentType($propertyFetch, Unset_::class);
|
||||
if ($isInUnset) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -225,8 +228,12 @@ final class PropertyManipulator
|
|||
|
||||
private function isInlineStmtWithConstructMethod(
|
||||
PropertyFetch|StaticPropertyFetch $propertyFetch,
|
||||
ClassMethod $classMethod
|
||||
?ClassMethod $classMethod
|
||||
): bool {
|
||||
if (! $classMethod instanceof ClassMethod) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->nodeNameResolver->isName($classMethod->name, MethodName::CONSTRUCT)) {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user