Skip to content

Commit 81fa72f

Browse files
committed
Feat: Add SimpleToComplexStringVariableFixer for PHP 8.2+ (part of #94)
1 parent 5a6dca0 commit 81fa72f

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
@@ -144,6 +144,7 @@
144144
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
145145
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
146146
use PhpCsFixer\Fixer\StringNotation\MultilineStringToHeredocFixer;
147+
use PhpCsFixer\Fixer\StringNotation\SimpleToComplexStringVariableFixer;
147148
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
148149
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
149150
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
@@ -405,6 +406,8 @@
405406
StrictParamFixer::class,
406407
// Convert multiline string to heredoc or nowdoc.
407408
MultilineStringToHeredocFixer::class,
409+
// Converts explicit variables in double-quoted strings from simple to complex format (${ to {$).
410+
SimpleToComplexStringVariableFixer::class,
408411
// Convert double quotes to single quotes for simple strings
409412
SingleQuoteFixer::class,
410413
// 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)