-
-
Notifications
You must be signed in to change notification settings - Fork 689
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3077 from rectorphp/fix-auto-import
Fix auto import
- Loading branch information
Showing
15 changed files
with
200 additions
and
62 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
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
42 changes: 27 additions & 15 deletions
42
...e/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/Fixture/bootstrap_names.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 |
---|---|---|
@@ -1,30 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
namespace { | ||
function run_me_never() | ||
{ | ||
// silent deprecations, since we test them | ||
error_reporting(E_ALL ^ E_DEPRECATED); | ||
|
||
// performance boost | ||
\SomeNamespace\gc_disable(); | ||
} | ||
} | ||
|
||
function run_me_never() | ||
namespace SomeNamespace | ||
{ | ||
// silent deprecations, since we test them | ||
error_reporting(E_ALL ^ E_DEPRECATED); | ||
|
||
// performance boost | ||
\SomeNamespace\gc_disable(); | ||
function gc_disable() | ||
{} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
declare(strict_types=1); | ||
use function SomeNamespace\gc_disable; | ||
namespace { | ||
use function SomeNamespace\gc_disable; | ||
function run_me_never() | ||
{ | ||
// silent deprecations, since we test them | ||
error_reporting(E_ALL ^ E_DEPRECATED); | ||
|
||
function run_me_never() | ||
{ | ||
// silent deprecations, since we test them | ||
error_reporting(E_ALL ^ E_DEPRECATED); | ||
// performance boost | ||
gc_disable(); | ||
} | ||
} | ||
|
||
// performance boost | ||
gc_disable(); | ||
namespace SomeNamespace | ||
{ | ||
function gc_disable() | ||
{} | ||
} | ||
|
||
?> |
10 changes: 10 additions & 0 deletions
10
...ing-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/Source/AnotherClass.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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SomeAnother; | ||
|
||
final class AnotherClass | ||
{ | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/Source/Foo.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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Foo; | ||
|
||
final class Bar | ||
{ | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/Source/YetAnotherClass.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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SomeAnother; | ||
|
||
final class YetAnotherClass | ||
{ | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...oding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/Source/safe_count.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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Safe; | ||
|
||
function count() | ||
{ | ||
|
||
} | ||
|
||
function substr() | ||
{ | ||
|
||
} |
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
5 changes: 0 additions & 5 deletions
5
...enameClassRector/FixtureAutoImportNames/class_imported_as_alias_without_namespace.php.inc
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
...sts/Rector/Class_/RenameClassRector/FixtureAutoImportNames/double_funciton_import.php.inc
This file was deleted.
Oops, something went wrong.
File renamed without changes.
38 changes: 38 additions & 0 deletions
38
...or/Class_/RenameClassRector/FixtureAutoImportNamesFunction/double_funciton_import.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,38 @@ | ||
<?php | ||
|
||
namespace Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Fixture\FixtureAutoImportNamesParameter; | ||
|
||
class DoubleFunctionImport | ||
{ | ||
public function create() | ||
{ | ||
return \Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Source\some_another_function(1, 2); | ||
} | ||
|
||
public function emulate() | ||
{ | ||
return \Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Source\some_another_function(4, 5); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Fixture\FixtureAutoImportNamesParameter; | ||
|
||
use function Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Source\some_another_function; | ||
class DoubleFunctionImport | ||
{ | ||
public function create() | ||
{ | ||
return some_another_function(1, 2); | ||
} | ||
|
||
public function emulate() | ||
{ | ||
return some_another_function(4, 5); | ||
} | ||
} | ||
|
||
?> |
49 changes: 49 additions & 0 deletions
49
...s/renaming/tests/Rector/Class_/RenameClassRector/FunctionAutoImportNamesParameterTest.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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Renaming\Tests\Rector\Class_\RenameClassRector; | ||
|
||
use Iterator; | ||
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Rector\Renaming\Rector\Class_\RenameClassRector; | ||
use Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Source\NewClass; | ||
use Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Source\OldClass; | ||
|
||
/** | ||
* @see \Rector\CodingStyle\Application\NameImportingCommander | ||
*/ | ||
final class FunctionAutoImportNamesParameterTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureAutoImportNamesFunction'); | ||
} | ||
|
||
protected function getAutoImportNames(): ?bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
protected function getRectorsWithConfiguration(): array | ||
{ | ||
return [ | ||
RenameClassRector::class => [ | ||
'$oldToNewClasses' => [ | ||
OldClass::class => NewClass::class, | ||
], | ||
], | ||
]; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
rules/renaming/tests/Rector/Class_/RenameClassRector/Source/some_another_function.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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Source; | ||
|
||
if (! function_exists('Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Source\some_another_function')) { | ||
function some_another_function() | ||
{ | ||
} | ||
} | ||
|
||
|