mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-24 17:36:02 +02:00
[MagicMethodRector] decouple dependency on specific class
This commit is contained in:
parent
e278a9cc04
commit
97932a59bd
@ -47,18 +47,25 @@ final class MagicMethodRector extends AbstractRector
|
||||
*/
|
||||
private $nodeTypeResolver;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $parentClass;
|
||||
|
||||
public function __construct(
|
||||
MethodBuilder $methodBuilder,
|
||||
DocBlockAnalyzer $docBlockAnalyzer,
|
||||
SmartClassReflector $smartClassReflector,
|
||||
MagicMethodMatcher $magicMethodMatcher,
|
||||
NodeTypeResolver $nodeTypeResolver
|
||||
NodeTypeResolver $nodeTypeResolver,
|
||||
string $parentClass = 'Nette\Object'
|
||||
) {
|
||||
$this->methodBuilder = $methodBuilder;
|
||||
$this->docBlockAnalyzer = $docBlockAnalyzer;
|
||||
$this->smartClassReflector = $smartClassReflector;
|
||||
$this->magicMethodMatcher = $magicMethodMatcher;
|
||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
$this->parentClass = $parentClass;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
@ -151,6 +158,6 @@ CODE_SAMPLE
|
||||
{
|
||||
$classNodeTypes = $this->nodeTypeResolver->resolve($classNode);
|
||||
|
||||
return in_array('Nette\Object', $classNodeTypes, true);
|
||||
return in_array($this->parentClass, $classNodeTypes, true);
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace SomeNamespace;
|
||||
|
||||
use Nette\Object;
|
||||
use Rector\Tests\Rector\Contrib\Nette\Utils\MagicMethodRector\Source\SomeObject;
|
||||
|
||||
class SomeClassExtendingNetteObject extends Object
|
||||
class SomeClassExtendingNetteObject extends SomeObject
|
||||
{
|
||||
private $value;
|
||||
private $anotherValue;
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace SomeNamespace;
|
||||
|
||||
use Nette\Object;
|
||||
use Rector\Tests\Rector\Contrib\Nette\Utils\MagicMethodRector\Source\SomeObject;
|
||||
|
||||
class SomeClassExtendingNetteObject2 extends Object
|
||||
class SomeClassExtendingNetteObject2 extends SomeObject
|
||||
{
|
||||
public $name;
|
||||
public $enabled;
|
||||
|
@ -15,10 +15,6 @@ final class MagicMethodRectorTest extends AbstractRectorTestCase
|
||||
*/
|
||||
public function test(string $wrong, string $fixed): void
|
||||
{
|
||||
if (PHP_VERSION >= '7.2.0') {
|
||||
$this->markTestSkipped('This test needs PHP 7.1 or lower.');
|
||||
}
|
||||
|
||||
$this->doTestFileMatchesExpectedContent($wrong, $fixed);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Rector\Contrib\Nette\Utils\MagicMethodRector\Source;
|
||||
|
||||
class SomeObject
|
||||
{
|
||||
|
||||
}
|
@ -2,13 +2,13 @@
|
||||
|
||||
namespace SomeNamespace;
|
||||
|
||||
use Nette\Object;
|
||||
use Rector\Tests\Rector\Contrib\Nette\Utils\MagicMethodRector\Source\SomeObject;
|
||||
|
||||
/**
|
||||
* @method getValue()
|
||||
* @method int getAnotherValue()
|
||||
*/
|
||||
class SomeClassExtendingNetteObject extends Object
|
||||
class SomeClassExtendingNetteObject extends SomeObject
|
||||
{
|
||||
private $value;
|
||||
private $anotherValue;
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace SomeNamespace;
|
||||
|
||||
use Nette\Object;
|
||||
use Rector\Tests\Rector\Contrib\Nette\Utils\MagicMethodRector\Source\SomeObject;
|
||||
|
||||
/**
|
||||
* @method void setName(string $var)
|
||||
@ -12,7 +12,7 @@ use Nette\Object;
|
||||
* @method getItems
|
||||
* @method setEnabled (bool)
|
||||
*/
|
||||
class SomeClassExtendingNetteObject2 extends Object
|
||||
class SomeClassExtendingNetteObject2 extends SomeObject
|
||||
{
|
||||
public $name;
|
||||
public $enabled;
|
||||
|
@ -1,2 +1,4 @@
|
||||
services:
|
||||
Rector\Rector\Contrib\Nette\Utils\MagicMethodRector: ~
|
||||
Rector\Rector\Contrib\Nette\Utils\MagicMethodRector:
|
||||
arguments:
|
||||
$parentClass: 'Rector\Tests\Rector\Contrib\Nette\Utils\MagicMethodRector\Source\SomeObject'
|
||||
|
Loading…
x
Reference in New Issue
Block a user