Skip to content

Commit d42b9d5

Browse files
committed
skip get/set magic
1 parent d39e1fe commit d42b9d5

4 files changed

Lines changed: 48 additions & 6 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

rules/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff 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
}

rules/Php74/Rector/Double/RealToFloatTypeCastRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace Rector\Php74\Rector\Double;
66

7-
use Rector\Renaming\Rector\Cast\RenameCastRector;
87
use PhpParser\Node;
98
use PhpParser\Node\Expr\Cast\Double;
109
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
1110
use Rector\Exception\ShouldNotHappenException;
1211
use Rector\Rector\AbstractRector;
12+
use Rector\Renaming\Rector\Cast\RenameCastRector;
1313
use Rector\ValueObject\PhpVersionFeature;
1414
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
1515
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;

rules/Php84/Rector/Class_/PropertyHookRector.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Rector\Php84\NodeFactory\PropertyHookFactory;
1414
use Rector\Php84\NodeFinder\SetterAndGetterFinder;
1515
use Rector\Rector\AbstractRector;
16+
use Rector\ValueObject\MethodName;
1617
use Rector\ValueObject\PhpVersionFeature;
1718
use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard;
1819
use 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
}

0 commit comments

Comments
 (0)