[MagicDisclosure] Fix property assign magic call [closes #1190]

This commit is contained in:
Tomas Votruba 2019-04-02 16:15:39 +02:00
parent 0543a5a2ab
commit c5f51e5cb1
5 changed files with 57 additions and 13 deletions

View File

@ -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,

View File

@ -118,10 +118,6 @@ CODE_SAMPLE
continue;
}
if ($this->propertyFetchManipulator->isPropertyToSelf($propertyFetchNode)) {
continue;
}
if (! $this->propertyFetchManipulator->isMagicOnType($propertyFetchNode, $type)) {
continue;
}

View File

@ -0,0 +1,35 @@
<?php
namespace Rector\Tests\Rector\MagicDisclosure\GetAndSetToMethodCallRector\Fixture;
use Rector\Tests\Rector\MagicDisclosure\GetAndSetToMethodCallRector\Source\Klarka;
class KlarkaExtended extends Klarka
{
public function run()
{
if ($this->leafBreadcrumbCategory) {
$category = $this->leafBreadcrumbCategory;
}
}
}
?>
-----
<?php
namespace Rector\Tests\Rector\MagicDisclosure\GetAndSetToMethodCallRector\Fixture;
use Rector\Tests\Rector\MagicDisclosure\GetAndSetToMethodCallRector\Source\Klarka;
class KlarkaExtended extends Klarka
{
public function run()
{
if ($this->get('leafBreadcrumbCategory')) {
$category = $this->get('leafBreadcrumbCategory');
}
}
}
?>

View File

@ -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',
],
];
}
}

View File

@ -0,0 +1,8 @@
<?php declare(strict_types=1);
namespace Rector\Tests\Rector\MagicDisclosure\GetAndSetToMethodCallRector\Source;
class Klarka
{
}