diff --git a/composer.json b/composer.json index 2819f50cd2d..e215566c2fb 100644 --- a/composer.json +++ b/composer.json @@ -87,6 +87,7 @@ "Rector\\JMS\\": "rules/jms/src", "Rector\\Laravel\\": "rules/laravel/src", "Rector\\Legacy\\": "rules/legacy/src", + "Rector\\MagicDisclosure\\": "rules/magic-disclosure/src", "Rector\\MysqlToMysqli\\": "rules/mysql-to-mysqli/src", "Rector\\NetteTesterToPHPUnit\\": "rules/nette-tester-to-phpunit/src", "Rector\\NetteToSymfony\\": "rules/nette-to-symfony/src", @@ -165,6 +166,7 @@ "Rector\\JMS\\Tests\\": "rules/jms/tests", "Rector\\Laravel\\Tests\\": "rules/laravel/tests", "Rector\\Legacy\\Tests\\": "rules/legacy/tests", + "Rector\\MagicDisclosure\\Tests\\": "rules/magic-disclosure/tests", "Rector\\MysqlToMysqli\\Tests\\": "rules/mysql-to-mysqli/tests", "Rector\\NetteTesterToPHPUnit\\Tests\\": "rules/nette-tester-to-phpunit/tests", "Rector\\NetteToSymfony\\Tests\\": "rules/nette-to-symfony/tests", diff --git a/docs/rector_rules_overview.md b/docs/rector_rules_overview.md index 5967f50ed62..604f5a03ef5 100644 --- a/docs/rector_rules_overview.md +++ b/docs/rector_rules_overview.md @@ -23,6 +23,7 @@ - [JMS](#jms) (2) - [Laravel](#laravel) (6) - [Legacy](#legacy) (2) +- [MagicDisclosure](#magicdisclosure) (1) - [MockistaToMockery](#mockistatomockery) (2) - [MysqlToMysqli](#mysqltomysqli) (4) - [Naming](#naming) (1) @@ -4498,6 +4499,25 @@ Change functions to static calls, so composer can autoload them

+## MagicDisclosure + +### `DefluentMethodCallRector` + +- class: [`Rector\MagicDisclosure\Rector\MethodCall\DefluentMethodCallRector`](/../master/rules/magic-disclosure/src/Rector/MethodCall/DefluentMethodCallRector.php) +- [test fixtures](/../master/rules/magic-disclosure/tests/Rector/MethodCall/DefluentMethodCallRector/Fixture) + +Turns fluent interface calls to classic ones. + +```diff + $someClass = new SomeClass(); +-$someClass->someFunction() +- ->otherFunction(); ++$someClass->someFunction(); ++$someClass->otherFunction(); +``` + +

+ ## MockistaToMockery ### `MockeryTearDownRector` @@ -11220,7 +11240,7 @@ Change @return types and type from static analysis to type declarations if not a ## General -- [Core](#core) (44) +- [Core](#core) (43) ## Core @@ -11592,23 +11612,6 @@ services:

-### `DefluentMethodCallRector` - -- class: [`Rector\Core\Rector\MethodCall\DefluentMethodCallRector`](/../master/src/Rector/MethodCall/DefluentMethodCallRector.php) -- [test fixtures](/../master/tests/Rector/MethodCall/DefluentMethodCallRector/Fixture) - -Turns fluent interface calls to classic ones. - -```diff - $someClass = new SomeClass(); --$someClass->someFunction() -- ->otherFunction(); -+$someClass->someFunction(); -+$someClass->otherFunction(); -``` - -

- ### `FunctionToMethodCallRector` - class: [`Rector\Core\Rector\Function_\FunctionToMethodCallRector`](/../master/src/Rector/Function_/FunctionToMethodCallRector.php) diff --git a/rules/magic-disclosure/config/config.yaml b/rules/magic-disclosure/config/config.yaml new file mode 100644 index 00000000000..38f925d0923 --- /dev/null +++ b/rules/magic-disclosure/config/config.yaml @@ -0,0 +1,10 @@ +services: + _defaults: + public: true + autowire: true + + Rector\MagicDisclosure\: + resource: '../src' + exclude: + - '../src/Rector/**/*Rector.php' + - '../src/ValueObject/*' diff --git a/src/Rector/MethodCall/DefluentMethodCallRector.php b/rules/magic-disclosure/src/Rector/MethodCall/DefluentMethodCallRector.php similarity index 95% rename from src/Rector/MethodCall/DefluentMethodCallRector.php rename to rules/magic-disclosure/src/Rector/MethodCall/DefluentMethodCallRector.php index 93f123e2acb..c39ce156bc9 100644 --- a/src/Rector/MethodCall/DefluentMethodCallRector.php +++ b/rules/magic-disclosure/src/Rector/MethodCall/DefluentMethodCallRector.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\Core\Rector\MethodCall; +namespace Rector\MagicDisclosure\Rector\MethodCall; use PhpParser\Node; use PhpParser\Node\Expr; @@ -19,7 +19,10 @@ use Rector\Core\ValueObject\AssignAndRootExpr; use Rector\NodeTypeResolver\Node\AttributeKey; /** - * @see \Rector\Core\Tests\Rector\MethodCall\DefluentMethodCallRector\DefluentMethodCallRectorTest + * @see https://ocramius.github.io/blog/fluent-interfaces-are-evil/ + * @see https://www.yegor256.com/2018/03/13/fluent-interfaces.html + * + * @see \Rector\MagicDisclosure\Tests\Rector\MethodCall\DefluentMethodCallRector\DefluentMethodCallRectorTest */ final class DefluentMethodCallRector extends AbstractRector { diff --git a/tests/Rector/MethodCall/DefluentMethodCallRector/DefluentMethodCallRectorTest.php b/rules/magic-disclosure/tests/Rector/MethodCall/DefluentMethodCallRector/DefluentMethodCallRectorTest.php similarity index 74% rename from tests/Rector/MethodCall/DefluentMethodCallRector/DefluentMethodCallRectorTest.php rename to rules/magic-disclosure/tests/Rector/MethodCall/DefluentMethodCallRector/DefluentMethodCallRectorTest.php index 410ef22f7ea..be551cc5adb 100644 --- a/tests/Rector/MethodCall/DefluentMethodCallRector/DefluentMethodCallRectorTest.php +++ b/rules/magic-disclosure/tests/Rector/MethodCall/DefluentMethodCallRector/DefluentMethodCallRectorTest.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace Rector\Core\Tests\Rector\MethodCall\DefluentMethodCallRector; +namespace Rector\MagicDisclosure\Tests\Rector\MethodCall\DefluentMethodCallRector; use Iterator; -use Rector\Core\Rector\MethodCall\DefluentMethodCallRector; use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase; -use Rector\Core\Tests\Rector\MethodCall\DefluentMethodCallRector\Source\FluentInterfaceClassInterface; +use Rector\MagicDisclosure\Rector\MethodCall\DefluentMethodCallRector; +use Rector\MagicDisclosure\Tests\Rector\MethodCall\DefluentMethodCallRector\Source\FluentInterfaceClassInterface; use Symplify\SmartFileSystem\SmartFileInfo; final class DefluentMethodCallRectorTest extends AbstractRectorTestCase diff --git a/tests/Rector/MethodCall/DefluentMethodCallRector/Fixture/fixture.php.inc b/rules/magic-disclosure/tests/Rector/MethodCall/DefluentMethodCallRector/Fixture/fixture.php.inc similarity index 60% rename from tests/Rector/MethodCall/DefluentMethodCallRector/Fixture/fixture.php.inc rename to rules/magic-disclosure/tests/Rector/MethodCall/DefluentMethodCallRector/Fixture/fixture.php.inc index 1b5fa11b0e2..4d0afd575b7 100644 --- a/tests/Rector/MethodCall/DefluentMethodCallRector/Fixture/fixture.php.inc +++ b/rules/magic-disclosure/tests/Rector/MethodCall/DefluentMethodCallRector/Fixture/fixture.php.inc @@ -1,8 +1,8 @@