-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DowngradePhp73] Handle heredoc new line stripped on multi rules
- Loading branch information
1 parent
0ed4563
commit fe6ddfc
Showing
3 changed files
with
143 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Issues\DowngradeHeredoc; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class DowngradeHeredocTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.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,105 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Issues\DowngradeNullJson\DowngradeHeredoc; | ||
|
||
class Fixture | ||
{ | ||
public function getDefinition(): FixerDefinitionInterface | ||
{ | ||
return new FixerDefinition( | ||
'Sorts attributes using the configured sort algorithm.', | ||
[ | ||
new VersionSpecificCodeSample( | ||
<<<'EOL' | ||
<?php | ||
#[Foo] | ||
#[Bar(3)] | ||
#[Qux(new Bar(5))] | ||
#[Corge(a: 'test')] | ||
class Sample1 {} | ||
#[ | ||
Foo, | ||
Bar(3), | ||
Qux(new Bar(5)), | ||
Corge(a: 'test'), | ||
] | ||
class Sample2 {} | ||
|
||
EOL, | ||
new VersionSpecification(8_00_00), | ||
), | ||
new VersionSpecificCodeSample( | ||
<<<'EOL' | ||
<?php | ||
use A\B\Foo; | ||
use A\B\Bar as BarAlias; | ||
use A\B as AB; | ||
#[Foo] | ||
#[BarAlias(3)] | ||
#[AB\Qux(new Bar(5))] | ||
#[\A\B\Corge(a: 'test')] | ||
class Sample1 {} | ||
|
||
EOL, | ||
new VersionSpecification(8_00_00), | ||
['sort_algorithm' => self::ORDER_CUSTOM, 'order' => ['A\B\Qux', 'A\B\Bar', 'A\B\Corge']], | ||
), | ||
], | ||
); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Issues\DowngradeNullJson\DowngradeHeredoc; | ||
|
||
class Fixture | ||
{ | ||
public function getDefinition(): FixerDefinitionInterface | ||
{ | ||
return new FixerDefinition('Sorts attributes using the configured sort algorithm.', [ | ||
new VersionSpecificCodeSample(<<<'EOL' | ||
<?php | ||
#[Foo] | ||
#[Bar(3)] | ||
#[Qux(new Bar(5))] | ||
#[Corge(a: 'test')] | ||
class Sample1 {} | ||
#[ | ||
Foo, | ||
Bar(3), | ||
Qux(new Bar(5)), | ||
Corge(a: 'test'), | ||
] | ||
class Sample2 {} | ||
|
||
EOL | ||
, new VersionSpecification(80000)), | ||
new VersionSpecificCodeSample(<<<'EOL' | ||
<?php | ||
use A\B\Foo; | ||
use A\B\Bar as BarAlias; | ||
use A\B as AB; | ||
#[Foo] | ||
#[BarAlias(3)] | ||
#[AB\Qux(new Bar(5))] | ||
#[\A\B\Corge(a: 'test')] | ||
class Sample1 {} | ||
|
||
EOL | ||
, new VersionSpecification(80000), ['sort_algorithm' => self::ORDER_CUSTOM, 'order' => ['A\B\Qux', 'A\B\Bar', 'A\B\Corge']]), | ||
]); | ||
} | ||
} | ||
|
||
?> |
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); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Set\ValueObject\DowngradeLevelSetList; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_72]); | ||
}; |