Skip to content

Commit

Permalink
Feat: Add SimpleToComplexStringVariableFixer for PHP 8.2+ (part of #94)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed May 10, 2024
1 parent 5a6dca0 commit 81fa72f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
use PhpCsFixer\Fixer\StringNotation\MultilineStringToHeredocFixer;
use PhpCsFixer\Fixer\StringNotation\SimpleToComplexStringVariableFixer;
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
Expand Down Expand Up @@ -405,6 +406,8 @@
StrictParamFixer::class,
// Convert multiline string to heredoc or nowdoc.
MultilineStringToHeredocFixer::class,
// Converts explicit variables in double-quoted strings from simple to complex format (${ to {$).
SimpleToComplexStringVariableFixer::class,
// Convert double quotes to single quotes for simple strings
SingleQuoteFixer::class,
// Each element of an array must be indented exactly once.
Expand Down
14 changes: 14 additions & 0 deletions tests/Integration/CodingStandardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ public function shouldFixPhp81(): void
);
}

/**
* @test
* @requires PHP >= 8.2
*/
public function shouldFixPhp82(): void
{
$fixedFile = $this->runEcsCheckOnFile(__DIR__ . '/Fixtures/Php82.wrong.php.inc');

$this->assertStringEqualsFile(
__DIR__ . '/Fixtures/Php82.correct.php.inc',
file_get_contents($fixedFile),
);
}

private function runEcsCheckOnFile(string $file): string
{
$fixtureFile = $this->initTempFixtureFile();
Expand Down
12 changes: 12 additions & 0 deletions tests/Integration/Fixtures/Php82.correct.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types=1);

namespace Lmc\CodingStandard\Integration\Fixtures;

class Php82
{
public function php82features(): void
{
$name = 'John';
$complexString = "Hello {$name}!";
}
}
12 changes: 12 additions & 0 deletions tests/Integration/Fixtures/Php82.wrong.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types=1);

namespace Lmc\CodingStandard\Integration\Fixtures;

class Php82
{
public function php82features(): void
{
$name = 'John';
$complexString = "Hello ${name}!";
}
}

0 comments on commit 81fa72f

Please sign in to comment.