File tree Expand file tree Collapse file tree
rules-tests/Php84/Rector/Class_/PropertyHookRector/Fixture
CodingStyle/Rector/FunctionLike 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 @@ -74,6 +74,11 @@ public function refactor(Node $node): null|CallLike
7474 return $ callLike ;
7575 }
7676
77+ public function provideMinPhpVersion (): int
78+ {
79+ return PhpVersionFeature::FIRST_CLASS_CALLABLE_SYNTAX ;
80+ }
81+
7782 private function shouldSkip (
7883 ArrowFunction |Closure $ node ,
7984 FuncCall |MethodCall |StaticCall $ callLike ,
@@ -240,9 +245,4 @@ private function isChainedCall(FuncCall|MethodCall|StaticCall $callLike): bool
240245
241246 return $ callLike ->var instanceof CallLike;
242247 }
243-
244- public function provideMinPhpVersion (): int
245- {
246- return PhpVersionFeature::FIRST_CLASS_CALLABLE_SYNTAX ;
247- }
248248}
Original file line number Diff line number Diff line change 44
55namespace Rector \Php74 \Rector \Double ;
66
7- use Rector \Renaming \Rector \Cast \RenameCastRector ;
87use PhpParser \Node ;
98use PhpParser \Node \Expr \Cast \Double ;
109use Rector \Configuration \Deprecation \Contract \DeprecatedInterface ;
1110use Rector \Exception \ShouldNotHappenException ;
1211use Rector \Rector \AbstractRector ;
12+ use Rector \Renaming \Rector \Cast \RenameCastRector ;
1313use Rector \ValueObject \PhpVersionFeature ;
1414use Rector \VersionBonding \Contract \MinPhpVersionInterface ;
1515use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
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