From 0e3f9f7812a8c9c553ce97c8ad91b19ed0c2a5b6 Mon Sep 17 00:00:00 2001 From: Christian Rodriguez Benthake Date: Fri, 28 Jul 2023 17:07:34 +0200 Subject: [PATCH 1/2] Create skip_readonly_new_static.php.inc Add new fixture for readonly including a `new static()` --- .../Fixture/skip_readonly_new_static.php.inc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_readonly_new_static.php.inc diff --git a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_readonly_new_static.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_readonly_new_static.php.inc new file mode 100644 index 00000000000..c8bfd2a58cf --- /dev/null +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_readonly_new_static.php.inc @@ -0,0 +1,18 @@ +method = 'hi'; + $self->method = 'hello'; + return $self; + } +} + +?> From 7414da5c1ca478a88b69875ab01ae706d2dcc99d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 28 Jul 2023 22:19:48 +0700 Subject: [PATCH 2/2] Closes #4616 Fixes https://github.com/rectorphp/rector/issues/8095 --- src/PhpParser/NodeFinder/PropertyFetchFinder.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/PhpParser/NodeFinder/PropertyFetchFinder.php b/src/PhpParser/NodeFinder/PropertyFetchFinder.php index e82b43e1793..df68d3f15d6 100644 --- a/src/PhpParser/NodeFinder/PropertyFetchFinder.php +++ b/src/PhpParser/NodeFinder/PropertyFetchFinder.php @@ -141,10 +141,11 @@ public function isLocalPropertyFetchByName(Expr $expr, Class_|Trait_ $class, str } $type = $this->nodeTypeResolver->getType($expr->var); - return $type instanceof FullyQualifiedObjectType && $this->nodeNameResolver->isName( - $class, - $type->getClassName() - ); + if ($type instanceof \PHPStan\Type\StaticType || $type instanceof FullyQualifiedObjectType) { + return $this->nodeNameResolver->isName($class, $type->getClassName()); + } + + return false; } /**