Skip to content

Commit

Permalink
use double quote to escape quotes in EncapsedStringsToSprintfRector
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Sep 23, 2024
1 parent a99b50d commit 807e7ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ final class TranslationFunction
}

?>

Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function configure(array $configuration): void
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Convert enscaped {$string} to more readable sprintf or concat, if no mask is used',
'Convert enscaped {$string} to more readable sprintf or concat, if no value is used',
[
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
Expand Down Expand Up @@ -204,7 +204,9 @@ private function createSprintfFuncCallOrConcat(string $mask, array $argumentVari
return null;
}

$arguments = [new Arg(new String_($mask))];
$string = $this->createString($mask);

$arguments = [new Arg($string)];
foreach ($argumentVariables as $argumentVariable) {
$arguments[] = new Arg($argumentVariable);
}
Expand Down Expand Up @@ -239,4 +241,13 @@ private function createSingleValueEdgeConcat(array $argumentVariables, string $m

return null;
}

private function createString(string $value): String_
{
$kind = str_contains($value, '\'') ? String_::KIND_DOUBLE_QUOTED : String_::KIND_SINGLE_QUOTED;

return new String_($value, [
'kind' => $kind,
]);
}
}

0 comments on commit 807e7ed

Please sign in to comment.