diff --git a/rules/nette-kdyby/src/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector.php b/rules/nette-kdyby/src/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector.php index 3ecb6e1f21bf..bd40992b8df4 100644 --- a/rules/nette-kdyby/src/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector.php +++ b/rules/nette-kdyby/src/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector.php @@ -4,6 +4,7 @@ namespace Rector\NetteKdyby\Rector\MethodCall; +use Nette\Application\UI\Control; use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\Assign; @@ -168,6 +169,11 @@ private function isLocalOnPropertyCall(MethodCall $methodCall): bool return false; } + // control event, inner only + if (is_a($className, Control::class, true)) { + return false; + } + if (method_exists($className, $methodName)) { return false; } diff --git a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/fixture.php.inc b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/simple_event.php.inc similarity index 100% rename from rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/fixture.php.inc rename to rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/simple_event.php.inc diff --git a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/skip_on_success_in_control.php.inc b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/skip_on_success_in_control.php.inc new file mode 100644 index 000000000000..89ecb9bc0fdb --- /dev/null +++ b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/skip_on_success_in_control.php.inc @@ -0,0 +1,20 @@ +onSuccess($user, 'run'); + + $this->onBeforeSuccess($user, 'run'); + } +} diff --git a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/ReplaceMagicPropertyEventWithEventClassRectorTest.php b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/ReplaceMagicPropertyEventWithEventClassRectorTest.php index 25d5b86097b8..28e286156ebf 100644 --- a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/ReplaceMagicPropertyEventWithEventClassRectorTest.php +++ b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/ReplaceMagicPropertyEventWithEventClassRectorTest.php @@ -9,9 +9,14 @@ final class ReplaceMagicPropertyEventWithEventClassRectorTest extends AbstractRectorTestCase { - public function test(): void + public function testSkip(): void { - $this->doTestFile(__DIR__ . '/Fixture/fixture.php.inc'); + $this->doTestFile(__DIR__ . '/Fixture/skip_on_success_in_control.php.inc'); + } + + public function testSimpleEvent(): void + { + $this->doTestFile(__DIR__ . '/Fixture/simple_event.php.inc'); $expectedEventFilePath = dirname($this->originalTempFile) . '/Event/FileManagerUploadEvent.php'; $this->assertFileExists($expectedEventFilePath);