Php_codesniffer: Squiz.Strings.EchoedStrings does not properly fix bracketed statements

Created on 8 Sep 2016  路  4Comments  路  Source: squizlabs/PHP_CodeSniffer

Using the following rules and PHP, PHPCBF makes an error during correction.

<rule ref="Squiz.Strings.EchoedStrings" />
<rule ref="Squiz.WhiteSpace.SemicolonSpacing" />
echo($y) ;

// becomes...

echo $y);

Modifying EchoedStringsSniff.php#L67 and including T_WHITESPACE solves the problem.

// with code extended

echo $y;
Bug

All 4 comments

Debug output from --report=diff -vvv:

*** START FILE FIXING ***
---START FILE CONTENT---
1|<?php
2|echo($y) ;
3|
--- END FILE CONTENT ---
        E: [Line 2] Echoed strings should not be bracketed (Squiz.Strings.EchoedStrings.HasBracket)
        => Changeset started by Squiz_Sniffs_Strings_EchoedStringsSniff (line 89)
            Q: Squiz_Sniffs_Strings_EchoedStringsSniff (line 90) replaced token 2 (T_OPEN_PARENTHESIS) "(" => ""
            Q: Squiz_Sniffs_Strings_EchoedStringsSniff (line 91) replaced token 5 (T_WHITESPACE) "路;" => ";"
            A: Squiz_Sniffs_Strings_EchoedStringsSniff (line 92) replaced token 2 (T_OPEN_PARENTHESIS) "(" => ""
            A: Squiz_Sniffs_Strings_EchoedStringsSniff (line 92) replaced token 5 (T_WHITESPACE) "路;" => ";"
        => Changeset ended: 2 changes applied
        E: [Line 2] Space found before semicolon; expected ");" but found ") ;" (Squiz.WhiteSpace.SemicolonSpacing.Incorrect)
        => Changeset started by Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff (line 90)
            Q: Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff (line 92) replaced token 5 (T_WHITESPACE) ";" => ";"
            * token 5 has already been modified, skipping *
        => Changeset failed to apply
        * fixed 2 violations, starting loop 2 *
---START FILE CONTENT---
1|<?php
2|echo$y);
3|
--- END FILE CONTENT ---
        E: [Line 2] Language constructs must be followed by a single space; expected "echo $y" but found "echo$y" (Squiz.WhiteSpace.LanguageConstructSpacing.Incorrect)
        Squiz_Sniffs_WhiteSpace_LanguageConstructSpacingSniff (line 93) replaced token 1 (T_ECHO) "echo" => "echo路"
        * fixed 1 violations, starting loop 3 *
---START FILE CONTENT---
1|<?php
2|echo $y);
3|
--- END FILE CONTENT ---
*** END FILE FIXING ***

Thanks for the bug report. I found another issue with the fixer that I also corrected (open brace wasn't given a space before it when needed).

Will this be included in v3.0.1?

Will this be included in v3.0.1?

3.0.1 is not the next 3.x release (3.0.0 isn't out yet), but it will be in both the next 2.x and 3.x releases.

Was this page helpful?
0 / 5 - 0 ratings