Skip to content

Commit 0f34419

Browse files
committed
Feat: Add SimpleToComplexStringVariableFixer for PHP 8.2+ (part of #94)
1 parent 5748e6c commit 0f34419

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

ecs.php

+3
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
146146
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
147147
use PhpCsFixer\Fixer\StringNotation\MultilineStringToHeredocFixer;
148+
use PhpCsFixer\Fixer\StringNotation\SimpleToComplexStringVariableFixer;
148149
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
149150
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
150151
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
@@ -408,6 +409,8 @@
408409
StrictComparisonFixer::class,
409410
// Convert multiline string to heredoc or nowdoc.
410411
MultilineStringToHeredocFixer::class,
412+
// Converts explicit variables in double-quoted strings from simple to complex format (${ to {$).
413+
SimpleToComplexStringVariableFixer::class,
411414
// Convert double quotes to single quotes for simple strings
412415
SingleQuoteFixer::class,
413416
// Each element of an array must be indented exactly once.

tests/Integration/CodingStandardTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ public function shouldFixPhp81(): void
5353
);
5454
}
5555

56+
/**
57+
* @test
58+
* @requires PHP >= 8.2
59+
*/
60+
public function shouldFixPhp82(): void
61+
{
62+
$fixedFile = $this->runEcsCheckOnFile(__DIR__ . '/Fixtures/Php82.wrong.php.inc');
63+
64+
$this->assertStringEqualsFile(
65+
__DIR__ . '/Fixtures/Php82.correct.php.inc',
66+
file_get_contents($fixedFile),
67+
);
68+
}
69+
5670
private function runEcsCheckOnFile(string $file): string
5771
{
5872
$fixtureFile = $this->initTempFixtureFile();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Lmc\CodingStandard\Integration\Fixtures;
4+
5+
class Php82
6+
{
7+
public function php82features(): void
8+
{
9+
$name = 'John';
10+
$complexString = "Hello {$name}!";
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Lmc\CodingStandard\Integration\Fixtures;
4+
5+
class Php82
6+
{
7+
public function php82features(): void
8+
{
9+
$name = 'John';
10+
$complexString = "Hello ${name}!";
11+
}
12+
}

0 commit comments

Comments
 (0)