Skip to content

Commit

Permalink
#80 - simple to complex string variables
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofrewak committed Oct 3, 2022
1 parent cdca8c1 commit 13ae71f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/Configuration/Defaults/CommonRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
use PhpCsFixer\Fixer\StringNotation\SimpleToComplexStringVariableFixer;
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
use PhpCsFixer\Fixer\Whitespace\CompactNullableTypehintFixer;
use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer;
Expand Down Expand Up @@ -248,5 +249,6 @@ class CommonRules extends Rules
SingleLineAfterImportsFixer::class => true,
SingleLineCommentSpacingFixer::class => true,
BlankLineAfterNamespaceFixer::class => true,
SimpleToComplexStringVariableFixer::class => true,
];
}
2 changes: 1 addition & 1 deletion src/Tools/CodestyleFileInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CodestyleFileInitializer
{
public function run(string $root, string $filename = "codestyle.php"): void
{
$codestyleFilePath = "${root}/${filename}";
$codestyleFilePath = "{$root}/{$filename}";

if (file_exists($codestyleFilePath)) {
fwrite(STDERR, "File codestyle.php already exists.\n");
Expand Down
6 changes: 3 additions & 3 deletions src/Tools/ComposerManifestScriptsInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ComposerManifestScriptsInitializer
{
public function run(string $root): void
{
$composerManifestFile = "${root}/composer.json";
$composerManifestFile = "{$root}/composer.json";

$hasComposerFileChanged = false;
$composer = json_decode(file_get_contents($composerManifestFile), associative: true);
Expand All @@ -19,10 +19,10 @@ public function run(string $root): void

foreach ($scripts as $command => $script) {
if (isset($composer["scripts"][$command])) {
fwrite(STDOUT, "Script ${command} is already declared.\n");
fwrite(STDOUT, "Script {$command} is already declared.\n");
} else {
$composer["scripts"][$command] = $script;
fwrite(STDOUT, "Script ${command} has been added to composer.json file.\n");
fwrite(STDOUT, "Script {$command} has been added to composer.json file.\n");
$hasComposerFileChanged = true;
}
}
Expand Down
14 changes: 7 additions & 7 deletions tests/codestyle/CodestyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function runFixer(bool $fix = false): bool
$application->setAutoExit(false);

$output = new BufferedOutput();
$result = $application->run(new StringInput("fix ${dryRun} --diff --config ./tests/codestyle/config.php"), $output);
$result = $application->run(new StringInput("fix {$dryRun} --diff --config ./tests/codestyle/config.php"), $output);

return $result === 0;
}
Expand All @@ -86,22 +86,22 @@ protected function runFixer(bool $fix = false): bool
*/
protected function testFixture(string $name): void
{
copy(__DIR__ . "/fixtures/${name}/actual.php", __DIR__ . "/tmp/${name}.php");
copy(__DIR__ . "/fixtures/{$name}/actual.php", __DIR__ . "/tmp/{$name}.php");

$this->assertFalse(
$this->runFixer(),
"Fixture fixtures/${name} returned invalid true result.",
"Fixture fixtures/{$name} returned invalid true result.",
);

$this->assertTrue(
$this->runFixer(fix: true),
"Fixture fixtures/${name} was not proceeded properly.",
"Fixture fixtures/{$name} was not proceeded properly.",
);

$this->assertFileEquals(
__DIR__ . "/fixtures/${name}/expected.php",
__DIR__ . "/tmp/${name}.php",
"Result of proceeded fixture fixtures/${name} is not equal to expected.",
__DIR__ . "/fixtures/{$name}/expected.php",
__DIR__ . "/tmp/{$name}.php",
"Result of proceeded fixture fixtures/{$name} is not equal to expected.",
);
}

Expand Down
7 changes: 7 additions & 0 deletions tests/codestyle/fixtures/stringVariables/actual.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

$test = "test";
$concat = "test $test test";
$legacy = "Hello ${test}!";
7 changes: 7 additions & 0 deletions tests/codestyle/fixtures/stringVariables/expected.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

$test = "test";
$concat = "test $test test";
$legacy = "Hello {$test}!";
2 changes: 1 addition & 1 deletion tests/codestyle/fixtures/trailingCommas/actual.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testParameters(
string $a,
string $b
): string {
return "${a}-${b}";
return "{$a}-{$b}";
}

public function testArrays(): array
Expand Down
2 changes: 1 addition & 1 deletion tests/codestyle/fixtures/trailingCommas/expected.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testParameters(
string $a,
string $b,
): string {
return "${a}-${b}";
return "{$a}-{$b}";
}

public function testArrays(): array
Expand Down

0 comments on commit 13ae71f

Please sign in to comment.