Skip to content

Commit

Permalink
String interpolation: don't suggest sprintf()
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Dec 11, 2022
1 parent 8c3c932 commit c140fc0
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 22 deletions.
3 changes: 0 additions & 3 deletions lib/Doctrine/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,6 @@
</rule>
<!-- Forbid strings in `"` unless necessary -->
<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
<message>Variable "%s" not allowed in double quoted string; use sprintf() or concatenation instead</message>
</rule>
<!-- Forbid braces around string in `echo` -->
<rule ref="Squiz.Strings.EchoedStrings"/>
<!-- Forbid spaces in type casts -->
Expand Down
6 changes: 3 additions & 3 deletions tests/expected_report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ tests/input/semicolon_spacing.php 3 0
tests/input/single-line-array-spacing.php 5 0
tests/input/spread-operator.php 6 0
tests/input/static-closures.php 1 0
tests/input/strings.php 1 0
tests/input/strings.php 3 0
tests/input/superfluous-naming.php 11 0
tests/input/test-case.php 8 0
tests/input/trailing_comma_on_array.php 1 0
Expand All @@ -52,9 +52,9 @@ tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 21 0
----------------------------------------------------------------------
A TOTAL OF 451 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
A TOTAL OF 453 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 374 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 375 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


10 changes: 10 additions & 0 deletions tests/fixed/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@
$doc = <<<'TEXT'
text without special chars
TEXT;

$interpolated = <<<TEXT
HEREDOC with interpolation like $doc is fine.
TEXT;

echo 'This should appear in single quotes.';

echo "This string\tmay appear\nin double quotes.";

echo "String interpolation like $doc should be avoided.";
10 changes: 10 additions & 0 deletions tests/input/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@
$doc = <<<TEXT
text without special chars
TEXT;

$interpolated = <<<TEXT
HEREDOC with interpolation like $doc is fine.
TEXT;

echo "This should appear in single quotes.";

echo "This string\tmay appear\nin double quotes.";

echo "String interpolation like $doc should be avoided.";
8 changes: 4 additions & 4 deletions tests/php72-compatibility.patch
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ index d1e1fad..ea3b611 100644
-tests/input/UselessConditions.php 21 0
+tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 451 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 404 ERRORS AND 0 WARNINGS WERE FOUND IN 44 FILES
-A TOTAL OF 453 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 406 ERRORS AND 0 WARNINGS WERE FOUND IN 44 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 374 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 327 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 375 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 328 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down
8 changes: 4 additions & 4 deletions tests/php73-compatibility.patch
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ index d1e1fad..9a78bc1 100644
-tests/input/UselessConditions.php 21 0
+tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 451 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 406 ERRORS AND 0 WARNINGS WERE FOUND IN 45 FILES
-A TOTAL OF 453 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 408 ERRORS AND 0 WARNINGS WERE FOUND IN 45 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 374 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 329 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 375 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 330 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down
8 changes: 4 additions & 4 deletions tests/php74-compatibility.patch
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ index d1e1fad..ed67841 100644
-tests/input/UselessConditions.php 21 0
+tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 451 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 415 ERRORS AND 0 WARNINGS WERE FOUND IN 45 FILES
-A TOTAL OF 453 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 417 ERRORS AND 0 WARNINGS WERE FOUND IN 45 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 374 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 338 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 375 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 339 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down
8 changes: 4 additions & 4 deletions tests/php80-compatibility.patch
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ index d1e1fad..71022c4 100644
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 21 0
----------------------------------------------------------------------
-A TOTAL OF 451 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 445 ERRORS AND 0 WARNINGS WERE FOUND IN 47 FILES
-A TOTAL OF 453 ERRORS AND 0 WARNINGS WERE FOUND IN 48 FILES
+A TOTAL OF 447 ERRORS AND 0 WARNINGS WERE FOUND IN 47 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 374 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 368 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 375 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 369 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down

0 comments on commit c140fc0

Please sign in to comment.