|
11 | 11 | use Rector\Php\PhpVersionProvider; |
12 | 12 | use Rector\Rector\AbstractRector; |
13 | 13 | use Rector\ValueObject\MethodName; |
14 | | -<<<<<<< HEAD |
15 | | -use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard; |
16 | | -======= |
17 | 14 | use Rector\ValueObject\PhpVersionFeature; |
| 15 | +use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard; |
18 | 16 | use Rector\VersionBonding\Contract\MinPhpVersionInterface; |
19 | | ->>>>>>> 971356b355 (add scalar types condition) |
20 | 17 | use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; |
21 | 18 | use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; |
22 | 19 |
|
|
28 | 25 | final class KnownMagicClassMethodTypeRector extends AbstractRector implements MinPhpVersionInterface |
29 | 26 | { |
30 | 27 | public function __construct( |
31 | | -<<<<<<< HEAD |
32 | | - private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard |
33 | | - ){ |
34 | | - } |
35 | | -======= |
36 | | - private readonly PhpVersionProvider $phpVersionProvider |
| 28 | + private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard, |
| 29 | + private readonly PhpVersionProvider $phpVersionProvider, |
37 | 30 | ) { |
38 | 31 |
|
39 | 32 | } |
40 | 33 |
|
41 | | ->>>>>>> 3a091179f1 (add call static support, set and get) |
42 | 34 | public function getRuleDefinition(): RuleDefinition |
43 | 35 | { |
44 | 36 | return new RuleDefinition( |
@@ -87,50 +79,38 @@ public function refactor(Node $node): ?Node |
87 | 79 | continue; |
88 | 80 | } |
89 | 81 |
|
90 | | -<<<<<<< HEAD |
91 | | - if (! $this->isName($classMethod, MethodName::CALL)) { |
92 | | - continue; |
93 | | - } |
94 | | -======= |
95 | | - if ($this->isNames($classMethod, [MethodName::CALL, MethodName::CALL_STATIC])) { |
96 | | - $firstParam = $classMethod->getParams()[0]; |
97 | | - if (! $firstParam->type instanceof Node) { |
98 | | - $firstParam->type = new Identifier('string'); |
99 | | - $hasChanged = true; |
100 | | - } |
101 | | ->>>>>>> 3a091179f1 (add call static support, set and get) |
102 | | - |
103 | 82 | if ($this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($classMethod)) { |
104 | 83 | return null; |
105 | 84 | } |
106 | 85 |
|
107 | | - $firstParam = $classMethod->getParams()[0]; |
108 | | - if (! $firstParam->type instanceof Node) { |
109 | | - $firstParam->type = new Identifier('string'); |
110 | | - $hasChanged = true; |
111 | | - } |
112 | | - |
113 | | - $secondParam = $classMethod->getParams()[1]; |
114 | | - if (! $secondParam->type instanceof Node) { |
115 | | - $secondParam->type = new Name('array'); |
116 | | - $hasChanged = true; |
117 | | - } |
118 | | - |
119 | | - if ($this->isName($classMethod, MethodName::__GET)) { |
120 | | - $firstParam = $classMethod->getParams()[0]; |
121 | | - if (! $firstParam->type instanceof Node) { |
122 | | - $firstParam->type = new Identifier('string'); |
| 86 | + if ($this->isNames($classMethod, [MethodName::CALL, MethodName::CALL_STATIC])) { |
| 87 | + $secondParam = $classMethod->getParams()[1]; |
| 88 | + if (! $secondParam->type instanceof Node) { |
| 89 | + $secondParam->type = new Name('array'); |
123 | 90 | $hasChanged = true; |
124 | 91 | } |
125 | 92 | } |
126 | 93 |
|
127 | | - if ($this->isName($classMethod, MethodName::__SET)) { |
| 94 | + // first arg string |
| 95 | + if ($this->isNames( |
| 96 | + $classMethod, |
| 97 | + [ |
| 98 | + MethodName::CALL, |
| 99 | + MethodName::CALL_STATIC, |
| 100 | + MethodName::__SET, |
| 101 | + MethodName::__GET, |
| 102 | + MethodName::ISSET, |
| 103 | + MethodName::UNSET, |
| 104 | + ] |
| 105 | + )) { |
128 | 106 | $firstParam = $classMethod->getParams()[0]; |
129 | 107 | if (! $firstParam->type instanceof Node) { |
130 | 108 | $firstParam->type = new Identifier('string'); |
131 | 109 | $hasChanged = true; |
132 | 110 | } |
| 111 | + } |
133 | 112 |
|
| 113 | + if ($this->isName($classMethod, MethodName::__SET)) { |
134 | 114 | if ($this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::MIXED_TYPE)) { |
135 | 115 | $secondParam = $classMethod->getParams()[1]; |
136 | 116 | if (! $secondParam->type instanceof Node) { |
|
0 commit comments