File tree Expand file tree Collapse file tree
rules-tests/Php84/Rector/Class_/PropertyHookRector/Fixture
rules/Php84/Rector/Class_ Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \Php84 \Rector \Class_ \PropertyHookRector \Fixture ;
4+
5+ final class SkipGetSetMagic
6+ {
7+ private string $ name ;
8+
9+ public function getName (): string
10+ {
11+ return $ this ->name ;
12+ }
13+
14+ public function setName (string $ name ): void
15+ {
16+ $ this ->name = ucfirst ($ name );
17+ }
18+
19+ public function __get ($ name )
20+ {
21+ }
22+
23+ public function __set ($ name , $ value )
24+ {
25+ }
26+ }
Original file line number Diff line number Diff line change 1313use Rector \Php84 \NodeFactory \PropertyHookFactory ;
1414use Rector \Php84 \NodeFinder \SetterAndGetterFinder ;
1515use Rector \Rector \AbstractRector ;
16+ use Rector \ValueObject \MethodName ;
1617use Rector \ValueObject \PhpVersionFeature ;
1718use Rector \VendorLocker \ParentClassMethodTypeOverrideGuard ;
1819use Rector \VersionBonding \Contract \MinPhpVersionInterface ;
@@ -82,6 +83,10 @@ public function refactor(Node $node): ?Node
8283 return null ;
8384 }
8485
86+ if ($ this ->hasMagicGetSetMethod ($ node )) {
87+ return null ;
88+ }
89+
8590 // nothing to hook to
8691 if ($ node ->getProperties () === []) {
8792 return null ;
@@ -149,4 +154,15 @@ public function provideMinPhpVersion(): int
149154 {
150155 return PhpVersionFeature::PROPERTY_HOOKS ;
151156 }
157+
158+ private function hasMagicGetSetMethod (Class_ $ class ): bool
159+ {
160+ $ magicGetMethod = $ class ->getMethod (MethodName::__GET);
161+ if ($ magicGetMethod instanceof ClassMethod) {
162+ return true ;
163+ }
164+
165+ $ magicSetMethod = $ class ->getMethod (MethodName::__SET);
166+ return $ magicSetMethod instanceof ClassMethod;
167+ }
152168}
You can’t perform that action at this time.
0 commit comments