From 7850452742417b5afaaa78a848e6b0f85be19a4f Mon Sep 17 00:00:00 2001 From: Matt Kynaston Date: Mon, 29 Apr 2019 12:01:37 +0100 Subject: [PATCH 1/3] Clarified usage of double quotes to match examples, added spaces to string concat examples --- docs/book/v2/ruleset.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/book/v2/ruleset.md b/docs/book/v2/ruleset.md index e4c5d2fb..6907069f 100644 --- a/docs/book/v2/ruleset.md +++ b/docs/book/v2/ruleset.md @@ -953,25 +953,26 @@ Force whitespace before and after concatenation ### Squiz.Strings.DoubleQuoteUsage #### Squiz.Strings.DoubleQuoteUsage.ContainsVar -Double quote strings may only be used if they contain variables. SQL queries containing single quotes are an exception +Double quote strings may only be used if they contain variables, control characters or if using single quotes would +result in more escaped characters than necessary. For instance, SQL queries containing single quotes are an exception to the rule. -*Valid: Double quote strings are only used when it contains a variable.* +*Valid: Double quote strings are only used when it contains a variable, control characters or single quotes.* ```php Date: Tue, 30 Apr 2019 19:14:37 +0100 Subject: [PATCH 2/3] Excluded Squiz.Strings.DoubleQuoteUsage.ContainsVar --- src/ZendCodingStandard/ruleset.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ZendCodingStandard/ruleset.xml b/src/ZendCodingStandard/ruleset.xml index b29cd359..7c75a317 100644 --- a/src/ZendCodingStandard/ruleset.xml +++ b/src/ZendCodingStandard/ruleset.xml @@ -384,9 +384,8 @@ - - - Variable "%s" not allowed in double quoted string; use sprintf() or concatenation instead + + From b95be20890aba16c0532618f74ebb8f49f76050b Mon Sep 17 00:00:00 2001 From: Matt Kynaston Date: Wed, 1 May 2019 10:49:33 +0100 Subject: [PATCH 3/3] Updated docs and added tests --- docs/book/v2/ruleset.md | 3 +-- test/expected-report.txt | 7 ++++--- test/fixable/strings-double-quote-usage.php | 16 ++++++++++++++++ test/fixed/strings-double-quote-usage.php | 16 ++++++++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 test/fixable/strings-double-quote-usage.php create mode 100644 test/fixed/strings-double-quote-usage.php diff --git a/docs/book/v2/ruleset.md b/docs/book/v2/ruleset.md index 6907069f..c7b6c357 100644 --- a/docs/book/v2/ruleset.md +++ b/docs/book/v2/ruleset.md @@ -963,12 +963,11 @@ to the rule. $string = "Hello There\r\n"; $string = "Hello $there"; $string = 'Hello There'; -$string = 'Hello' . ' There' . "\n"; $string = '\$var'; $query = "SELECT * FROM table WHERE name =''"; ``` -*Invalid: There are no variables, control characters inside double quote strings* +*Invalid: There are no variables or control characters inside double quote strings.* ```php