From 7c9f4a33cd22ea1f481193296a1f549b77671b9d Mon Sep 17 00:00:00 2001 From: Dorian Villet Date: Fri, 4 Oct 2019 16:59:42 +0200 Subject: [PATCH 1/2] Add documentation for ImportFullyQualifiedNamesRector new '$shouldImportRootNamespaceClasses' argument. --- docs/AllRectorsOverview.md | 71 ++++++++++++++++++- docs/NodesOverview.md | 2 +- .../ImportFullyQualifiedNamesRector.php | 38 ++++++++++ 3 files changed, 107 insertions(+), 4 deletions(-) diff --git a/docs/AllRectorsOverview.md b/docs/AllRectorsOverview.md index 55aed4f877bd..643f1ce7fdc3 100644 --- a/docs/AllRectorsOverview.md +++ b/docs/AllRectorsOverview.md @@ -1,4 +1,4 @@ -# All 367 Rectors Overview +# All 369 Rectors Overview - [Projects](#projects) - [General](#general) @@ -1246,6 +1246,32 @@ Import fully qualified names to use statements } ``` +```yaml +services: + Rector\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector: + $shouldImportRootNamespaceClasses: false +``` + +↓ + +```diff ++use SomeAnother\AnotherClass; ++ + class SomeClass + { + public function create() + { +- return SomeAnother\AnotherClass; ++ return AnotherClass; + } + + public function createDate() + { + return new \DateTime(); // this remains untouched + } + } +``` +
### `MakeInheritedMethodVisibilitySameAsParentRector` @@ -1369,7 +1395,7 @@ services: - class: `Rector\CodingStyle\Rector\Use_\RemoveUnusedAliasRector` -Removes unused use aliases +Removes unused use aliases. Keep annotation aliases like "Doctrine\ORM\Mapping as ORM" to keep convention format ```diff -use Symfony\Kernel as BaseKernel; @@ -1532,6 +1558,25 @@ Prefer quote that not inside the string
+### `UseIncrementAssignRector` + +- class: `Rector\CodingStyle\Rector\Assign\UseIncrementAssignRector` + +Use ++ increment instead of $var += 1. + +```diff + class SomeClass + { + public function run() + { +- $style += 1; ++ ++$style + } + } +``` + +
+ ### `VarConstantCommentRector` - class: `Rector\CodingStyle\Rector\ClassConst\VarConstantCommentRector` @@ -1983,6 +2028,26 @@ Removes method that set values that are never used
+### `RemoveUnreachableStatementRector` + +- class: `Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector` + +Remove unreachable statements + +```diff + class SomeClass + { + public function run() + { + return 5; +- +- $removeMe = 10; + } + } +``` + +
+ ### `RemoveUnusedDoctrineEntityMethodAndPropertyRector` - class: `Rector\DeadCode\Rector\Class_\RemoveUnusedDoctrineEntityMethodAndPropertyRector` @@ -3869,7 +3934,7 @@ Remove 0 from break and continue - class: `Rector\Php55\Rector\FuncCall\PregReplaceEModifierRector` -The /e modifier is no longer supported, use preg_replace_callback instead +The /e modifier is no longer supported, use preg_replace_callback instead ```diff class SomeClass diff --git a/docs/NodesOverview.md b/docs/NodesOverview.md index b920efe543d0..9c57df3b2352 100644 --- a/docs/NodesOverview.md +++ b/docs/NodesOverview.md @@ -917,7 +917,7 @@ if (true) { ```php ?> -feelfeel diff --git a/packages/CodingStyle/src/Rector/Namespace_/ImportFullyQualifiedNamesRector.php b/packages/CodingStyle/src/Rector/Namespace_/ImportFullyQualifiedNamesRector.php index 32912c6ae938..8e6e189bf0a5 100644 --- a/packages/CodingStyle/src/Rector/Namespace_/ImportFullyQualifiedNamesRector.php +++ b/packages/CodingStyle/src/Rector/Namespace_/ImportFullyQualifiedNamesRector.php @@ -7,6 +7,7 @@ use Rector\CodingStyle\Node\NameImporter; use Rector\Rector\AbstractRector; use Rector\RectorDefinition\CodeSample; +use Rector\RectorDefinition\ConfiguredCodeSample; use Rector\RectorDefinition\RectorDefinition; /** @@ -65,6 +66,43 @@ public function create() } PHP ), + new ConfiguredCodeSample( + <<<'PHP' +class SomeClass +{ + public function create() + { + return SomeAnother\AnotherClass; + } + + public function createDate() + { + return new \DateTime(); // this remains untouched + } +} +PHP + , + <<<'PHP' +use SomeAnother\AnotherClass; + +class SomeClass +{ + public function create() + { + return AnotherClass; + } + + public function createDate() + { + return new \DateTime(); // this remains untouched + } +} +PHP + , + [ + '$shouldImportRootNamespaceClasses' => false, + ] + ), ]); } From 3296681cb11361db4a4157515063e1db74bbce18 Mon Sep 17 00:00:00 2001 From: Dorian Villet Date: Fri, 4 Oct 2019 17:01:46 +0200 Subject: [PATCH 2/2] Create a better contrast between the two examples. --- docs/AllRectorsOverview.md | 7 +++++++ .../Namespace_/ImportFullyQualifiedNamesRector.php | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/docs/AllRectorsOverview.md b/docs/AllRectorsOverview.md index 643f1ce7fdc3..e4c69191307e 100644 --- a/docs/AllRectorsOverview.md +++ b/docs/AllRectorsOverview.md @@ -1235,6 +1235,7 @@ Import fully qualified names to use statements ```diff +use SomeAnother\AnotherClass; ++use DateTime; + class SomeClass { @@ -1243,6 +1244,12 @@ Import fully qualified names to use statements - return SomeAnother\AnotherClass; + return AnotherClass; } + + public function createDate() + { +- return new \DateTime(); ++ return new DateTime(); + } } ``` diff --git a/packages/CodingStyle/src/Rector/Namespace_/ImportFullyQualifiedNamesRector.php b/packages/CodingStyle/src/Rector/Namespace_/ImportFullyQualifiedNamesRector.php index 8e6e189bf0a5..038667977bfe 100644 --- a/packages/CodingStyle/src/Rector/Namespace_/ImportFullyQualifiedNamesRector.php +++ b/packages/CodingStyle/src/Rector/Namespace_/ImportFullyQualifiedNamesRector.php @@ -51,11 +51,17 @@ public function create() { return SomeAnother\AnotherClass; } + + public function createDate() + { + return new \DateTime(); + } } PHP , <<<'PHP' use SomeAnother\AnotherClass; +use DateTime; class SomeClass { @@ -63,6 +69,11 @@ public function create() { return AnotherClass; } + + public function createDate() + { + return new DateTime(); + } } PHP ),