From 3998382717aad0bafc3a51f79c5fba4a2279c7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Mon, 29 Jan 2024 13:07:24 +0100 Subject: [PATCH 1/4] norm backslashes in single quoted strings --- doc/ruleSets/PhpCsFixer.rst | 5 +---- doc/rules/string_notation/string_implicit_backslashes.rst | 5 +---- src/RuleSet/Sets/PhpCsFixerSet.php | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/doc/ruleSets/PhpCsFixer.rst b/doc/ruleSets/PhpCsFixer.rst index c9bb1a3254d..8a0ab5b0e1a 100644 --- a/doc/ruleSets/PhpCsFixer.rst +++ b/doc/ruleSets/PhpCsFixer.rst @@ -66,10 +66,7 @@ Rules - `self_static_accessor <./../rules/class_notation/self_static_accessor.rst>`_ - `single_line_comment_style <./../rules/comment/single_line_comment_style.rst>`_ - `single_line_empty_body <./../rules/basic/single_line_empty_body.rst>`_ -- `string_implicit_backslashes <./../rules/string_notation/string_implicit_backslashes.rst>`_ with config: - - ``['single_quoted' => 'ignore']`` - +- `string_implicit_backslashes <./../rules/string_notation/string_implicit_backslashes.rst>`_ - `whitespace_after_comma_in_array <./../rules/array_notation/whitespace_after_comma_in_array.rst>`_ with config: ``['ensure_single_space' => true]`` diff --git a/doc/rules/string_notation/string_implicit_backslashes.rst b/doc/rules/string_notation/string_implicit_backslashes.rst index c615ca80148..a4fd82061f1 100644 --- a/doc/rules/string_notation/string_implicit_backslashes.rst +++ b/doc/rules/string_notation/string_implicit_backslashes.rst @@ -144,10 +144,7 @@ Rule sets The rule is part of the following rule set: -- `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config: - - ``['single_quoted' => 'ignore']`` - +- `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ References ---------- diff --git a/src/RuleSet/Sets/PhpCsFixerSet.php b/src/RuleSet/Sets/PhpCsFixerSet.php index e90a02dd807..8770cbada8b 100644 --- a/src/RuleSet/Sets/PhpCsFixerSet.php +++ b/src/RuleSet/Sets/PhpCsFixerSet.php @@ -119,7 +119,7 @@ public function getRules(): array 'single_line_comment_style' => true, 'single_line_empty_body' => true, 'single_line_throw' => false, - 'string_implicit_backslashes' => ['single_quoted' => 'ignore'], + 'string_implicit_backslashes' => true, 'whitespace_after_comma_in_array' => ['ensure_single_space' => true], ]; } From a412f84b2fb5baa8cd053487cf8c41bfa4c49645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Mon, 29 Apr 2024 15:42:48 +0200 Subject: [PATCH 2/4] Revert "norm backslashes in single quoted strings" --- doc/ruleSets/PhpCsFixer.rst | 5 ++++- doc/rules/string_notation/string_implicit_backslashes.rst | 5 ++++- src/RuleSet/Sets/PhpCsFixerSet.php | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/doc/ruleSets/PhpCsFixer.rst b/doc/ruleSets/PhpCsFixer.rst index 8a0ab5b0e1a..c9bb1a3254d 100644 --- a/doc/ruleSets/PhpCsFixer.rst +++ b/doc/ruleSets/PhpCsFixer.rst @@ -66,7 +66,10 @@ Rules - `self_static_accessor <./../rules/class_notation/self_static_accessor.rst>`_ - `single_line_comment_style <./../rules/comment/single_line_comment_style.rst>`_ - `single_line_empty_body <./../rules/basic/single_line_empty_body.rst>`_ -- `string_implicit_backslashes <./../rules/string_notation/string_implicit_backslashes.rst>`_ +- `string_implicit_backslashes <./../rules/string_notation/string_implicit_backslashes.rst>`_ with config: + + ``['single_quoted' => 'ignore']`` + - `whitespace_after_comma_in_array <./../rules/array_notation/whitespace_after_comma_in_array.rst>`_ with config: ``['ensure_single_space' => true]`` diff --git a/doc/rules/string_notation/string_implicit_backslashes.rst b/doc/rules/string_notation/string_implicit_backslashes.rst index a4fd82061f1..c615ca80148 100644 --- a/doc/rules/string_notation/string_implicit_backslashes.rst +++ b/doc/rules/string_notation/string_implicit_backslashes.rst @@ -144,7 +144,10 @@ Rule sets The rule is part of the following rule set: -- `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ +- `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config: + + ``['single_quoted' => 'ignore']`` + References ---------- diff --git a/src/RuleSet/Sets/PhpCsFixerSet.php b/src/RuleSet/Sets/PhpCsFixerSet.php index 8770cbada8b..e90a02dd807 100644 --- a/src/RuleSet/Sets/PhpCsFixerSet.php +++ b/src/RuleSet/Sets/PhpCsFixerSet.php @@ -119,7 +119,7 @@ public function getRules(): array 'single_line_comment_style' => true, 'single_line_empty_body' => true, 'single_line_throw' => false, - 'string_implicit_backslashes' => true, + 'string_implicit_backslashes' => ['single_quoted' => 'ignore'], 'whitespace_after_comma_in_array' => ['ensure_single_space' => true], ]; } From 8d6c8e7e0bdb0f0ed0440cf9d2c9de439569da2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Mon, 22 Apr 2024 18:16:15 +0200 Subject: [PATCH 3/4] configure locally only --- .php-cs-fixer.dist.php | 1 + 1 file changed, 1 insertion(+) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index e16e47480cc..0e786c4c8a5 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -36,6 +36,7 @@ '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()) From fc760e00d252632570f0cc17a80a649edc3cb2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sun, 21 Apr 2024 10:38:15 +0200 Subject: [PATCH 4/4] run fixer --- src/AbstractPhpdocToTypeDeclarationFixer.php | 2 +- .../Report/FixReport/ReporterFactory.php | 2 +- .../Report/ListSetsReport/ReporterFactory.php | 2 +- src/DocBlock/Line.php | 4 +-- src/DocBlock/TypeExpression.php | 6 ++-- src/Doctrine/Annotation/Tokens.php | 4 +-- src/Documentation/DocumentationLocator.php | 2 +- src/Documentation/FixerDocumentGenerator.php | 4 +-- .../OrderedAttributesFixer.php | 2 +- .../Basic/NonPrintableCharacterFixer.php | 2 +- src/Fixer/Basic/PsrAutoloadingFixer.php | 2 +- src/Fixer/ClassNotation/OrderedTypesFixer.php | 2 +- src/Fixer/ClassNotation/SelfAccessorFixer.php | 2 +- src/Fixer/Comment/CommentToPhpdocFixer.php | 2 +- .../MultilineCommentOpeningClosingFixer.php | 4 +-- .../Import/FullyQualifiedStrictTypesFixer.php | 2 +- src/Fixer/Import/NoUnusedImportsFixer.php | 2 +- .../NamespaceNotation/CleanNamespaceFixer.php | 2 +- src/Fixer/PhpUnit/PhpUnitAttributesFixer.php | 6 ++-- .../PhpUnit/PhpUnitFqcnAnnotationFixer.php | 2 +- .../PhpUnit/PhpUnitMethodCasingFixer.php | 4 +-- .../PhpUnit/PhpUnitTestAnnotationFixer.php | 4 +-- .../PhpUnitTestClassRequiresCoversFixer.php | 4 +-- src/Fixer/Phpdoc/PhpdocListTypeFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocSeparationFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocToCommentFixer.php | 2 +- .../StringNotation/HeredocToNowdocFixer.php | 4 +-- .../MultilineStringToHeredocFixer.php | 6 ++-- .../SimpleToComplexStringVariableFixer.php | 4 +-- src/Fixer/StringNotation/SingleQuoteFixer.php | 4 +-- .../Whitespace/NoTrailingWhitespaceFixer.php | 2 +- src/FixerFactory.php | 2 +- .../Analyzer/DataProviderAnalyzer.php | 2 +- src/Tokenizer/Transformers.php | 2 +- tests/AutoReview/ProjectCodeTest.php | 8 ++--- tests/Console/ApplicationTest.php | 4 +-- tests/Differ/AbstractDifferTestCase.php | 4 +-- tests/DocBlock/TypeExpressionTest.php | 30 ++++++++-------- .../Alias/RandomApiMigrationFixerTest.php | 16 ++++----- .../Basic/NonPrintableCharacterFixerTest.php | 4 +-- tests/Fixer/Basic/PsrAutoloadingFixerTest.php | 26 +++++++------- .../ClassReferenceNameCasingFixerTest.php | 4 +-- .../ModernizeTypesCastingFixerTest.php | 12 +++---- .../ClassNotation/OrderedTraitsFixerTest.php | 2 +- .../NativeConstantInvocationFixerTest.php | 36 +++++++++---------- .../NoBreakCommentFixerTest.php | 8 ++--- .../NoUnneededBracesFixerTest.php | 2 +- .../NoUnneededCurlyBracesFixerTest.php | 2 +- .../PhpdocToParamTypeFixerTest.php | 4 +-- .../PhpdocToPropertyTypeFixerTest.php | 2 +- .../PhpdocToReturnTypeFixerTest.php | 4 +-- .../RegularCallableCallFixerTest.php | 6 ++-- .../SingleLineThrowFixerTest.php | 8 ++--- .../SingleLineAfterImportsFixerTest.php | 6 ++-- .../ClassKeywordFixerTest.php | 8 ++--- .../ClassKeywordRemoveFixerTest.php | 18 +++++----- .../DirConstantFixerTest.php | 8 ++--- .../LanguageConstruct/IsNullFixerTest.php | 20 +++++------ .../BlankLineAfterNamespaceFixerTest.php | 2 +- .../PhpUnit/PhpUnitAttributesFixerTest.php | 4 +-- ...hpUnitNoExpectationAnnotationFixerTest.php | 2 +- .../PhpUnitTestAnnotationFixerTest.php | 8 ++--- .../StringNotation/SingleQuoteFixerTest.php | 10 +++--- tests/FixerFactoryTest.php | 2 +- .../ProcessLinterProcessBuilderTest.php | 4 +-- tests/PregTest.php | 2 +- tests/RuleSet/Sets/AbstractSetTestCase.php | 2 +- tests/Smoke/InstallViaComposerTest.php | 2 +- tests/Test/AbstractFixerTestCase.php | 2 +- tests/Test/AbstractTransformerTestCase.php | 2 +- .../Analysis/AttributeAnalysisTest.php | 4 +-- .../Analyzer/AttributeAnalyzerTest.php | 32 ++++++++--------- .../Processor/ImportProcessorTest.php | 14 ++++---- .../Transformer/ImportTransformerTest.php | 4 +-- .../NameQualifiedTransformerTest.php | 2 +- 75 files changed, 220 insertions(+), 220 deletions(-) diff --git a/src/AbstractPhpdocToTypeDeclarationFixer.php b/src/AbstractPhpdocToTypeDeclarationFixer.php index 0f427f093e0..4e50a6789cf 100644 --- a/src/AbstractPhpdocToTypeDeclarationFixer.php +++ b/src/AbstractPhpdocToTypeDeclarationFixer.php @@ -34,7 +34,7 @@ */ abstract class AbstractPhpdocToTypeDeclarationFixer extends AbstractFixer implements ConfigurableFixerInterface { - private const REGEX_CLASS = '(?:\\\\?+'.TypeExpression::REGEX_IDENTIFIER + private const REGEX_CLASS = '(?:\\\?+'.TypeExpression::REGEX_IDENTIFIER .'(\\\\'.TypeExpression::REGEX_IDENTIFIER.')*+)'; /** diff --git a/src/Console/Report/FixReport/ReporterFactory.php b/src/Console/Report/FixReport/ReporterFactory.php index e4efd9907f2..86855df254a 100644 --- a/src/Console/Report/FixReport/ReporterFactory.php +++ b/src/Console/Report/FixReport/ReporterFactory.php @@ -37,7 +37,7 @@ public function registerBuiltInReporters(): self 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') diff --git a/src/Console/Report/ListSetsReport/ReporterFactory.php b/src/Console/Report/ListSetsReport/ReporterFactory.php index 45f2a26f27d..0d0ae6da883 100644 --- a/src/Console/Report/ListSetsReport/ReporterFactory.php +++ b/src/Console/Report/ListSetsReport/ReporterFactory.php @@ -39,7 +39,7 @@ public function registerBuiltInReporters(): self 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') diff --git a/src/DocBlock/Line.php b/src/DocBlock/Line.php index 1e6fa5b9498..9ef4a087404 100644 --- a/src/DocBlock/Line.php +++ b/src/DocBlock/Line.php @@ -59,7 +59,7 @@ public function getContent(): string */ 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 @@ public function containsUsefulContent(): bool */ public function containsATag(): bool { - return Preg::match('/\\*\s*@/', $this->content); + return Preg::match('/\*\s*@/', $this->content); } /** diff --git a/src/DocBlock/TypeExpression.php b/src/DocBlock/TypeExpression.php index a8577f3468e..44b89bb84c7 100644 --- a/src/DocBlock/TypeExpression.php +++ b/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 ) | (? # full name, e.g.: `int`, `\DateTime`, `\Foo\Bar`, `positive-int` - \\\\?+ + \\\?+ (?'.self::REGEX_IDENTIFIER.') (?:[\\\\\-](?&identifier))*+ ) diff --git a/src/Doctrine/Annotation/Tokens.php b/src/Doctrine/Annotation/Tokens.php index 12d8ac5cb4d..298cd6d8eaa 100644 --- a/src/Doctrine/Annotation/Tokens.php +++ b/src/Doctrine/Annotation/Tokens.php @@ -246,7 +246,7 @@ public function insertAt(int $index, Token $token): void 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 @@ public function offsetSet($index, $token): void $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); diff --git a/src/Documentation/DocumentationLocator.php b/src/Documentation/DocumentationLocator.php index fb35fe43510..3769c4fdeab 100644 --- a/src/Documentation/DocumentationLocator.php +++ b/src/Documentation/DocumentationLocator.php @@ -43,7 +43,7 @@ public function getFixersDocumentationIndexFilePath(): string 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'; diff --git a/src/Documentation/FixerDocumentGenerator.php b/src/Documentation/FixerDocumentGenerator.php index e875752e019..68bff9a6aab 100644 --- a/src/Documentation/FixerDocumentGenerator.php +++ b/src/Documentation/FixerDocumentGenerator.php @@ -256,7 +256,7 @@ public function generateFixerDocumentation(FixerInterface $fixer): string $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 .= << 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']], ), ], ); diff --git a/src/Fixer/Basic/NonPrintableCharacterFixer.php b/src/Fixer/Basic/NonPrintableCharacterFixer.php index d150cb5f8d9..61dffe300a9 100644 --- a/src/Fixer/Basic/NonPrintableCharacterFixer.php +++ b/src/Fixer/Basic/NonPrintableCharacterFixer.php @@ -144,7 +144,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } if ($stringTypeChanged) { - $content = Preg::replace('/(\\\\{1,2})/', '\\\\\\\\', $content); + $content = Preg::replace('/(\\\{1,2})/', '\\\\\\\\', $content); $content = str_replace('$', '\$', $content); } diff --git a/src/Fixer/Basic/PsrAutoloadingFixer.php b/src/Fixer/Basic/PsrAutoloadingFixer.php index 2f31f540fe9..db42b6971f7 100644 --- a/src/Fixer/Basic/PsrAutoloadingFixer.php +++ b/src/Fixer/Basic/PsrAutoloadingFixer.php @@ -127,7 +127,7 @@ public function supports(\SplFileInfo $file): bool } // ignore stubs/fixtures, since they typically contain invalid files for various reasons - return !Preg::match('{[/\\\\](stub|fixture)s?[/\\\\]}i', $file->getRealPath()); + return !Preg::match('{[/\\\](stub|fixture)s?[/\\\]}i', $file->getRealPath()); } protected function createConfigurationDefinition(): FixerConfigurationResolverInterface diff --git a/src/Fixer/ClassNotation/OrderedTypesFixer.php b/src/Fixer/ClassNotation/OrderedTypesFixer.php index b7e58f565f2..a327a448c7c 100644 --- a/src/Fixer/ClassNotation/OrderedTypesFixer.php +++ b/src/Fixer/ClassNotation/OrderedTypesFixer.php @@ -342,7 +342,7 @@ private function collectUnionOrIntersectionTypes(string $type): array */ private function runTypesThroughSortingAlgorithm(array $types): array { - $normalizeType = static fn (string $type): string => Preg::replace('/^\\\\?/', '', $type); + $normalizeType = static fn (string $type): string => Preg::replace('/^\\\?/', '', $type); usort($types, function ($a, $b) use ($normalizeType): int { if (\is_array($a)) { diff --git a/src/Fixer/ClassNotation/SelfAccessorFixer.php b/src/Fixer/ClassNotation/SelfAccessorFixer.php index 1ad573c991f..7150b6bbd98 100644 --- a/src/Fixer/ClassNotation/SelfAccessorFixer.php +++ b/src/Fixer/ClassNotation/SelfAccessorFixer.php @@ -184,7 +184,7 @@ private function getClassStart(Tokens $tokens, int $index, string $namespace): ? { $namespace = ('' !== $namespace ? '\\'.$namespace : '').'\\'; - foreach (array_reverse(Preg::split('/(\\\\)/', $namespace, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE)) as $piece) { + foreach (array_reverse(Preg::split('/(\\\)/', $namespace, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE)) as $piece) { $index = $tokens->getPrevMeaningfulToken($index); if ('\\' === $piece) { if (!$tokens[$index]->isGivenKind(T_NS_SEPARATOR)) { diff --git a/src/Fixer/Comment/CommentToPhpdocFixer.php b/src/Fixer/Comment/CommentToPhpdocFixer.php index aedaa12b674..3b29e04c09a 100644 --- a/src/Fixer/Comment/CommentToPhpdocFixer.php +++ b/src/Fixer/Comment/CommentToPhpdocFixer.php @@ -134,7 +134,7 @@ function (bool $carry, int $index) use ($tokens): bool { if ($carry) { return true; } - if (!Preg::match('~(?:#|//|/\*+|\R(?:\s*\*)?)\s*\@([a-zA-Z0-9_\\\\-]+)(?=\s|\(|$)~', $tokens[$index]->getContent(), $matches)) { + if (!Preg::match('~(?:#|//|/\*+|\R(?:\s*\*)?)\s*\@([a-zA-Z0-9_\\\-]+)(?=\s|\(|$)~', $tokens[$index]->getContent(), $matches)) { return false; } diff --git a/src/Fixer/Comment/MultilineCommentOpeningClosingFixer.php b/src/Fixer/Comment/MultilineCommentOpeningClosingFixer.php index dc4b7dc3322..055c701bb1c 100644 --- a/src/Fixer/Comment/MultilineCommentOpeningClosingFixer.php +++ b/src/Fixer/Comment/MultilineCommentOpeningClosingFixer.php @@ -75,11 +75,11 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // Fix opening if ($token->isGivenKind(T_COMMENT)) { - $newContent = Preg::replace('/^\\/\\*{2,}(?!\\/)/', '/*', $newContent); + $newContent = Preg::replace('/^\/\*{2,}(?!\/)/', '/*', $newContent); } // Fix closing - $newContent = Preg::replace('/(?getId(), $newContent]); diff --git a/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php b/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php index b0ee95f21cd..001839669ab 100644 --- a/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php +++ b/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php @@ -43,7 +43,7 @@ */ final class FullyQualifiedStrictTypesFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface { - private const REGEX_CLASS = '(?:\\\\?+'.TypeExpression::REGEX_IDENTIFIER + private const REGEX_CLASS = '(?:\\\?+'.TypeExpression::REGEX_IDENTIFIER .'(\\\\'.TypeExpression::REGEX_IDENTIFIER.')*+)'; /** diff --git a/src/Fixer/Import/NoUnusedImportsFixer.php b/src/Fixer/Import/NoUnusedImportsFixer.php index 689bbc56fc5..379396d9613 100644 --- a/src/Fixer/Import/NoUnusedImportsFixer.php +++ b/src/Fixer/Import/NoUnusedImportsFixer.php @@ -175,7 +175,7 @@ private function isImportUsed(Tokens $tokens, NamespaceAnalysis $namespace, Name if ($token->isComment() && Preg::match( - '/(?getShortName().'(?![[:alnum:]])/i', + '/(?getShortName().'(?![[:alnum:]])/i', $token->getContent() ) ) { diff --git a/src/Fixer/NamespaceNotation/CleanNamespaceFixer.php b/src/Fixer/NamespaceNotation/CleanNamespaceFixer.php index f39ed81de79..bb63adbd241 100644 --- a/src/Fixer/NamespaceNotation/CleanNamespaceFixer.php +++ b/src/Fixer/NamespaceNotation/CleanNamespaceFixer.php @@ -27,7 +27,7 @@ public function getDefinition(): FixerDefinitionInterface { $samples = []; - foreach (['namespace Foo \\ Bar;', 'echo foo /* comment */ \\ bar();'] as $sample) { + foreach (['namespace Foo \ Bar;', 'echo foo /* comment */ \ bar();'] as $sample) { $samples[] = new VersionSpecificCodeSample( "getTag()->getName()), + sprintf('/@%s\s+(.*\S)(?:\R|\s*\*+\/$)/', $annotation->getTag()->getName()), $annotation->getContent(), $matches, ); @@ -427,7 +427,7 @@ private static function fixUses(Tokens $tokens, int $index, Annotation $annotati if (str_starts_with($matches[1], '::')) { $attributeName = 'UsesFunction'; $attributeTokens = [self::createEscapedStringToken(substr($matches[1], 2))]; - } elseif (Preg::match('/^[a-zA-Z\d\\\\]+$/', $matches[1])) { + } elseif (Preg::match('/^[a-zA-Z\d\\\]+$/', $matches[1])) { $attributeName = 'UsesClass'; $attributeTokens = self::toClassConstant($matches[1]); } else { @@ -443,7 +443,7 @@ private static function fixUses(Tokens $tokens, int $index, Annotation $annotati private static function getMatches(Annotation $annotation): array { Preg::match( - sprintf('/@%s\s+(\S+)(?:\s+(\S+))?(?:\s+(.+\S))?\s*(?:\R|\*+\\/$)/', $annotation->getTag()->getName()), + sprintf('/@%s\s+(\S+)(?:\s+(\S+))?(?:\s+(.+\S))?\s*(?:\R|\*+\/$)/', $annotation->getTag()->getName()), $annotation->getContent(), $matches, ); diff --git a/src/Fixer/PhpUnit/PhpUnitFqcnAnnotationFixer.php b/src/Fixer/PhpUnit/PhpUnitFqcnAnnotationFixer.php index 65ae1ada299..46bb9a7da4d 100644 --- a/src/Fixer/PhpUnit/PhpUnitFqcnAnnotationFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitFqcnAnnotationFixer.php @@ -77,7 +77,7 @@ private function fixPhpUnitClass(Tokens $tokens, int $startIndex, int $endIndex) if ($tokens[$index]->isGivenKind(T_DOC_COMMENT)) { $tokens[$index] = new Token([T_DOC_COMMENT, Preg::replace( '~^(\s*\*\s*@(?:expectedException|covers|coversDefaultClass|uses)\h+)(?!(?:self|static)::)(\w.*)$~m', - '$1\\\\$2', + '$1\\\$2', $tokens[$index]->getContent() )]); } diff --git a/src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php b/src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php index 04a3e5f73eb..c742c2d1319 100644 --- a/src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php @@ -52,7 +52,7 @@ public function getDefinition(): FixerDefinitionInterface [ new CodeSample( 'whitespacesConfig->getLineEnding()), new CodeSample('whitespacesConfig->getLineEnding(), ['style' => 'annotation']), ], diff --git a/src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php b/src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php index d2f2929b19e..b95abb75f7c 100644 --- a/src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php @@ -78,8 +78,8 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en 'coversNothing', ], [ - 'phpunit\\framework\\attributes\\coversclass', - 'phpunit\\framework\\attributes\\coversnothing', + 'phpunit\framework\attributes\coversclass', + 'phpunit\framework\attributes\coversnothing', ], ); } diff --git a/src/Fixer/Phpdoc/PhpdocListTypeFixer.php b/src/Fixer/Phpdoc/PhpdocListTypeFixer.php index cfd56af1111..9d2cdff9be4 100644 --- a/src/Fixer/Phpdoc/PhpdocListTypeFixer.php +++ b/src/Fixer/Phpdoc/PhpdocListTypeFixer.php @@ -65,6 +65,6 @@ public function getPriority(): int protected function normalize(string $type): string { - return Preg::replace('/array(?=<(?:[^,<]|<[^>]+>)+(>|{|\\())/i', 'list', $type); + return Preg::replace('/array(?=<(?:[^,<]|<[^>]+>)+(>|{|\())/i', 'list', $type); } } diff --git a/src/Fixer/Phpdoc/PhpdocSeparationFixer.php b/src/Fixer/Phpdoc/PhpdocSeparationFixer.php index 3fade23f721..b52aa25c42f 100644 --- a/src/Fixer/Phpdoc/PhpdocSeparationFixer.php +++ b/src/Fixer/Phpdoc/PhpdocSeparationFixer.php @@ -295,7 +295,7 @@ private function shouldBeTogether(Annotation $first, Annotation $second, array $ private function tagName(Annotation $annotation): ?string { - Preg::match('/@([a-zA-Z0-9_\\\\-]+(?=\s|$|\())/', $annotation->getContent(), $matches); + Preg::match('/@([a-zA-Z0-9_\\\-]+(?=\s|$|\())/', $annotation->getContent(), $matches); return $matches[1] ?? null; } diff --git a/src/Fixer/Phpdoc/PhpdocToCommentFixer.php b/src/Fixer/Phpdoc/PhpdocToCommentFixer.php index 8f2ea442589..d6372d8f926 100644 --- a/src/Fixer/Phpdoc/PhpdocToCommentFixer.php +++ b/src/Fixer/Phpdoc/PhpdocToCommentFixer.php @@ -158,7 +158,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - if (0 < Preg::matchAll('~\@([a-zA-Z0-9_\\\\-]+)\b~', $token->getContent(), $matches)) { + if (0 < Preg::matchAll('~\@([a-zA-Z0-9_\\\-]+)\b~', $token->getContent(), $matches)) { foreach ($matches[1] as $match) { if (\in_array(strtolower($match), $this->ignoredTags, true)) { continue 2; diff --git a/src/Fixer/StringNotation/HeredocToNowdocFixer.php b/src/Fixer/StringNotation/HeredocToNowdocFixer.php index 800c79db4f7..9c736c14205 100644 --- a/src/Fixer/StringNotation/HeredocToNowdocFixer.php +++ b/src/Fixer/StringNotation/HeredocToNowdocFixer.php @@ -81,12 +81,12 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $content = $tokens[$index + 1]->getContent(); // regex: odd number of backslashes, not followed by dollar - if (Preg::match('/(?convertToNowdoc($token); - $content = str_replace(['\\\\', '\\$'], ['\\', '$'], $content); + $content = str_replace(['\\\\', '\$'], ['\\', '$'], $content); $tokens[$index + 1] = new Token([ $tokens[$index + 1]->getId(), $content, diff --git a/src/Fixer/StringNotation/MultilineStringToHeredocFixer.php b/src/Fixer/StringNotation/MultilineStringToHeredocFixer.php index 841a68fa55e..1a6790e6791 100644 --- a/src/Fixer/StringNotation/MultilineStringToHeredocFixer.php +++ b/src/Fixer/StringNotation/MultilineStringToHeredocFixer.php @@ -108,9 +108,9 @@ private function convertStringToHeredoc(Tokens $tokens, int $stringStartIndex, i $content = substr($content, 1, -1); if ($isSingleQuoted) { - $content = Preg::replace('~\\\\([\\\\\'])~', '$1', $content); + $content = Preg::replace('~\\\([\\\\\'])~', '$1', $content); } else { - $content = Preg::replace('~(\\\\\\\\)|\\\\(")~', '$1$2', $content); + $content = Preg::replace('~(\\\\\\\)|\\\(")~', '$1$2', $content); } $constantStringToken = new Token([T_ENCAPSED_AND_WHITESPACE, $content."\n"]); @@ -143,7 +143,7 @@ private function convertStringToHeredoc(Tokens $tokens, int $stringStartIndex, i if ($tokens[$i]->isGivenKind(T_ENCAPSED_AND_WHITESPACE)) { $tokens[$i] = new Token([ $tokens[$i]->getId(), - Preg::replace('~(\\\\\\\\)|\\\\(")~', '$1$2', $tokens[$i]->getContent()), + Preg::replace('~(\\\\\\\)|\\\(")~', '$1$2', $tokens[$i]->getContent()), ]); } } diff --git a/src/Fixer/StringNotation/SimpleToComplexStringVariableFixer.php b/src/Fixer/StringNotation/SimpleToComplexStringVariableFixer.php index 75891ac082a..efb139ca3f0 100644 --- a/src/Fixer/StringNotation/SimpleToComplexStringVariableFixer.php +++ b/src/Fixer/StringNotation/SimpleToComplexStringVariableFixer.php @@ -94,8 +94,8 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $tokenOfStringBeforeToken = $tokens[$index - 1]; $stringContent = $tokenOfStringBeforeToken->getContent(); - if (str_ends_with($stringContent, '$') && !str_ends_with($stringContent, '\\$')) { - $newContent = substr($stringContent, 0, -1).'\\$'; + if (str_ends_with($stringContent, '$') && !str_ends_with($stringContent, '\$')) { + $newContent = substr($stringContent, 0, -1).'\$'; $tokenOfStringBeforeToken = new Token([T_ENCAPSED_AND_WHITESPACE, $newContent]); } diff --git a/src/Fixer/StringNotation/SingleQuoteFixer.php b/src/Fixer/StringNotation/SingleQuoteFixer.php index a56c6b4eec5..10698a69935 100644 --- a/src/Fixer/StringNotation/SingleQuoteFixer.php +++ b/src/Fixer/StringNotation/SingleQuoteFixer.php @@ -88,10 +88,10 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void '"' === $content[0] && (true === $this->configuration['strings_containing_single_quote_chars'] || !str_contains($content, "'")) // regex: odd number of backslashes, not followed by double quote or dollar - && !Preg::match('/(?getContent(), -1, PREG_SPLIT_DELIM_CAPTURE); + $lines = Preg::split('/(\R+)/', $token->getContent(), -1, PREG_SPLIT_DELIM_CAPTURE); $linesSize = \count($lines); // fix only multiline whitespaces or singleline whitespaces at the end of file diff --git a/src/FixerFactory.php b/src/FixerFactory.php index a364db658f6..214f8577c6e 100644 --- a/src/FixerFactory.php +++ b/src/FixerFactory.php @@ -89,7 +89,7 @@ public function registerBuiltInFixers(): self /** @var SplFileInfo $file */ foreach (SymfonyFinder::create()->files()->in(__DIR__.'/Fixer')->name('*Fixer.php')->depth(1) as $file) { $relativeNamespace = $file->getRelativePath(); - $fixerClass = 'PhpCsFixer\\Fixer\\'.('' !== $relativeNamespace ? $relativeNamespace.'\\' : '').$file->getBasename('.php'); + $fixerClass = 'PhpCsFixer\Fixer\\'.('' !== $relativeNamespace ? $relativeNamespace.'\\' : '').$file->getBasename('.php'); $builtInFixers[] = $fixerClass; } } diff --git a/src/Tokenizer/Analyzer/DataProviderAnalyzer.php b/src/Tokenizer/Analyzer/DataProviderAnalyzer.php index 09f58b70d55..78040f3ac68 100644 --- a/src/Tokenizer/Analyzer/DataProviderAnalyzer.php +++ b/src/Tokenizer/Analyzer/DataProviderAnalyzer.php @@ -26,7 +26,7 @@ */ final class DataProviderAnalyzer { - private const REGEX_CLASS = '(?:\\\\?+'.TypeExpression::REGEX_IDENTIFIER + private const REGEX_CLASS = '(?:\\\?+'.TypeExpression::REGEX_IDENTIFIER .'(\\\\'.TypeExpression::REGEX_IDENTIFIER.')*+)'; /** diff --git a/src/Tokenizer/Transformers.php b/src/Tokenizer/Transformers.php index e874553820c..e5650659b23 100644 --- a/src/Tokenizer/Transformers.php +++ b/src/Tokenizer/Transformers.php @@ -101,7 +101,7 @@ private function findBuiltInTransformers(): iterable /** @var SplFileInfo $file */ foreach (Finder::create()->files()->in(__DIR__.'/Transformer') as $file) { $relativeNamespace = $file->getRelativePath(); - $class = __NAMESPACE__.'\\Transformer\\'.('' !== $relativeNamespace ? $relativeNamespace.'\\' : '').$file->getBasename('.php'); + $class = __NAMESPACE__.'\Transformer\\'.('' !== $relativeNamespace ? $relativeNamespace.'\\' : '').$file->getBasename('.php'); yield new $class(); } diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index d421a632522..016ff93a1c5 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -72,7 +72,7 @@ public static function tearDownAfterClass(): void */ public function testThatSrcClassHaveTestClass(string $className): void { - $testClassName = 'PhpCsFixer\\Tests'.substr($className, 10).'Test'; + $testClassName = 'PhpCsFixer\Tests'.substr($className, 10).'Test'; self::assertTrue(class_exists($testClassName), sprintf('Expected test class "%s" for "%s" not found.', $testClassName, $className)); } @@ -506,7 +506,7 @@ public function testDataProvidersDeclaredReturnType(string $testClassName, \Refl self::assertCount(1, $types, sprintf('DataProvider `%s@return` must provide single type.', $methodId)); self::assertMatchesRegularExpression('/^iterable\`).', $methodId)); + self::assertMatchesRegularExpression('/^iterable\<(?:(?:int\|)?string, )?array\{/', $types[0], sprintf('DataProvider `%s@return` must return iterable of tuples (eg `iterable`).', $methodId)); } /** @@ -903,7 +903,7 @@ private static function getSrcClasses(): array $classes = array_map( static fn (SplFileInfo $file): string => sprintf( - '%s\\%s%s%s', + '%s\%s%s%s', 'PhpCsFixer', strtr($file->getRelativePath(), \DIRECTORY_SEPARATOR, '\\'), '' !== $file->getRelativePath() ? '\\' : '', @@ -939,7 +939,7 @@ private static function getTestClasses(): array $classes = array_map( static fn (SplFileInfo $file): string => sprintf( - 'PhpCsFixer\\Tests\\%s%s%s', + 'PhpCsFixer\Tests\%s%s%s', strtr($file->getRelativePath(), \DIRECTORY_SEPARATOR, '\\'), '' !== $file->getRelativePath() ? '\\' : '', $file->getBasename('.'.$file->getExtension()) diff --git a/tests/Console/ApplicationTest.php b/tests/Console/ApplicationTest.php index 0cde0238433..789a59df409 100644 --- a/tests/Console/ApplicationTest.php +++ b/tests/Console/ApplicationTest.php @@ -26,8 +26,8 @@ final class ApplicationTest extends TestCase { public function testApplication(): void { - $regex = '/^PHP CS Fixer \\d+.\\d+.\\d+(-DEV)?<\\/info> .+<\\/info>' - .' by Fabien Potencier<\\/comment>, Dariusz Ruminski<\\/comment> and contributors<\\/comment>\\.' + $regex = '/^PHP CS Fixer \d+.\d+.\d+(-DEV)?<\/info> .+<\/info>' + .' by Fabien Potencier<\/comment>, Dariusz Ruminski<\/comment> and contributors<\/comment>\.' ."\nPHP runtime: \\d+.\\d+.\\d+(-dev)?<\\/info>$/"; self::assertMatchesRegularExpression($regex, (new Application())->getLongVersion()); diff --git a/tests/Differ/AbstractDifferTestCase.php b/tests/Differ/AbstractDifferTestCase.php index 1e1391b3e48..af4cca39da8 100644 --- a/tests/Differ/AbstractDifferTestCase.php +++ b/tests/Differ/AbstractDifferTestCase.php @@ -30,8 +30,8 @@ final public function testIsDiffer(): void '/Test$/', '', str_replace( - 'PhpCsFixer\\Tests\\Differ\\', - 'PhpCsFixer\\Differ\\', + 'PhpCsFixer\Tests\Differ\\', + 'PhpCsFixer\Differ\\', static::class ) ); diff --git a/tests/DocBlock/TypeExpressionTest.php b/tests/DocBlock/TypeExpressionTest.php index b61f7347de0..5a3dcdf85ed 100644 --- a/tests/DocBlock/TypeExpressionTest.php +++ b/tests/DocBlock/TypeExpressionTest.php @@ -43,12 +43,12 @@ public function testGetTypes(string $typesExpression, ?array $expectedTypes = nu $unionTestNs = '__UnionTest__'; $unionExpression = $this->parseTypeExpression( - $unionTestNs.'\\A|'.$typesExpression.'|'.$unionTestNs.'\\Z', + $unionTestNs.'\A|'.$typesExpression.'|'.$unionTestNs.'\Z', null, [] ); self::assertSame( - [$unionTestNs.'\\A', ...$expectedTypes, $unionTestNs.'\\Z'], + [$unionTestNs.'\A', ...$expectedTypes, $unionTestNs.'\Z'], [...$unionExpression->getTypes()] ); } @@ -191,25 +191,25 @@ public static function provideGetTypesCases(): iterable yield ['Closure(string)']; - yield ['\\closure(string): void']; + yield ['\closure(string): void']; yield [\Closure::class]; - yield ['\\Closure()']; + yield ['\Closure()']; - yield ['\\Closure(string)']; + yield ['\Closure(string)']; - yield ['\\Closure(string, bool)']; + yield ['\Closure(string, bool)']; - yield ['\\Closure(string|int, bool)']; + yield ['\Closure(string|int, bool)']; - yield ['\\Closure(string):bool']; + yield ['\Closure(string):bool']; - yield ['\\Closure(string): bool']; + yield ['\Closure(string): bool']; - yield ['\\Closure(string|int, bool): bool']; + yield ['\Closure(string|int, bool): bool']; - yield ['\\Closure(float|int): (bool|int)']; + yield ['\Closure(float|int): (bool|int)']; yield ['Closure(): T']; @@ -243,13 +243,13 @@ public static function provideGetTypesCases(): iterable yield ['(int)']; - yield ['(int|\\Exception)']; + yield ['(int|\Exception)']; yield ['($foo is int ? false : true)']; yield ['($foo🚀3 is int ? false : true)']; - yield ['\'a\\\'s"\\\\\n\r\t\'|"b\\"s\'\\\\\n\r\t"', ['\'a\\\'s"\\\\\n\r\t\'', '"b\\"s\'\\\\\n\r\t"']]; + yield ['\'a\\\'s"\\\\\n\r\t\'|"b\"s\'\\\\\n\r\t"', ['\'a\\\'s"\\\\\n\r\t\'', '"b\"s\'\\\\\n\r\t"']]; yield ['string'.str_repeat('[]', 128)]; @@ -325,9 +325,9 @@ public static function provideParseInvalidExceptionCases(): iterable yield ['class cannot contain space']; - yield ['\\\\class_with_double_backslash']; + yield ['\\\class_with_double_backslash']; - yield ['class\\\\with_double_backslash']; + yield ['class\\\with_double_backslash']; yield ['class_with_end_backslash\\']; diff --git a/tests/Fixer/Alias/RandomApiMigrationFixerTest.php b/tests/Fixer/Alias/RandomApiMigrationFixerTest.php index e5dd3df4ac5..60016129b4e 100644 --- a/tests/Fixer/Alias/RandomApiMigrationFixerTest.php +++ b/tests/Fixer/Alias/RandomApiMigrationFixerTest.php @@ -114,19 +114,19 @@ public static function provideFixCases(): iterable yield [' true], ]; @@ -215,7 +215,7 @@ function f(string $p) yield [ ' [ - ' [ - ' [ - ' [ - ' [ - ' [ - ' [ - ' [ - ' [ - ' null, null, new class {}); Foo\Bar::bind(fn () => null, null, new class {}); - \A\B\\Bar::bind(fn () => null, null, new class {}); + \A\B\Bar::bind(fn () => null, null, new class {}); ', ' null, null, new class {}); \CLOSURE::bind(fn () => null, null, new class {}); Foo\Bar::bind(fn () => null, null, new class {}); - \A\B\\Bar::bind(fn () => null, null, new class {}); + \A\B\Bar::bind(fn () => null, null, new class {}); ', ]; diff --git a/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php b/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php index b195a3214c6..906eea08e7a 100644 --- a/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php +++ b/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php @@ -103,17 +103,17 @@ public function usesInval() yield ['intval(mt_rand(0, 100));']; - yield [' [ + yield 'simple, leading \ before character order' => [ 'doTest($before); @@ -161,7 +161,7 @@ public static function provideFixWithDefaultConfigurationCases(): iterable yield ['doTest( 'fixer->configure([ - 'comment_text' => '~***(//[No break here.]\\\\)***~', + 'comment_text' => '~***(//[No break here.]\\\)***~', ]); $this->doTest( @@ -1183,10 +1183,10 @@ public function testFixWithCommentTextWithSpecialRegexpCharacters(): void switch ($foo) { case 1: foo(); - // ~***(//[No break here.]\\\\)***~ + // ~***(//[No break here.]\\\)***~ case 2: bar(); - // ~***(//[No break here.]\\\\)***~ + // ~***(//[No break here.]\\\)***~ default: baz(); }', @@ -1194,7 +1194,7 @@ public function testFixWithCommentTextWithSpecialRegexpCharacters(): void switch ($foo) { case 1: foo(); - // ~***(//[No break here.]\\\\)***~ + // ~***(//[No break here.]\\\)***~ case 2: bar(); default: diff --git a/tests/Fixer/ControlStructure/NoUnneededBracesFixerTest.php b/tests/Fixer/ControlStructure/NoUnneededBracesFixerTest.php index c8779695e3c..90c66953e2f 100644 --- a/tests/Fixer/ControlStructure/NoUnneededBracesFixerTest.php +++ b/tests/Fixer/ControlStructure/NoUnneededBracesFixerTest.php @@ -173,7 +173,7 @@ function Bar(){} yield [ '', "', " [ - ' [ @@ -82,7 +82,7 @@ function my_foo2($bar) {} ' [ - ' [ diff --git a/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php b/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php index 02fc7d0d595..6ac64233ba1 100644 --- a/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php +++ b/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php @@ -53,7 +53,7 @@ public static function provideFixCases(): iterable ]; yield 'invalid class 2' => [ - ' [ @@ -65,7 +65,7 @@ public static function provideFixCases(): iterable ]; yield 'invalid class 5' => [ - ' [ diff --git a/tests/Fixer/FunctionNotation/RegularCallableCallFixerTest.php b/tests/Fixer/FunctionNotation/RegularCallableCallFixerTest.php index 5a987477f61..41d2b2e2d84 100644 --- a/tests/Fixer/FunctionNotation/RegularCallableCallFixerTest.php +++ b/tests/Fixer/FunctionNotation/RegularCallableCallFixerTest.php @@ -181,17 +181,17 @@ function call_user_func($foo){} yield 'function name with escaped slash' => [ ' [ ' [ 'dirname(__FILE__);']; - yield ['is_null(json_decode($x));']; - yield [' self::createCase( ['class'], - '#[CoversClass(\\VendorName\\ClassName::class)]', + '#[CoversClass(\VendorName\ClassName::class)]', '@covers \VendorName\ClassName', ); @@ -533,7 +533,7 @@ public function testBar($x) {} */ private static function createCase(array $scopes, string $expectedAttribute, string $inputAnnotation): array { - $expectedAttribute = str_replace('#[', '#[\\PHPUnit\\Framework\\Attributes\\', $expectedAttribute); + $expectedAttribute = str_replace('#[', '#[\PHPUnit\Framework\Attributes\\', $expectedAttribute); return [ sprintf( diff --git a/tests/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixerTest.php index e6f49e0ebbc..e676c62aab6 100644 --- a/tests/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixerTest.php @@ -453,7 +453,7 @@ public function testFnc($param) }', ]; - yield 'special \\ handling' => [ + yield 'special \ handling' => [ <<<'EOT' isAbstract() && !$class->isAnonymous() && $class->implementsInterface(FixerInterface::class) && str_starts_with($class->getNamespaceName(), 'PhpCsFixer\\Fixer\\'); + return !$class->isAbstract() && !$class->isAnonymous() && $class->implementsInterface(FixerInterface::class) && str_starts_with($class->getNamespaceName(), 'PhpCsFixer\Fixer\\'); } ); diff --git a/tests/Linter/ProcessLinterProcessBuilderTest.php b/tests/Linter/ProcessLinterProcessBuilderTest.php index 143dd5c5298..53b39f7afc3 100644 --- a/tests/Linter/ProcessLinterProcessBuilderTest.php +++ b/tests/Linter/ProcessLinterProcessBuilderTest.php @@ -48,7 +48,7 @@ public static function providePrepareCommandOnPhpOnLinuxOrMacCases(): iterable { yield 'Linux-like' => ['php', 'foo.php', "'php' '-l' 'foo.php'"]; - yield 'Windows-like' => ['C:\\Program Files\\php\\php.exe', 'foo bar\\baz.php', "'C:\\Program Files\\php\\php.exe' '-l' 'foo bar\\baz.php'"]; + yield 'Windows-like' => ['C:\Program Files\php\php.exe', 'foo bar\baz.php', "'C:\\Program Files\\php\\php.exe' '-l' 'foo bar\\baz.php'"]; } /** @@ -73,6 +73,6 @@ public static function providePrepareCommandOnPhpOnWindowsCases(): iterable { yield 'Linux-like' => ['php', 'foo.php', 'php -l foo.php']; - yield 'Windows-like' => ['C:\\Program Files\\php\\php.exe', 'foo bar\\baz.php', '"C:\\Program Files\\php\\php.exe" -l "foo bar\\baz.php"']; + yield 'Windows-like' => ['C:\Program Files\php\php.exe', 'foo bar\baz.php', '"C:\Program Files\php\php.exe" -l "foo bar\baz.php"']; } } diff --git a/tests/PregTest.php b/tests/PregTest.php index ad949548b33..9234d5bd289 100644 --- a/tests/PregTest.php +++ b/tests/PregTest.php @@ -64,7 +64,7 @@ public static function providePatternValidationCases(): iterable yield 'valid_paired_non_utf8_only' => ["(\xFF)", true]; - yield 'php_version_dependent' => ['([\\R])', false, PregException::class, '/Compilation failed: escape sequence is invalid/']; + yield 'php_version_dependent' => ['([\R])', false, PregException::class, '/Compilation failed: escape sequence is invalid/']; yield 'null_byte_injection' => ['()'."\0", null, PregException::class, '/NUL( byte)? is not a valid modifier|Null byte in regex/']; } diff --git a/tests/RuleSet/Sets/AbstractSetTestCase.php b/tests/RuleSet/Sets/AbstractSetTestCase.php index 3e228432ad7..0af4a225362 100644 --- a/tests/RuleSet/Sets/AbstractSetTestCase.php +++ b/tests/RuleSet/Sets/AbstractSetTestCase.php @@ -75,7 +75,7 @@ protected static function assertSanityString(string $string): void protected static function getSet(): RuleSetDescriptionInterface { - $setClassName = preg_replace('/^(PhpCsFixer)\\\\Tests(\\\\.+)Test$/', '$1$2', static::class); + $setClassName = preg_replace('/^(PhpCsFixer)\\\Tests(\\\.+)Test$/', '$1$2', static::class); return new $setClassName(); } diff --git a/tests/Smoke/InstallViaComposerTest.php b/tests/Smoke/InstallViaComposerTest.php index 42505c7764b..558eeea8eb0 100644 --- a/tests/Smoke/InstallViaComposerTest.php +++ b/tests/Smoke/InstallViaComposerTest.php @@ -125,7 +125,7 @@ public function testInstallationViaArtifactIsPossible(): void unlink($tmpArtifactPath); $this->fs->mkdir($tmpArtifactPath); - $fakeVersion = preg_replace('/\\-.+/', '', Application::VERSION, 1).'-alpha987654321'; + $fakeVersion = preg_replace('/\-.+/', '', Application::VERSION, 1).'-alpha987654321'; $tmpPath = $this->createFakeComposerProject([ 'repositories' => [ diff --git a/tests/Test/AbstractFixerTestCase.php b/tests/Test/AbstractFixerTestCase.php index 3722da891cd..ef2129dcc1d 100644 --- a/tests/Test/AbstractFixerTestCase.php +++ b/tests/Test/AbstractFixerTestCase.php @@ -570,7 +570,7 @@ final public function testProperMethodNaming(): void protected function createFixer(): AbstractFixer { - $fixerClassName = preg_replace('/^(PhpCsFixer)\\\\Tests(\\\\.+)Test$/', '$1$2', static::class); + $fixerClassName = preg_replace('/^(PhpCsFixer)\\\Tests(\\\.+)Test$/', '$1$2', static::class); return new $fixerClassName(); } diff --git a/tests/Test/AbstractTransformerTestCase.php b/tests/Test/AbstractTransformerTestCase.php index fdf20cc6b3c..b5f22ab173a 100644 --- a/tests/Test/AbstractTransformerTestCase.php +++ b/tests/Test/AbstractTransformerTestCase.php @@ -209,7 +209,7 @@ private function countTokenPrototypes(Tokens $tokens, array $prototypes): int private function createTransformer(): TransformerInterface { - $transformerClassName = preg_replace('/^(PhpCsFixer)\\\\Tests(\\\\.+)Test$/', '$1$2', static::class); + $transformerClassName = preg_replace('/^(PhpCsFixer)\\\Tests(\\\.+)Test$/', '$1$2', static::class); return new $transformerClassName(); } diff --git a/tests/Tokenizer/Analyzer/Analysis/AttributeAnalysisTest.php b/tests/Tokenizer/Analyzer/Analysis/AttributeAnalysisTest.php index 39763334a6a..915b5cb08e6 100644 --- a/tests/Tokenizer/Analyzer/Analysis/AttributeAnalysisTest.php +++ b/tests/Tokenizer/Analyzer/Analysis/AttributeAnalysisTest.php @@ -27,8 +27,8 @@ final class AttributeAnalysisTest extends TestCase public function testAttribute(): void { $attributes = [ - ['start' => 3, 'end' => 12, 'name' => 'AB\\Baz'], - ['start' => 14, 'end' => 32, 'name' => '\\A\\B\\Qux'], + ['start' => 3, 'end' => 12, 'name' => 'AB\Baz'], + ['start' => 14, 'end' => 32, 'name' => '\A\B\Qux'], ]; $analysis = new AttributeAnalysis(2, 34, 3, 34, $attributes); diff --git a/tests/Tokenizer/Analyzer/AttributeAnalyzerTest.php b/tests/Tokenizer/Analyzer/AttributeAnalyzerTest.php index 2509c121deb..e7ec98698a0 100644 --- a/tests/Tokenizer/Analyzer/AttributeAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/AttributeAnalyzerTest.php @@ -184,17 +184,17 @@ function foo() {} new AttributeAnalysis(4, 15, 4, 14, [[ 'start' => 5, 'end' => 13, - 'name' => 'AB\\Baz', + 'name' => 'AB\Baz', ]]), new AttributeAnalysis(16, 49, 16, 48, [[ 'start' => 17, 'end' => 47, - 'name' => 'A\\B\\Quux', + 'name' => 'A\B\Quux', ]]), new AttributeAnalysis(50, 60, 50, 59, [[ 'start' => 51, 'end' => 58, - 'name' => '\\A\\B\\Qux', + 'name' => '\A\B\Qux', ]]), new AttributeAnalysis(61, 67, 61, 66, [[ 'start' => 62, @@ -224,17 +224,17 @@ function foo() {} new AttributeAnalysis(3, 14, 3, 13, [[ 'start' => 4, 'end' => 12, - 'name' => 'AB\\Baz', + 'name' => 'AB\Baz', ]]), new AttributeAnalysis(15, 48, 15, 47, [[ 'start' => 16, 'end' => 46, - 'name' => 'A\\B\\Quux', + 'name' => 'A\B\Quux', ]]), new AttributeAnalysis(49, 59, 49, 58, [[ 'start' => 50, 'end' => 57, - 'name' => '\\A\\B\\Qux', + 'name' => '\A\B\Qux', ]]), new AttributeAnalysis(60, 66, 60, 65, [[ 'start' => 61, @@ -280,15 +280,15 @@ function foo() {} new AttributeAnalysis(2, 83, 2, 82, [[ 'start' => 3, 'end' => 14, - 'name' => 'AB\\Baz', + 'name' => 'AB\Baz', ], [ 'start' => 16, 'end' => 47, - 'name' => 'A\\B\\Quux', + 'name' => 'A\B\Quux', ], [ 'start' => 49, 'end' => 57, - 'name' => '\\A\\B\\Qux', + 'name' => '\A\B\Qux', ], [ 'start' => 59, 'end' => 63, @@ -315,15 +315,15 @@ function foo() {} new AttributeAnalysis(2, 77, 2, 76, [[ 'start' => 3, 'end' => 12, - 'name' => 'AB\\Baz', + 'name' => 'AB\Baz', ], [ 'start' => 14, 'end' => 45, - 'name' => 'A\\B\\Quux', + 'name' => 'A\B\Quux', ], [ 'start' => 47, 'end' => 55, - 'name' => '\\A\\B\\Qux', + 'name' => '\A\B\Qux', ], [ 'start' => 57, 'end' => 61, @@ -381,12 +381,12 @@ function foo() {} new AttributeAnalysis(2, 13, 2, 12, [[ 'start' => 3, 'end' => 11, - 'name' => 'AB\\Baz', + 'name' => 'AB\Baz', ]]), new AttributeAnalysis(14, 34, 14, 33, [[ 'start' => 15, 'end' => 32, - 'name' => '\\A\\B\\Qux', + 'name' => '\A\B\Qux', ]]), new AttributeAnalysis(35, 38, 35, 37, [[ 'start' => 36, @@ -410,11 +410,11 @@ function foo() {} new AttributeAnalysis(2, 39, 2, 38, [[ 'start' => 3, 'end' => 12, - 'name' => 'AB\\Baz', + 'name' => 'AB\Baz', ], [ 'start' => 14, 'end' => 32, - 'name' => '\\A\\B\\Qux', + 'name' => '\A\B\Qux', ], [ 'start' => 34, 'end' => 35, diff --git a/tests/Tokenizer/Processor/ImportProcessorTest.php b/tests/Tokenizer/Processor/ImportProcessorTest.php index 36a39902886..94fb1542616 100644 --- a/tests/Tokenizer/Processor/ImportProcessorTest.php +++ b/tests/Tokenizer/Processor/ImportProcessorTest.php @@ -53,17 +53,17 @@ public static function provideTokenizeNameCases(): iterable { yield [__CLASS__]; - yield ['Foo\\Bar']; + yield ['Foo\Bar']; - yield ['\\Foo\\Bar']; + yield ['\Foo\Bar']; yield ['FooBar']; - yield ['\\FooBar']; + yield ['\FooBar']; - yield ['\\Foo\\Bar\\Baz\\Buzz']; + yield ['\Foo\Bar\Baz\Buzz']; - yield ['\\Foo1\\Bar_\\baz\\buzz']; + yield ['\Foo1\Bar_\baz\buzz']; } /** @@ -101,7 +101,7 @@ public static function provideInsertImportsCases(): iterable namespace Foo; ', [ - 'class' => ['Other\\A', 'Other\\B'], + 'class' => ['Other\A', 'Other\B'], ], 6, ]; @@ -120,7 +120,7 @@ public static function provideInsertImportsCases(): iterable } ', [ - 'class' => ['Other\\A', 'Other\\B'], + 'class' => ['Other\A', 'Other\B'], ], 7, ]; diff --git a/tests/Tokenizer/Transformer/ImportTransformerTest.php b/tests/Tokenizer/Transformer/ImportTransformerTest.php index 92229bfbeea..50f34c6a1df 100644 --- a/tests/Tokenizer/Transformer/ImportTransformerTest.php +++ b/tests/Tokenizer/Transformer/ImportTransformerTest.php @@ -69,7 +69,7 @@ public static function provideProcessCases(): iterable ]; yield [ - ' CT::T_CONST_IMPORT, ], @@ -104,7 +104,7 @@ public static function provideProcessCases(): iterable ]; yield [ - ' CT::T_FUNCTION_IMPORT, ], diff --git a/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php b/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php index 0145bf47365..a917dcd864d 100644 --- a/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php +++ b/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php @@ -248,7 +248,7 @@ public static function providePriorityCases(): iterable new Token([T_STRING, 'Transformer']), new Token(';'), ], - '