EspaceImplicitBackslashesFixer - Fix escaping multiple backslashes

by @julienfalque

Some issues have been detected in this pull request

Issues that can be fixed by applying a patch

Review the proposed patch then download it to apply it manually or execute the following command from the repository root directory:

$ curl https://fabbot.io/patch/FriendsOfPHP/PHP-CS-Fixer/3708/577b477ec913f0cf5a61d3086fb1726dbf17956f/cs.diff | patch -p0
diff -ru src/Fixer/StringNotation/EscapeImplicitBackslashesFixer.php src/Fixer/StringNotation/EscapeImplicitBackslashesFixer.php
--- src/Fixer/StringNotation/EscapeImplicitBackslashesFixer.php	2018-04-16 11:31:44.667707011 +0000
+++ src/Fixer/StringNotation/EscapeImplicitBackslashesFixer.php	2018-04-16 11:31:45.184695372 +0000
@@ -47,21 +47,21 @@
 
         return new FixerDefinition(
             'Escape implicit backslashes in strings and heredocs to ease the understanding of which are special chars interpreted by PHP and which not.',
-            [
+            array(
                 new CodeSample($codeSamble),
                 new CodeSample(
                     $codeSamble,
-                    ['single_quoted' => true]
+                    array('single_quoted' => true)
                 ),
                 new CodeSample(
                     $codeSamble,
-                    ['double_quoted' => false]
+                    array('double_quoted' => false)
                 ),
                 new CodeSample(
                     $codeSamble,
-                    ['heredoc_syntax' => false]
+                    array('heredoc_syntax' => false)
                 ),
-            ],
+            ),
             'In PHP double-quoted strings and heredocs some chars like `n`, `$` or `u` have special meanings if preceded by a backslash '
             .'(and some are special only if followed by other special chars), while a backslash preceding other chars are interpreted like a plain '
             .'backslash. The precise list of those special chars is hard to remember and to identify quickly: this fixer escapes backslashes '
@@ -78,7 +78,7 @@
      */
     public function isCandidate(Tokens $tokens)
     {
-        return $tokens->isAnyTokenKindsFound([T_ENCAPSED_AND_WHITESPACE, T_CONSTANT_ENCAPSED_STRING]);
+        return $tokens->isAnyTokenKindsFound(array(T_ENCAPSED_AND_WHITESPACE, T_CONSTANT_ENCAPSED_STRING));
     }
 
     /**
@@ -105,7 +105,7 @@
             if ($token->equals('"')) {
                 $doubleQuoteOpened = !$doubleQuoteOpened;
             }
-            if (!$token->isGivenKind([T_ENCAPSED_AND_WHITESPACE, T_CONSTANT_ENCAPSED_STRING]) || false === strpos($content, '\\')) {
+            if (!$token->isGivenKind(array(T_ENCAPSED_AND_WHITESPACE, T_CONSTANT_ENCAPSED_STRING)) || false === strpos($content, '\\')) {
                 continue;
             }
 
@@ -137,7 +137,7 @@
 
             $newContent = Preg::replace($regex, '\\\\\\\\$1', $content);
             if ($newContent !== $content) {
-                $tokens[$index] = new Token([$token->getId(), $newContent]);
+                $tokens[$index] = new Token(array($token->getId(), $newContent));
             }
         }
     }
@@ -147,19 +147,19 @@
      */
     protected function createConfigurationDefinition()
     {
-        return new FixerConfigurationResolver([
+        return new FixerConfigurationResolver(array(
             (new FixerOptionBuilder('single_quoted', 'Whether to fix single-quoted strings.'))
-                ->setAllowedTypes(['bool'])
+                ->setAllowedTypes(array('bool'))
                 ->setDefault(false)
                 ->getOption(),
             (new FixerOptionBuilder('double_quoted', 'Whether to fix double-quoted strings.'))
-                ->setAllowedTypes(['bool'])
+                ->setAllowedTypes(array('bool'))
                 ->setDefault(true)
                 ->getOption(),
             (new FixerOptionBuilder('heredoc_syntax', 'Whether to fix heredoc syntax.'))
-                ->setAllowedTypes(['bool'])
+                ->setAllowedTypes(array('bool'))
                 ->setDefault(true)
                 ->getOption(),
-        ]);
+        ));
     }
 }
diff -ru tests/Fixer/StringNotation/EscapeImplicitBackslashesFixerTest.php tests/Fixer/StringNotation/EscapeImplicitBackslashesFixerTest.php
--- tests/Fixer/StringNotation/EscapeImplicitBackslashesFixerTest.php	2018-04-16 11:31:44.796704107 +0000
+++ tests/Fixer/StringNotation/EscapeImplicitBackslashesFixerTest.php	2018-04-16 11:31:45.073697871 +0000
@@ -41,14 +41,14 @@
 
     public function provideTestFixCases()
     {
-        return [
-            [
+        return array(
+            array(
                 <<<'EOF'
 <?php $var = 'String (\\\'\r\n\x0) for My\Prefix\\';
 EOF
                 ,
-            ],
-            [
+            ),
+            array(
                 <<<'EOF'
 <?php $var = 'String (\\\'\\r\\n\\x0) for My\\Prefix\\';
 EOF
@@ -57,9 +57,9 @@
 <?php $var = 'String (\\\'\r\n\x0) for My\Prefix\\';
 EOF
                 ,
-                ['single_quoted' => true],
-            ],
-            [
+                array('single_quoted' => true),
+            ),
+            array(
                 <<<'EOF'
 <?php
 $var = "\\A\\B\\C\\D\\E\\F\\G\\H\\I\\J\\K\\L\\M\\N\\O\\P\\Q\\R\\S\\T\\U\\V\\W\\X\\Y\\Z";
@@ -116,8 +116,8 @@
 
 EOF
                 ,
-            ],
-            [
+            ),
+            array(
                 <<<'EOF'
 <?php
 $var = "\e\f\n\r\t\v \\ \$ \"";
@@ -131,8 +131,8 @@
 
 EOF
                 ,
-            ],
-            [
+            ),
+            array(
                 <<<'EOF'
 <?php
 $var = "\0 \00 \000 \0000 \00000";
@@ -146,8 +146,8 @@
 
 EOF
                 ,
-            ],
-            [
+            ),
+            array(
                 <<<'EOF'
 <?php
 $var = "\xA \x99 \u{0}";
@@ -161,8 +161,8 @@
 
 EOF
                 ,
-            ],
-            [
+            ),
+            array(
                 <<<'EOF'
 <?php
 $var = 'backslash \\ already escaped';
@@ -184,8 +184,8 @@
 
 EOF
                 ,
-            ],
-            [
+            ),
+            array(
                 <<<'EOF'
 <?php
 $var = "\A\a \' \8\9 \xZ \u";
@@ -193,9 +193,9 @@
 EOF
                 ,
                 null,
-                ['double_quoted' => false],
-            ],
-            [
+                array('double_quoted' => false),
+            ),
+            array(
                 <<<'EOF'
 <?php
 $var = <<<HEREDOC_SYNTAX
@@ -220,9 +220,9 @@
 EOF
                 ,
                 null,
-                ['heredoc_syntax' => false],
-            ],
-            [
+                array('heredoc_syntax' => false),
+            ),
+            array(
                 <<<'EOF'
 <?php
 $var = "\\bar";
@@ -243,8 +243,8 @@
 $var = "\\\\\\bar";
 EOF
                 ,
-            ],
-            [
+            ),
+            array(
                 <<<'EOF'
 <?php
 $var = '\\bar';
@@ -265,9 +265,9 @@
 $var = '\\\\\\bar';
 EOF
                 ,
-                ['single_quoted' => true],
-            ],
-            [
+                array('single_quoted' => true),
+            ),
+            array(
                 <<<'EOF'
 <?php
 $var = <<<TXT
@@ -294,8 +294,8 @@
 
 EOF
                 ,
-            ],
-            [
+            ),
+            array(
                 <<<'EOF'
 <?php
 $var = <<<'TXT'
@@ -309,7 +309,7 @@
 
 EOF
                 ,
-            ],
-        ];
+            ),
+        );
     }
 }

0
Common Typos

0
File Permissions