|
15 | 15 | use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover; |
16 | 16 | use Rector\Comments\NodeDocBlock\DocBlockUpdater; |
17 | 17 | use Rector\Doctrine\NodeAnalyzer\AttrinationFinder; |
| 18 | +use Rector\NodeAnalyzer\MagicClassMethodAnalyzer; |
18 | 19 | use Rector\Rector\AbstractRector; |
19 | 20 | use Rector\Symfony\Enum\FosAnnotation; |
20 | 21 | use Rector\Symfony\Enum\SymfonyAnnotation; |
@@ -47,7 +48,8 @@ public function __construct( |
47 | 48 | private readonly PhpDocTagRemover $phpDocTagRemover, |
48 | 49 | private readonly DocBlockUpdater $docBlockUpdater, |
49 | 50 | private readonly ControllerAnalyzer $controllerAnalyzer, |
50 | | - private readonly AttrinationFinder $attrinationFinder |
| 51 | + private readonly AttrinationFinder $attrinationFinder, |
| 52 | + private readonly MagicClassMethodAnalyzer $magicClassMethodAnalyzer |
51 | 53 | ) { |
52 | 54 | } |
53 | 55 |
|
@@ -134,7 +136,7 @@ public function refactor(Node $node): ?Class_ |
134 | 136 | $hasChanged = false; |
135 | 137 |
|
136 | 138 | foreach ($node->getMethods() as $classMethod) { |
137 | | - if (! $classMethod->isPublic() || $classMethod->isMagic()) { |
| 139 | + if ($this->shouldSkipMethod($classMethod)) { |
138 | 140 | continue; |
139 | 141 | } |
140 | 142 |
|
@@ -255,14 +257,21 @@ public function refactor(Node $node): ?Class_ |
255 | 257 | return $node; |
256 | 258 | } |
257 | 259 |
|
| 260 | + private function shouldSkipMethod(Node\Stmt\ClassMethod $classMethod): bool |
| 261 | + { |
| 262 | + return |
| 263 | + !$classMethod->isPublic() |
| 264 | + || $this->magicClassMethodAnalyzer->isUnsafeOverridden($classMethod); |
| 265 | + } |
| 266 | + |
258 | 267 | private function shouldSkipClass(Class_ $class): bool |
259 | 268 | { |
260 | 269 | if (! $this->controllerAnalyzer->isController($class)) { |
261 | 270 | return true; |
262 | 271 | } |
263 | 272 |
|
264 | 273 | foreach ($class->getMethods() as $classMethod) { |
265 | | - if (! $classMethod->isPublic() || $classMethod->isMagic()) { |
| 274 | + if ($this->shouldSkipMethod($classMethod)) { |
266 | 275 | continue; |
267 | 276 | } |
268 | 277 |
|
|
0 commit comments