-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new option for auto importing names (#764)
* Add new option for auto importing names - In order to apply the Option::AUTO_IMPORT_NAMES only on those files which are really changed by a rector we introduce this new option * [ci-review] Rector Rectify * Update packages/PostRector/Rector/NameImportingPostRector.php Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com> * [ci-review] Rector Rectify Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
- Loading branch information
1 parent
e22645d
commit 0315a82
Showing
8 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ctor/Namespace_/ImportFullyQualifiedNamesRector/AutoImportNamesOnlyOnChangedFilesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
/** | ||
* @see \Rector\PostRector\Rector\NameImportingPostRector | ||
*/ | ||
final class AutoImportNamesOnlyOnChangedFilesTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
/** | ||
* @return Iterator<SmartFileInfo> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureNameImportingOnChangedFiles'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/import_only_on_changed_files_config.php'; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...dNamesRector/FixtureNameImportingOnChangedFiles/auto_import_names_on_changed_file.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\FixtureNameImportingOnChangedFiles; | ||
|
||
class AutoImportNamesOnChangedFile | ||
{ | ||
/** | ||
* @var \Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Source\NormalParamClass | ||
*/ | ||
private $some; | ||
|
||
public function __construct(\Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Source\NormalParamClass $some) | ||
{ | ||
$this->some = $some; | ||
} | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\FixtureNameImportingOnChangedFiles; | ||
|
||
use Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Source\NormalReturnClass; | ||
class AutoImportNamesOnChangedFile | ||
{ | ||
/** | ||
* @var NormalReturnClass | ||
*/ | ||
private $some; | ||
|
||
public function __construct(NormalReturnClass $some) | ||
{ | ||
$this->some = $some; | ||
} | ||
} | ||
?> |
19 changes: 19 additions & 0 deletions
19
...edNamesRector/FixtureNameImportingOnChangedFiles/skip_auto_import_names_no_change.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\FixtureNameImportingOnChangedFiles; | ||
|
||
class SkipAutoImportNameNoChange | ||
{ | ||
/** | ||
* @var \SomeAnother\AnotherClass | ||
*/ | ||
public $some; | ||
|
||
public function __construct(\SomeAnother\AnotherClass $some) | ||
{ | ||
$this->some = $some; | ||
} | ||
} | ||
?> |
26 changes: 26 additions & 0 deletions
26
...Namespace_/ImportFullyQualifiedNamesRector/config/import_only_on_changed_files_config.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Core\Configuration\Option; | ||
use Rector\Renaming\Rector\Name\RenameClassRector; | ||
|
||
use Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Source\NormalParamClass; | ||
use Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Source\NormalReturnClass; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$parameters = $containerConfigurator->parameters(); | ||
$parameters->set(Option::AUTO_IMPORT_NAMES, true); | ||
$parameters->set(Option::IMPORT_DOC_BLOCKS, true); | ||
$parameters->set(Option::APPLY_AUTO_IMPORT_NAMES_ON_CHANGED_FILES_ONLY, true); | ||
|
||
$services = $containerConfigurator->services(); | ||
|
||
$services->set(RenameClassRector::class) | ||
->call('configure', [[ | ||
RenameClassRector::OLD_TO_NEW_CLASSES => [ | ||
NormalParamClass::class => NormalReturnClass::class, | ||
], | ||
]]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters