Browse Source

chore: Normalize implicit backslahes in single quoted strings internally (#7786)

Michael Voříšek 10 months ago
parent
commit
db8c6b0583

+ 1 - 0
.php-cs-fixer.dist.php

@@ -36,6 +36,7 @@ return (new Config())
         'modernize_strpos' => true, // needs PHP 8+ or polyfill
         'no_useless_concat_operator' => false, // TODO switch back on when the `src/Console/Application.php` no longer needs the concat
         'numeric_literal_separator' => true,
+        'string_implicit_backslashes' => true, // https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/7786
     ])
     ->setFinder(
         (new Finder())

+ 1 - 1
src/AbstractPhpdocToTypeDeclarationFixer.php

@@ -34,7 +34,7 @@ use PhpCsFixer\Tokenizer\Tokens;
  */
 abstract class AbstractPhpdocToTypeDeclarationFixer extends AbstractFixer implements ConfigurableFixerInterface
 {
-    private const REGEX_CLASS = '(?:\\\\?+'.TypeExpression::REGEX_IDENTIFIER
+    private const REGEX_CLASS = '(?:\\\?+'.TypeExpression::REGEX_IDENTIFIER
         .'(\\\\'.TypeExpression::REGEX_IDENTIFIER.')*+)';
 
     /**

+ 1 - 1
src/Console/Report/FixReport/ReporterFactory.php

@@ -37,7 +37,7 @@ final class ReporterFactory
             foreach (SymfonyFinder::create()->files()->name('*Reporter.php')->in(__DIR__) as $file) {
                 $relativeNamespace = $file->getRelativePath();
                 $builtInReporters[] = sprintf(
-                    '%s\\%s%s',
+                    '%s\%s%s',
                     __NAMESPACE__,
                     '' !== $relativeNamespace ? $relativeNamespace.'\\' : '',
                     $file->getBasename('.php')

+ 1 - 1
src/Console/Report/ListSetsReport/ReporterFactory.php

@@ -39,7 +39,7 @@ final class ReporterFactory
             foreach (SymfonyFinder::create()->files()->name('*Reporter.php')->in(__DIR__) as $file) {
                 $relativeNamespace = $file->getRelativePath();
                 $builtInReporters[] = sprintf(
-                    '%s\\%s%s',
+                    '%s\%s%s',
                     __NAMESPACE__,
                     '' !== $relativeNamespace ? $relativeNamespace.'\\' : '',
                     $file->getBasename('.php')

+ 2 - 2
src/DocBlock/Line.php

@@ -59,7 +59,7 @@ final class Line
      */
     public function containsUsefulContent(): bool
     {
-        return Preg::match('/\\*\s*\S+/', $this->content) && '' !== trim(str_replace(['/', '*'], ' ', $this->content));
+        return Preg::match('/\*\s*\S+/', $this->content) && '' !== trim(str_replace(['/', '*'], ' ', $this->content));
     }
 
     /**
@@ -69,7 +69,7 @@ final class Line
      */
     public function containsATag(): bool
     {
-        return Preg::match('/\\*\s*@/', $this->content);
+        return Preg::match('/\*\s*@/', $this->content);
     }
 
     /**

+ 3 - 3
src/DocBlock/TypeExpression.php

@@ -147,8 +147,8 @@ final class TypeExpression
                           (?:\.(?&constant_digits)|(?<=\d)\.)?+
                           (?:e[+-]?(?&constant_digits))?+
                     )
-                    | \'(?:[^\'\\\\]|\\\\.)*+\'
-                    | "(?:[^"\\\\]|\\\\.)*+"
+                    | \'(?:[^\'\\\]|\\\.)*+\'
+                    | "(?:[^"\\\]|\\\.)*+"
                     (?-i)
                 )
                 |
@@ -159,7 +159,7 @@ final class TypeExpression
                 )
                 |
                 (?<name> # full name, e.g.: `int`, `\DateTime`, `\Foo\Bar`, `positive-int`
-                    \\\\?+
+                    \\\?+
                     (?<identifier>'.self::REGEX_IDENTIFIER.')
                     (?:[\\\\\-](?&identifier))*+
                 )

+ 2 - 2
src/Doctrine/Annotation/Tokens.php

@@ -246,7 +246,7 @@ final class Tokens extends \SplFixedArray
     public function offsetSet($index, $token): void
     {
         if (null === $token) {
-            throw new \InvalidArgumentException('Token must be an instance of PhpCsFixer\\Doctrine\\Annotation\\Token, "null" given.');
+            throw new \InvalidArgumentException('Token must be an instance of PhpCsFixer\Doctrine\Annotation\Token, "null" given.');
         }
 
         if (!$token instanceof Token) {
@@ -256,7 +256,7 @@ final class Tokens extends \SplFixedArray
                 $type = \get_class($token);
             }
 
-            throw new \InvalidArgumentException(sprintf('Token must be an instance of PhpCsFixer\\Doctrine\\Annotation\\Token, "%s" given.', $type));
+            throw new \InvalidArgumentException(sprintf('Token must be an instance of PhpCsFixer\Doctrine\Annotation\Token, "%s" given.', $type));
         }
 
         parent::offsetSet($index, $token);

+ 1 - 1
src/Documentation/DocumentationLocator.php

@@ -43,7 +43,7 @@ final class DocumentationLocator
     public function getFixerDocumentationFilePath(FixerInterface $fixer): string
     {
         return $this->getFixersDocumentationDirectoryPath().'/'.Preg::replaceCallback(
-            '/^.*\\\\(.+)\\\\(.+)Fixer$/',
+            '/^.*\\\(.+)\\\(.+)Fixer$/',
             static fn (array $matches): string => Utils::camelCaseToUnderscore($matches[1]).'/'.Utils::camelCaseToUnderscore($matches[2]),
             \get_class($fixer)
         ).'.rst';

+ 2 - 2
src/Documentation/FixerDocumentGenerator.php

@@ -256,7 +256,7 @@ final class FixerDocumentGenerator
         $fileName = "`{$className} <./../../../{$fileName}>`_";
 
         $testFileName = Preg::replace('~.*\K/src/(?=Fixer/)~', '/tests/', $fileName);
-        $testFileName = Preg::replace('~PhpCsFixer\\\\\\\\\K(?=Fixer\\\\\\\\)~', 'Tests\\\\\\\\', $testFileName);
+        $testFileName = Preg::replace('~PhpCsFixer\\\\\\\\\K(?=Fixer\\\\\\\)~', 'Tests\\\\\\\\', $testFileName);
         $testFileName = Preg::replace('~(?= <|\.php>)~', 'Test', $testFileName);
 
         $doc .= <<<RST
@@ -317,7 +317,7 @@ final class FixerDocumentGenerator
         $currentGroup = null;
 
         foreach ($fixers as $fixer) {
-            $namespace = Preg::replace('/^.*\\\\(.+)\\\\.+Fixer$/', '$1', \get_class($fixer));
+            $namespace = Preg::replace('/^.*\\\(.+)\\\.+Fixer$/', '$1', \get_class($fixer));
             $group = $overrideGroups[$namespace] ?? Preg::replace('/(?<=[[:lower:]])(?=[[:upper:]])/', ' ', $namespace);
 
             if ($group !== $currentGroup) {

+ 1 - 1
src/Fixer/AttributeNotation/OrderedAttributesFixer.php

@@ -91,7 +91,7 @@ final class OrderedAttributesFixer extends AbstractFixer implements Configurable
 
                         EOL,
                     new VersionSpecification(8_00_00),
-                    ['sort_algorithm' => self::ORDER_CUSTOM, 'order' => ['A\\B\\Qux', 'A\\B\\Bar', 'A\\B\\Corge']],
+                    ['sort_algorithm' => self::ORDER_CUSTOM, 'order' => ['A\B\Qux', 'A\B\Bar', 'A\B\Corge']],
                 ),
             ],
         );

Some files were not shown because too many files changed in this diff