Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Php55] Make StringClassNameToClassConstantRector configurable to kee…
…p first pre-backslash string configurable (#5354)
- Loading branch information
1 parent
68c42e7
commit dc9573d
Showing
4 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...Rector/String_/StringClassNameToClassConstantRector/FixtureKeepPreSlash/pre_slash.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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector\FixtureKeepPreSlash; | ||
|
||
final class PreSlash | ||
{ | ||
public function preSlash() | ||
{ | ||
return '\Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector\Source\AnotherClass'; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector\FixtureKeepPreSlash; | ||
|
||
final class PreSlash | ||
{ | ||
public function preSlash() | ||
{ | ||
return '\\' . \Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector\Source\AnotherClass::class; | ||
} | ||
} | ||
|
||
?> |
28 changes: 28 additions & 0 deletions
28
rules-tests/Php55/Rector/String_/StringClassNameToClassConstantRector/KeepPreSlashTest.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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class KeepPreSlashTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/FixtureKeepPreSlash'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule_keep_pre_slash.php'; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...or/String_/StringClassNameToClassConstantRector/config/configured_rule_keep_pre_slash.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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig | ||
->ruleWithConfiguration(StringClassNameToClassConstantRector::class, [ | ||
'Nette\*', | ||
'Error', | ||
'Exception', | ||
|
||
// keep '\\' prefix string on string '\Foo\Bar' | ||
StringClassNameToClassConstantRector::SHOULD_KEEP_PRE_SLASH => true | ||
]); | ||
}; |
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