From c5f51e5cb1156361d2498a792139dabc2eaff58d Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 2 Apr 2019 16:15:39 +0200 Subject: [PATCH] [MagicDisclosure] Fix property assign magic call [closes #1190] --- src/Console/Command/ProcessCommand.php | 6 ++-- .../GetAndSetToMethodCallRector.php | 4 --- .../Fixture/klarka.php.inc | 35 +++++++++++++++++++ .../GetAndSetToMethodCallRectorTest.php | 17 +++++---- .../Source/Klarka.php | 8 +++++ 5 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/Fixture/klarka.php.inc create mode 100644 tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/Source/Klarka.php diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index 835b2223b9c..3b27c6a8098 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -18,7 +18,6 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symplify\PackageBuilder\Console\Command\CommandNaming; -use Symplify\PackageBuilder\Parameter\ParameterProvider; final class ProcessCommand extends AbstractCommand { @@ -70,8 +69,11 @@ final class ProcessCommand extends AbstractCommand /** * @var string[] */ - private $fileExtensions; + private $fileExtensions = []; + /** + * @param string[] $fileExtensions + */ public function __construct( SymfonyStyle $symfonyStyle, FilesFinder $phpFilesFinder, diff --git a/src/Rector/MagicDisclosure/GetAndSetToMethodCallRector.php b/src/Rector/MagicDisclosure/GetAndSetToMethodCallRector.php index 69f01891e1b..aa3eece6e8b 100644 --- a/src/Rector/MagicDisclosure/GetAndSetToMethodCallRector.php +++ b/src/Rector/MagicDisclosure/GetAndSetToMethodCallRector.php @@ -118,10 +118,6 @@ CODE_SAMPLE continue; } - if ($this->propertyFetchManipulator->isPropertyToSelf($propertyFetchNode)) { - continue; - } - if (! $this->propertyFetchManipulator->isMagicOnType($propertyFetchNode, $type)) { continue; } diff --git a/tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/Fixture/klarka.php.inc b/tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/Fixture/klarka.php.inc new file mode 100644 index 00000000000..0980e65f20c --- /dev/null +++ b/tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/Fixture/klarka.php.inc @@ -0,0 +1,35 @@ +leafBreadcrumbCategory) { + $category = $this->leafBreadcrumbCategory; + } + } +} + +?> +----- +get('leafBreadcrumbCategory')) { + $category = $this->get('leafBreadcrumbCategory'); + } + } +} + +?> diff --git a/tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/GetAndSetToMethodCallRectorTest.php b/tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/GetAndSetToMethodCallRectorTest.php index 0fbb7ac40e8..52eac943298 100644 --- a/tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/GetAndSetToMethodCallRectorTest.php +++ b/tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/GetAndSetToMethodCallRectorTest.php @@ -4,19 +4,19 @@ namespace Rector\Tests\Rector\MagicDisclosure\GetAndSetToMethodCallRector; use Rector\Rector\MagicDisclosure\GetAndSetToMethodCallRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; +use Rector\Tests\Rector\MagicDisclosure\GetAndSetToMethodCallRector\Source\Klarka; use Rector\Tests\Rector\MagicDisclosure\GetAndSetToMethodCallRector\Source\SomeContainer; final class GetAndSetToMethodCallRectorTest extends AbstractRectorTestCase { public function test(): void { - $this->doTestFiles( - [ - __DIR__ . '/Fixture/fixture.php.inc', - __DIR__ . '/Fixture/fixture2.php.inc', - __DIR__ . '/Fixture/fixture3.php.inc', - ] - ); + $this->doTestFiles([ + __DIR__ . '/Fixture/fixture.php.inc', + __DIR__ . '/Fixture/fixture2.php.inc', + __DIR__ . '/Fixture/fixture3.php.inc', + __DIR__ . '/Fixture/klarka.php.inc', + ]); } protected function getRectorClass(): string @@ -38,6 +38,9 @@ final class GetAndSetToMethodCallRectorTest extends AbstractRectorTestCase 'get' => 'getService', 'set' => 'addService', ], + Klarka::class => [ + 'get' => 'get', + ], ]; } } diff --git a/tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/Source/Klarka.php b/tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/Source/Klarka.php new file mode 100644 index 00000000000..0e212d9387c --- /dev/null +++ b/tests/Rector/MagicDisclosure/GetAndSetToMethodCallRector/Source/Klarka.php @@ -0,0 +1,8 @@ +