From 777c1ee91bb398bd4bec2b9764f9469e5a9ec67e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 20 Jun 2026 16:07:32 +0200 Subject: [PATCH 1/5] [dx] add fresh new common sets, extend existing ones --- bin/ecs.php | 2 +- config/set/common.php | 4 +++ config/set/common/casing.php | 19 +++++++++++ config/set/common/cleanup.php | 10 ++++++ config/set/common/comments.php | 10 +++++- config/set/common/operators.php | 17 ++++++++++ config/set/common/strings.php | 10 ++++++ .../Commenting/AddMissingParamNameFixer.php | 2 +- scoper.php | 34 +++++++++---------- src/Config/Level/ArrayLevel.php | 4 +++ src/Config/Level/DocblockLevel.php | 6 ++++ src/Configuration/ECSConfigBuilder.php | 32 +++++++++++++++-- src/FileSystem/PathNormalizer.php | 2 +- .../PHPUnit/AbstractCheckerTestCase.php | 2 +- src/ValueObject/Set/SetList.php | 20 +++++++++++ .../EditorConfig/EditorConfigFactoryTest.php | 31 +++++++++-------- 16 files changed, 166 insertions(+), 39 deletions(-) create mode 100644 config/set/common/casing.php create mode 100644 config/set/common/cleanup.php create mode 100644 config/set/common/operators.php create mode 100644 config/set/common/strings.php diff --git a/bin/ecs.php b/bin/ecs.php index 6177f183ba5..23c1eada2f1 100755 --- a/bin/ecs.php +++ b/bin/ecs.php @@ -19,7 +19,7 @@ define('__ECS_RUNNING__', true); -# 1. autoload +// 1. autoload $autoloadIncluder = new ECSAutoloadIncluder(); $autoloadIncluder->includeCwdVendorAutoloadIfExists(); diff --git a/config/set/common.php b/config/set/common.php index 156b6d8f268..476d9b8d082 100644 --- a/config/set/common.php +++ b/config/set/common.php @@ -13,5 +13,9 @@ SetList::DOCBLOCK, SetList::NAMESPACES, SetList::SPACES, + SetList::CASING, + SetList::OPERATORS, + SetList::STRINGS, + SetList::CLEANUP, SetList::CLEAN_CODE, ]); diff --git a/config/set/common/casing.php b/config/set/common/casing.php new file mode 100644 index 00000000000..c98d491647a --- /dev/null +++ b/config/set/common/casing.php @@ -0,0 +1,19 @@ +withRules([ + NativeFunctionCasingFixer::class, + NativeTypeDeclarationCasingFixer::class, + IntegerLiteralCaseFixer::class, + MagicMethodCasingFixer::class, + ClassReferenceNameCasingFixer::class, + ]); diff --git a/config/set/common/cleanup.php b/config/set/common/cleanup.php new file mode 100644 index 00000000000..d1c811f364e --- /dev/null +++ b/config/set/common/cleanup.php @@ -0,0 +1,10 @@ +withRules([NoEmptyStatementFixer::class, NoUselessReturnFixer::class]); diff --git a/config/set/common/comments.php b/config/set/common/comments.php index e24cf765e83..60f493af1d8 100644 --- a/config/set/common/comments.php +++ b/config/set/common/comments.php @@ -3,7 +3,15 @@ declare(strict_types=1); use PHP_CodeSniffer\Standards\Generic\Sniffs\VersionControl\GitMergeConflictSniff; +use PhpCsFixer\Fixer\Comment\NoEmptyCommentFixer; +use PhpCsFixer\Fixer\Comment\SingleLineCommentSpacingFixer; +use PhpCsFixer\Fixer\Comment\SingleLineCommentStyleFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; return ECSConfig::configure() - ->withRules([GitMergeConflictSniff::class]); + ->withRules([ + GitMergeConflictSniff::class, + NoEmptyCommentFixer::class, + SingleLineCommentSpacingFixer::class, + SingleLineCommentStyleFixer::class, + ]); diff --git a/config/set/common/operators.php b/config/set/common/operators.php new file mode 100644 index 00000000000..a769b97803c --- /dev/null +++ b/config/set/common/operators.php @@ -0,0 +1,17 @@ +withRules([ + NoUselessConcatOperatorFixer::class, + NoUselessNullsafeOperatorFixer::class, + StandardizeNotEqualsFixer::class, + LongToShorthandOperatorFixer::class, + ]); diff --git a/config/set/common/strings.php b/config/set/common/strings.php new file mode 100644 index 00000000000..d710bc13987 --- /dev/null +++ b/config/set/common/strings.php @@ -0,0 +1,10 @@ +withRules([StringImplicitBackslashesFixer::class, HeredocToNowdocFixer::class]); diff --git a/packages/coding-standard/src/Fixer/Commenting/AddMissingParamNameFixer.php b/packages/coding-standard/src/Fixer/Commenting/AddMissingParamNameFixer.php index 73b537cba2a..1b57b21a39f 100644 --- a/packages/coding-standard/src/Fixer/Commenting/AddMissingParamNameFixer.php +++ b/packages/coding-standard/src/Fixer/Commenting/AddMissingParamNameFixer.php @@ -141,7 +141,7 @@ private function shouldSkipLine(Line $line): bool private function createNewLineContent(string $newArgumentName, Line $line): string { // @see https://regex101.com/r/4FL49H/1 - $missingDollarSignPattern = '#(@param\s+([\w\|\[\]\\\\]+\s)?)(' . ltrim($newArgumentName, '$') . ')#'; + $missingDollarSignPattern = '#(@param\s+([\w\|\[\]\\\]+\s)?)(' . ltrim($newArgumentName, '$') . ')#'; // missing \$ case - possibly own worker if (Regex::match($line->getContent(), $missingDollarSignPattern)) { diff --git a/scoper.php b/scoper.php index 532b14e39c3..11623bfa236 100644 --- a/scoper.php +++ b/scoper.php @@ -42,14 +42,14 @@ // excluded 'exclude-namespaces' => [ - '#^Symplify\\\\EasyCodingStandard#', - '#^Symplify\\\\CodingStandard#', + '#^Symplify\\\EasyCodingStandard#', + '#^Symplify\\\CodingStandard#', '#^PhpCsFixer#', '#^PHP_CodeSniffer#', - '#^Symfony\\\\Polyfill#', - '#^PHPUnit\\\\Framework#', - '#^PHPUnit\\\\Runner#', - '#^PHPUnit\\\\Util#', + '#^Symfony\\\Polyfill#', + '#^PHPUnit\\\Framework#', + '#^PHPUnit\\\Runner#', + '#^PHPUnit\\\Util#', ], 'exclude-constants' => [ // Symfony global constants @@ -79,11 +79,11 @@ static function (string $filePath, string $prefix, string $content): string { // php-cs-fixer uses partial namespaces, that are only strings - should be kept untouched // ref.: https://github.com/easy-coding-standard/easy-coding-standard/issues/91 return str_replace([ - $prefix . '\\\\ORM\\\\Entity', - $prefix . '\\\\ORM\\\\Mapping\\\\Entity', - $prefix . '\\\\Mapping\\\\Entity', - $prefix . '\\\\ODM\\\\Document', - ], ['ORM\\Entity', 'ORM\\Mapping\\Entity', 'Mapping\\Entity', 'ODM\\Document'], $content); + $prefix . '\\\ORM\\\Entity', + $prefix . '\\\ORM\\\Mapping\\\Entity', + $prefix . '\\\Mapping\\\Entity', + $prefix . '\\\ODM\\\Document', + ], ['ORM\Entity', 'ORM\Mapping\Entity', 'Mapping\Entity', 'ODM\Document'], $content); }, static function (string $filePath, string $prefix, string $content): string { @@ -122,14 +122,14 @@ function (string $filePath, string $prefix, string $content): string { } // real namespace - $content = Strings::replace($content, '#' . $prefix . '\\\\PHPUnit\\\\Framework#', 'PHPUnit\Framework'); - $content = Strings::replace($content, '#' . $prefix . '\\\\PHPUnit\\\\Runner#', 'PHPUnit\Runner'); - $content = Strings::replace($content, '#' . $prefix . '\\\\PHPUnit\\\\Util#', 'PHPUnit\Util'); + $content = Strings::replace($content, '#' . $prefix . '\\\PHPUnit\\\Framework#', 'PHPUnit\Framework'); + $content = Strings::replace($content, '#' . $prefix . '\\\PHPUnit\\\Runner#', 'PHPUnit\Runner'); + $content = Strings::replace($content, '#' . $prefix . '\\\PHPUnit\\\Util#', 'PHPUnit\Util'); // lower case namespace - $content = Strings::replace($content, '#' . $prefix . '\\\\phpunit\\\\framework#', 'phpunit\framework'); - $content = Strings::replace($content, '#' . $prefix . '\\\\phpunit\\\\runner#', 'phpunit\runner'); - $content = Strings::replace($content, '#' . $prefix . '\\\\phpunit\\\\util#', 'phpunit\util'); + $content = Strings::replace($content, '#' . $prefix . '\\\phpunit\\\framework#', 'phpunit\framework'); + $content = Strings::replace($content, '#' . $prefix . '\\\phpunit\\\runner#', 'phpunit\runner'); + $content = Strings::replace($content, '#' . $prefix . '\\\phpunit\\\util#', 'phpunit\util'); return $content; }, diff --git a/src/Config/Level/ArrayLevel.php b/src/Config/Level/ArrayLevel.php index a828113d4c7..659730de899 100644 --- a/src/Config/Level/ArrayLevel.php +++ b/src/Config/Level/ArrayLevel.php @@ -6,7 +6,9 @@ use PHP_CodeSniffer\Sniffs\Sniff; use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer; +use PhpCsFixer\Fixer\ArrayNotation\NoMultilineWhitespaceAroundDoubleArrowFixer; use PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer; +use PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceInEmptyArrayFixer; use PhpCsFixer\Fixer\ArrayNotation\TrimArraySpacesFixer; use PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer; use PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer; @@ -34,6 +36,8 @@ final class ArrayLevel NoWhitespaceBeforeCommaInArrayFixer::class, WhitespaceAfterCommaInArrayFixer::class, TrimArraySpacesFixer::class, + NoWhitespaceInEmptyArrayFixer::class, + NoMultilineWhitespaceAroundDoubleArrowFixer::class, NoTrailingCommaInSinglelineFixer::class, // syntax normalization diff --git a/src/Config/Level/DocblockLevel.php b/src/Config/Level/DocblockLevel.php index 23ca458a5d2..8564326936b 100644 --- a/src/Config/Level/DocblockLevel.php +++ b/src/Config/Level/DocblockLevel.php @@ -11,8 +11,11 @@ use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocIndentFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocLineSpanFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocNoDuplicateTypesFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocNoEmptyReturnFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocOrderByValueFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocTagCasingFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimConsecutiveBlankLineSeparationFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer; @@ -70,10 +73,13 @@ final class DocblockLevel PhpdocIndentFixer::class, // type / formatting normalization + PhpdocTagCasingFixer::class, + PhpdocNoDuplicateTypesFixer::class, PhpdocTypesFixer::class, PhpdocLineSpanFixer::class, PhpdocVarWithoutNameFixer::class, PhpdocReturnSelfReferenceFixer::class, + PhpdocOrderByValueFixer::class, // dropping content NoEmptyPhpdocFixer::class, diff --git a/src/Configuration/ECSConfigBuilder.php b/src/Configuration/ECSConfigBuilder.php index 753baa9d7b1..ebea8856fdb 100644 --- a/src/Configuration/ECSConfigBuilder.php +++ b/src/Configuration/ECSConfigBuilder.php @@ -63,7 +63,7 @@ final class ECSConfigBuilder private array $rules = []; /** - * @var array, mixed> + * @var array, mixed> */ private array $rulesWithConfiguration = []; @@ -252,6 +252,14 @@ public function withPreparedSets( bool $namespaces = false, /** @see SetList::CONTROL_STRUCTURES */ bool $controlStructures = false, + /** @see SetList::CASING */ + bool $casing = false, + /** @see SetList::OPERATORS */ + bool $operators = false, + /** @see SetList::STRINGS */ + bool $strings = false, + /** @see SetList::CLEANUP */ + bool $cleanup = false, /** * @deprecated as never worked, used different rules. Use Rector instead. * @see SetList::PHPUNIT @@ -286,6 +294,10 @@ public function withPreparedSets( 'docblocks' => $docblocks, 'controlStructures' => $controlStructures, 'comments' => $comments, + 'casing' => $casing, + 'operators' => $operators, + 'strings' => $strings, + 'cleanup' => $cleanup, ]))) !== []) { throw new SuperfluousConfigurationException( sprintf( @@ -324,6 +336,22 @@ public function withPreparedSets( if ($comments) { $this->sets[] = SetList::COMMENTS; } + + if ($casing) { + $this->sets[] = SetList::CASING; + } + + if ($operators) { + $this->sets[] = SetList::OPERATORS; + } + + if ($strings) { + $this->sets[] = SetList::STRINGS; + } + + if ($cleanup) { + $this->sets[] = SetList::CLEANUP; + } } if ($strict) { @@ -725,7 +753,7 @@ public function withSpacing(?string $indentation = null, ?string $lineEnding = n } /** - * @param class-string<(FixerInterface | Sniff)> $checkerClass + * @param class-string<(FixerInterface|Sniff)> $checkerClass * @param mixed[] $configuration */ public function withConfiguredRule(string $checkerClass, array $configuration): self diff --git a/src/FileSystem/PathNormalizer.php b/src/FileSystem/PathNormalizer.php index bd82d0e301f..49be64625cb 100644 --- a/src/FileSystem/PathNormalizer.php +++ b/src/FileSystem/PathNormalizer.php @@ -20,7 +20,7 @@ final class PathNormalizer /** * @see https://regex101.com/r/d4F5Fm/1 */ - private const string SCHEME_PATH_REGEX = '#^([a-z]+)\\:\\/\\/(.+)#'; + private const string SCHEME_PATH_REGEX = '#^([a-z]+)\:\/\/(.+)#'; /** * @see https://regex101.com/r/no28vw/1 diff --git a/src/Testing/PHPUnit/AbstractCheckerTestCase.php b/src/Testing/PHPUnit/AbstractCheckerTestCase.php index f1b927a72ab..f4cddd2a253 100644 --- a/src/Testing/PHPUnit/AbstractCheckerTestCase.php +++ b/src/Testing/PHPUnit/AbstractCheckerTestCase.php @@ -25,7 +25,7 @@ */ abstract class AbstractCheckerTestCase extends AbstractTestCase implements ConfigAwareInterface { - private const string SPLIT_LINE_REGEX = "#\-\-\-\-\-\r?\n#"; + private const string SPLIT_LINE_REGEX = "#\\-\\-\\-\\-\\-\r?\n#"; /** * @var string[] diff --git a/src/ValueObject/Set/SetList.php b/src/ValueObject/Set/SetList.php index 4dc18204bca..6c725d50a88 100644 --- a/src/ValueObject/Set/SetList.php +++ b/src/ValueObject/Set/SetList.php @@ -71,6 +71,26 @@ final class SetList */ public const string STRICT = __DIR__ . '/../../../config/set/common/strict.php'; + /** + * @api + */ + public const string CASING = __DIR__ . '/../../../config/set/common/casing.php'; + + /** + * @api + */ + public const string OPERATORS = __DIR__ . '/../../../config/set/common/operators.php'; + + /** + * @api + */ + public const string STRINGS = __DIR__ . '/../../../config/set/common/strings.php'; + + /** + * @api + */ + public const string CLEANUP = __DIR__ . '/../../../config/set/common/cleanup.php'; + /** * @api */ diff --git a/tests/Configuration/EditorConfig/EditorConfigFactoryTest.php b/tests/Configuration/EditorConfig/EditorConfigFactoryTest.php index 149a91fefe6..15ea0fcf20c 100644 --- a/tests/Configuration/EditorConfig/EditorConfigFactoryTest.php +++ b/tests/Configuration/EditorConfig/EditorConfigFactoryTest.php @@ -47,7 +47,7 @@ public function testParsingInvalidIniFile(): void $this->expectException(Exception::class); $editorConfigFactory = new EditorConfigFactory(); - @$editorConfigFactory->parse(<<parse(<<<'INI' fleeb! INI ); @@ -58,7 +58,7 @@ public function testLoadsExpectedSections(): void $this->assertEquals( new EditorConfigFactory() ->parse( - <<assertEquals( new EditorConfigFactory() - ->parse(<<parse(<<<'INI' [*] indent_style = space INI @@ -119,7 +119,7 @@ public function testIndentStyleTabs(): void { $this->assertEquals( new EditorConfigFactory() - ->parse(<<parse(<<<'INI' [*] indent_style = tab INI @@ -139,7 +139,7 @@ public function testEndOfLinePosix(): void { $this->assertEquals( new EditorConfigFactory() - ->parse(<<parse(<<<'INI' [*] end_of_line = lf INI @@ -159,7 +159,7 @@ public function testEndOfLineLegacy(): void { $this->assertEquals( new EditorConfigFactory() - ->parse(<<parse(<<<'INI' [*] end_of_line = cr INI @@ -179,7 +179,7 @@ public function testEndOfLineWindows(): void { $this->assertEquals( new EditorConfigFactory() - ->parse(<<parse(<<<'INI' [*] end_of_line = crlf INI @@ -200,7 +200,7 @@ public function testTrimTrailingWhitespaceEnabled(): void $this->assertEquals( new EditorConfigFactory() ->parse( - <<assertEquals( new EditorConfigFactory() ->parse( - <<assertEquals( new EditorConfigFactory() - ->parse(<<parse( + <<<'INI' [*] insert_final_newline = true INI @@ -262,7 +263,7 @@ public function testInsertFinalNewlineDisabled(): void $this->assertEquals( new EditorConfigFactory() ->parse( - <<assertEquals( new EditorConfigFactory() - ->parse(<<parse(<<<'INI' [*] max_line_length = 63 INI @@ -302,7 +303,7 @@ public function quoteTypeAuto(): void { $this->assertEquals( new EditorConfigFactory() - ->parse(<<parse(<<<'INI' [*] quote_type = auto INI @@ -322,7 +323,7 @@ public function quoteTypeSingle(): void { $this->assertEquals( new EditorConfigFactory() - ->parse(<<parse(<<<'INI' [*] quote_type = single INI @@ -342,7 +343,7 @@ public function quoteTypeDouble(): void { $this->assertEquals( new EditorConfigFactory() - ->parse(<<parse(<<<'INI' [*] quote_type = double INI From 7d3b4d25e8a7490648741466f1c00542695f8d59 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 20 Jun 2026 16:20:38 +0200 Subject: [PATCH 2/5] remove HERENOW doc change, remo string rules --- config/set/common.php | 1 - config/set/common/strings.php | 10 ------ scoper.php | 12 +++---- src/Configuration/ECSConfigBuilder.php | 7 ----- .../PHPUnit/AbstractCheckerTestCase.php | 2 +- src/ValueObject/Set/SetList.php | 5 --- .../EditorConfig/EditorConfigFactoryTest.php | 31 +++++++++---------- 7 files changed, 22 insertions(+), 46 deletions(-) delete mode 100644 config/set/common/strings.php diff --git a/config/set/common.php b/config/set/common.php index 476d9b8d082..e5b72984343 100644 --- a/config/set/common.php +++ b/config/set/common.php @@ -15,7 +15,6 @@ SetList::SPACES, SetList::CASING, SetList::OPERATORS, - SetList::STRINGS, SetList::CLEANUP, SetList::CLEAN_CODE, ]); diff --git a/config/set/common/strings.php b/config/set/common/strings.php deleted file mode 100644 index d710bc13987..00000000000 --- a/config/set/common/strings.php +++ /dev/null @@ -1,10 +0,0 @@ -withRules([StringImplicitBackslashesFixer::class, HeredocToNowdocFixer::class]); diff --git a/scoper.php b/scoper.php index 11623bfa236..554225cbb86 100644 --- a/scoper.php +++ b/scoper.php @@ -122,14 +122,14 @@ function (string $filePath, string $prefix, string $content): string { } // real namespace - $content = Strings::replace($content, '#' . $prefix . '\\\PHPUnit\\\Framework#', 'PHPUnit\Framework'); - $content = Strings::replace($content, '#' . $prefix . '\\\PHPUnit\\\Runner#', 'PHPUnit\Runner'); - $content = Strings::replace($content, '#' . $prefix . '\\\PHPUnit\\\Util#', 'PHPUnit\Util'); + $content = Strings::replace($content, '#' . $prefix . '\\\\PHPUnit\\\Framework#', 'PHPUnit\Framework'); + $content = Strings::replace($content, '#' . $prefix . '\\\\PHPUnit\\\Runner#', 'PHPUnit\Runner'); + $content = Strings::replace($content, '#' . $prefix . '\\\\PHPUnit\\\Util#', 'PHPUnit\Util'); // lower case namespace - $content = Strings::replace($content, '#' . $prefix . '\\\phpunit\\\framework#', 'phpunit\framework'); - $content = Strings::replace($content, '#' . $prefix . '\\\phpunit\\\runner#', 'phpunit\runner'); - $content = Strings::replace($content, '#' . $prefix . '\\\phpunit\\\util#', 'phpunit\util'); + $content = Strings::replace($content, '#' . $prefix . '\\\\PHPunit\\\framework#', 'phpunit\framework'); + $content = Strings::replace($content, '#' . $prefix . '\\\\PHPunit\\\runner#', 'phpunit\runner'); + $content = Strings::replace($content, '#' . $prefix . '\\\\PHPunit\\\util#', 'phpunit\util'); return $content; }, diff --git a/src/Configuration/ECSConfigBuilder.php b/src/Configuration/ECSConfigBuilder.php index ebea8856fdb..45db5340403 100644 --- a/src/Configuration/ECSConfigBuilder.php +++ b/src/Configuration/ECSConfigBuilder.php @@ -256,8 +256,6 @@ public function withPreparedSets( bool $casing = false, /** @see SetList::OPERATORS */ bool $operators = false, - /** @see SetList::STRINGS */ - bool $strings = false, /** @see SetList::CLEANUP */ bool $cleanup = false, /** @@ -296,7 +294,6 @@ public function withPreparedSets( 'comments' => $comments, 'casing' => $casing, 'operators' => $operators, - 'strings' => $strings, 'cleanup' => $cleanup, ]))) !== []) { throw new SuperfluousConfigurationException( @@ -345,10 +342,6 @@ public function withPreparedSets( $this->sets[] = SetList::OPERATORS; } - if ($strings) { - $this->sets[] = SetList::STRINGS; - } - if ($cleanup) { $this->sets[] = SetList::CLEANUP; } diff --git a/src/Testing/PHPUnit/AbstractCheckerTestCase.php b/src/Testing/PHPUnit/AbstractCheckerTestCase.php index f4cddd2a253..f1b927a72ab 100644 --- a/src/Testing/PHPUnit/AbstractCheckerTestCase.php +++ b/src/Testing/PHPUnit/AbstractCheckerTestCase.php @@ -25,7 +25,7 @@ */ abstract class AbstractCheckerTestCase extends AbstractTestCase implements ConfigAwareInterface { - private const string SPLIT_LINE_REGEX = "#\\-\\-\\-\\-\\-\r?\n#"; + private const string SPLIT_LINE_REGEX = "#\-\-\-\-\-\r?\n#"; /** * @var string[] diff --git a/src/ValueObject/Set/SetList.php b/src/ValueObject/Set/SetList.php index 6c725d50a88..dd9cfde2d4e 100644 --- a/src/ValueObject/Set/SetList.php +++ b/src/ValueObject/Set/SetList.php @@ -81,11 +81,6 @@ final class SetList */ public const string OPERATORS = __DIR__ . '/../../../config/set/common/operators.php'; - /** - * @api - */ - public const string STRINGS = __DIR__ . '/../../../config/set/common/strings.php'; - /** * @api */ diff --git a/tests/Configuration/EditorConfig/EditorConfigFactoryTest.php b/tests/Configuration/EditorConfig/EditorConfigFactoryTest.php index 15ea0fcf20c..149a91fefe6 100644 --- a/tests/Configuration/EditorConfig/EditorConfigFactoryTest.php +++ b/tests/Configuration/EditorConfig/EditorConfigFactoryTest.php @@ -47,7 +47,7 @@ public function testParsingInvalidIniFile(): void $this->expectException(Exception::class); $editorConfigFactory = new EditorConfigFactory(); - @$editorConfigFactory->parse(<<<'INI' + @$editorConfigFactory->parse(<<assertEquals( new EditorConfigFactory() ->parse( - <<<'INI' + <<assertEquals( new EditorConfigFactory() - ->parse(<<<'INI' + ->parse(<<assertEquals( new EditorConfigFactory() - ->parse(<<<'INI' + ->parse(<<assertEquals( new EditorConfigFactory() - ->parse(<<<'INI' + ->parse(<<assertEquals( new EditorConfigFactory() - ->parse(<<<'INI' + ->parse(<<assertEquals( new EditorConfigFactory() - ->parse(<<<'INI' + ->parse(<<assertEquals( new EditorConfigFactory() ->parse( - <<<'INI' + <<assertEquals( new EditorConfigFactory() ->parse( - <<<'INI' + <<assertEquals( new EditorConfigFactory() - ->parse( - <<<'INI' + ->parse(<<assertEquals( new EditorConfigFactory() ->parse( - <<<'INI' + <<assertEquals( new EditorConfigFactory() - ->parse(<<<'INI' + ->parse(<<assertEquals( new EditorConfigFactory() - ->parse(<<<'INI' + ->parse(<<assertEquals( new EditorConfigFactory() - ->parse(<<<'INI' + ->parse(<<assertEquals( new EditorConfigFactory() - ->parse(<<<'INI' + ->parse(<< Date: Sat, 20 Jun 2026 16:25:20 +0200 Subject: [PATCH 3/5] extend sets further --- config/set/common/cleanup.php | 11 +++++- config/set/common/comments.php | 2 ++ config/set/common/namespaces.php | 10 ++++-- config/set/common/operators.php | 6 ++++ .../Commenting/AddMissingParamNameFixer.php | 2 +- .../src/TokenRunner/TokenFinder.php | 2 +- scoper.php | 34 +++++++++---------- src/Config/ECSConfig.php | 2 +- src/Config/Level/ArrayLevel.php | 5 +++ src/Config/Level/ControlStructuresLevel.php | 14 ++++++++ src/Config/Level/DocblockLevel.php | 14 ++++++++ src/Config/Level/SpacesLevel.php | 2 ++ src/Skipper/Contract/SkipVoterInterface.php | 4 +-- src/Skipper/Matcher/FileInfoMatcher.php | 4 +-- .../SkipVoter/ClassAndCodeSkipVoter.php | 4 +-- src/Skipper/SkipVoter/ClassSkipVoter.php | 4 +-- src/Skipper/SkipVoter/MessageSkipVoter.php | 4 +-- src/Skipper/SkipVoter/PathSkipVoter.php | 4 +-- src/Skipper/Skipper/SkipSkipper.php | 2 +- src/Skipper/Skipper/Skipper.php | 4 +-- src/ValueObject/Configuration.php | 6 ++-- 21 files changed, 98 insertions(+), 42 deletions(-) diff --git a/config/set/common/cleanup.php b/config/set/common/cleanup.php index d1c811f364e..3281d3c2733 100644 --- a/config/set/common/cleanup.php +++ b/config/set/common/cleanup.php @@ -2,9 +2,18 @@ declare(strict_types=1); +use PhpCsFixer\Fixer\CastNotation\NoShortBoolCastFixer; +use PhpCsFixer\Fixer\ClassNotation\NoNullPropertyInitializationFixer; +use PhpCsFixer\Fixer\FunctionNotation\LambdaNotUsedImportFixer; use PhpCsFixer\Fixer\ReturnNotation\NoUselessReturnFixer; use PhpCsFixer\Fixer\Semicolon\NoEmptyStatementFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; return ECSConfig::configure() - ->withRules([NoEmptyStatementFixer::class, NoUselessReturnFixer::class]); + ->withRules([ + NoEmptyStatementFixer::class, + NoUselessReturnFixer::class, + LambdaNotUsedImportFixer::class, + NoNullPropertyInitializationFixer::class, + NoShortBoolCastFixer::class, + ]); diff --git a/config/set/common/comments.php b/config/set/common/comments.php index 60f493af1d8..5bb82a9d3fe 100644 --- a/config/set/common/comments.php +++ b/config/set/common/comments.php @@ -3,6 +3,7 @@ declare(strict_types=1); use PHP_CodeSniffer\Standards\Generic\Sniffs\VersionControl\GitMergeConflictSniff; +use PhpCsFixer\Fixer\Comment\MultilineCommentOpeningClosingFixer; use PhpCsFixer\Fixer\Comment\NoEmptyCommentFixer; use PhpCsFixer\Fixer\Comment\SingleLineCommentSpacingFixer; use PhpCsFixer\Fixer\Comment\SingleLineCommentStyleFixer; @@ -14,4 +15,5 @@ NoEmptyCommentFixer::class, SingleLineCommentSpacingFixer::class, SingleLineCommentStyleFixer::class, + MultilineCommentOpeningClosingFixer::class, ]); diff --git a/config/set/common/namespaces.php b/config/set/common/namespaces.php index ee345d61b62..d2b2b2301d2 100644 --- a/config/set/common/namespaces.php +++ b/config/set/common/namespaces.php @@ -2,12 +2,16 @@ declare(strict_types=1); +use PhpCsFixer\Fixer\Import\NoUnneededImportAliasFixer; use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer; use PhpCsFixer\Fixer\Import\OrderedImportsFixer; use PhpCsFixer\Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; return ECSConfig::configure() - ->withRules( - [NoUnusedImportsFixer::class, OrderedImportsFixer::class, SingleBlankLineBeforeNamespaceFixer::class] - ); + ->withRules([ + NoUnusedImportsFixer::class, + OrderedImportsFixer::class, + SingleBlankLineBeforeNamespaceFixer::class, + NoUnneededImportAliasFixer::class, + ]); diff --git a/config/set/common/operators.php b/config/set/common/operators.php index a769b97803c..2be8b9a8727 100644 --- a/config/set/common/operators.php +++ b/config/set/common/operators.php @@ -2,10 +2,13 @@ declare(strict_types=1); +use PhpCsFixer\Fixer\Operator\AssignNullCoalescingToCoalesceEqualFixer; use PhpCsFixer\Fixer\Operator\LongToShorthandOperatorFixer; use PhpCsFixer\Fixer\Operator\NoUselessConcatOperatorFixer; use PhpCsFixer\Fixer\Operator\NoUselessNullsafeOperatorFixer; +use PhpCsFixer\Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer; use PhpCsFixer\Fixer\Operator\StandardizeNotEqualsFixer; +use PhpCsFixer\Fixer\Operator\TernaryToNullCoalescingFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; return ECSConfig::configure() @@ -14,4 +17,7 @@ NoUselessNullsafeOperatorFixer::class, StandardizeNotEqualsFixer::class, LongToShorthandOperatorFixer::class, + ObjectOperatorWithoutWhitespaceFixer::class, + TernaryToNullCoalescingFixer::class, + AssignNullCoalescingToCoalesceEqualFixer::class, ]); diff --git a/packages/coding-standard/src/Fixer/Commenting/AddMissingParamNameFixer.php b/packages/coding-standard/src/Fixer/Commenting/AddMissingParamNameFixer.php index 1b57b21a39f..73b537cba2a 100644 --- a/packages/coding-standard/src/Fixer/Commenting/AddMissingParamNameFixer.php +++ b/packages/coding-standard/src/Fixer/Commenting/AddMissingParamNameFixer.php @@ -141,7 +141,7 @@ private function shouldSkipLine(Line $line): bool private function createNewLineContent(string $newArgumentName, Line $line): string { // @see https://regex101.com/r/4FL49H/1 - $missingDollarSignPattern = '#(@param\s+([\w\|\[\]\\\]+\s)?)(' . ltrim($newArgumentName, '$') . ')#'; + $missingDollarSignPattern = '#(@param\s+([\w\|\[\]\\\\]+\s)?)(' . ltrim($newArgumentName, '$') . ')#'; // missing \$ case - possibly own worker if (Regex::match($line->getContent(), $missingDollarSignPattern)) { diff --git a/packages/coding-standard/src/TokenRunner/TokenFinder.php b/packages/coding-standard/src/TokenRunner/TokenFinder.php index 9158bf24036..422bae71c48 100644 --- a/packages/coding-standard/src/TokenRunner/TokenFinder.php +++ b/packages/coding-standard/src/TokenRunner/TokenFinder.php @@ -13,7 +13,7 @@ final class TokenFinder /** * @param Tokens $tokens */ - public function getPreviousMeaningfulToken(Tokens $tokens, int | Token $position): Token + public function getPreviousMeaningfulToken(Tokens $tokens, int|Token $position): Token { if (is_int($position)) { return $this->findPreviousTokenByPosition($tokens, $position); diff --git a/scoper.php b/scoper.php index 554225cbb86..532b14e39c3 100644 --- a/scoper.php +++ b/scoper.php @@ -42,14 +42,14 @@ // excluded 'exclude-namespaces' => [ - '#^Symplify\\\EasyCodingStandard#', - '#^Symplify\\\CodingStandard#', + '#^Symplify\\\\EasyCodingStandard#', + '#^Symplify\\\\CodingStandard#', '#^PhpCsFixer#', '#^PHP_CodeSniffer#', - '#^Symfony\\\Polyfill#', - '#^PHPUnit\\\Framework#', - '#^PHPUnit\\\Runner#', - '#^PHPUnit\\\Util#', + '#^Symfony\\\\Polyfill#', + '#^PHPUnit\\\\Framework#', + '#^PHPUnit\\\\Runner#', + '#^PHPUnit\\\\Util#', ], 'exclude-constants' => [ // Symfony global constants @@ -79,11 +79,11 @@ static function (string $filePath, string $prefix, string $content): string { // php-cs-fixer uses partial namespaces, that are only strings - should be kept untouched // ref.: https://github.com/easy-coding-standard/easy-coding-standard/issues/91 return str_replace([ - $prefix . '\\\ORM\\\Entity', - $prefix . '\\\ORM\\\Mapping\\\Entity', - $prefix . '\\\Mapping\\\Entity', - $prefix . '\\\ODM\\\Document', - ], ['ORM\Entity', 'ORM\Mapping\Entity', 'Mapping\Entity', 'ODM\Document'], $content); + $prefix . '\\\\ORM\\\\Entity', + $prefix . '\\\\ORM\\\\Mapping\\\\Entity', + $prefix . '\\\\Mapping\\\\Entity', + $prefix . '\\\\ODM\\\\Document', + ], ['ORM\\Entity', 'ORM\\Mapping\\Entity', 'Mapping\\Entity', 'ODM\\Document'], $content); }, static function (string $filePath, string $prefix, string $content): string { @@ -122,14 +122,14 @@ function (string $filePath, string $prefix, string $content): string { } // real namespace - $content = Strings::replace($content, '#' . $prefix . '\\\\PHPUnit\\\Framework#', 'PHPUnit\Framework'); - $content = Strings::replace($content, '#' . $prefix . '\\\\PHPUnit\\\Runner#', 'PHPUnit\Runner'); - $content = Strings::replace($content, '#' . $prefix . '\\\\PHPUnit\\\Util#', 'PHPUnit\Util'); + $content = Strings::replace($content, '#' . $prefix . '\\\\PHPUnit\\\\Framework#', 'PHPUnit\Framework'); + $content = Strings::replace($content, '#' . $prefix . '\\\\PHPUnit\\\\Runner#', 'PHPUnit\Runner'); + $content = Strings::replace($content, '#' . $prefix . '\\\\PHPUnit\\\\Util#', 'PHPUnit\Util'); // lower case namespace - $content = Strings::replace($content, '#' . $prefix . '\\\\PHPunit\\\framework#', 'phpunit\framework'); - $content = Strings::replace($content, '#' . $prefix . '\\\\PHPunit\\\runner#', 'phpunit\runner'); - $content = Strings::replace($content, '#' . $prefix . '\\\\PHPunit\\\util#', 'phpunit\util'); + $content = Strings::replace($content, '#' . $prefix . '\\\\phpunit\\\\framework#', 'phpunit\framework'); + $content = Strings::replace($content, '#' . $prefix . '\\\\phpunit\\\\runner#', 'phpunit\runner'); + $content = Strings::replace($content, '#' . $prefix . '\\\\phpunit\\\\util#', 'phpunit\util'); return $content; }, diff --git a/src/Config/ECSConfig.php b/src/Config/ECSConfig.php index 26125cdcfcd..0b140f8be12 100644 --- a/src/Config/ECSConfig.php +++ b/src/Config/ECSConfig.php @@ -201,7 +201,7 @@ public function reportingRealPath(bool $absolute = true): void } /** - * @link https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/index.rst + * @see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/index.rst * @param string[] $setNames */ public function dynamicSets(array $setNames): void diff --git a/src/Config/Level/ArrayLevel.php b/src/Config/Level/ArrayLevel.php index 659730de899..cbd21569b37 100644 --- a/src/Config/Level/ArrayLevel.php +++ b/src/Config/Level/ArrayLevel.php @@ -14,6 +14,7 @@ use PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer; use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer; use PhpCsFixer\Fixer\FixerInterface; +use PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer; use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer; use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer; use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer; @@ -42,6 +43,7 @@ final class ArrayLevel // syntax normalization ArraySyntaxFixer::class, + ListSyntaxFixer::class, TrailingCommaInMultilineFixer::class, // invasive layout changes @@ -61,6 +63,9 @@ final class ArrayLevel ArraySyntaxFixer::class => [ 'syntax' => 'short', ], + ListSyntaxFixer::class => [ + 'syntax' => 'short', + ], TrailingCommaInMultilineFixer::class => [ 'elements' => [TrailingCommaInMultilineFixer::ELEMENTS_ARRAYS], ], diff --git a/src/Config/Level/ControlStructuresLevel.php b/src/Config/Level/ControlStructuresLevel.php index 9ba95af700c..28f82a83c57 100644 --- a/src/Config/Level/ControlStructuresLevel.php +++ b/src/Config/Level/ControlStructuresLevel.php @@ -10,9 +10,15 @@ use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer; use PhpCsFixer\Fixer\ClassNotation\SelfAccessorFixer; use PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer; +use PhpCsFixer\Fixer\ControlStructure\IncludeFixer; +use PhpCsFixer\Fixer\ControlStructure\NoAlternativeSyntaxFixer; +use PhpCsFixer\Fixer\ControlStructure\NoSuperfluousElseifFixer; use PhpCsFixer\Fixer\ControlStructure\NoUselessElseFixer; +use PhpCsFixer\Fixer\ControlStructure\SimplifiedIfReturnFixer; +use PhpCsFixer\Fixer\ControlStructure\SwitchContinueToBreakFixer; use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer; use PhpCsFixer\Fixer\FixerInterface; +use PhpCsFixer\Fixer\FunctionNotation\NullableTypeDeclarationForDefaultNullValueFixer; use PhpCsFixer\Fixer\LanguageConstruct\ExplicitIndirectVariableFixer; use PhpCsFixer\Fixer\LanguageConstruct\FunctionToConstantFixer; use PhpCsFixer\Fixer\LanguageConstruct\IsNullFixer; @@ -45,6 +51,7 @@ final class ControlStructuresLevel FunctionToConstantFixer::class, StandardizeIncrementFixer::class, NewWithBracesFixer::class, + NullableTypeDeclarationForDefaultNullValueFixer::class, // string and variable handling ExplicitStringVariableFixer::class, @@ -55,9 +62,16 @@ final class ControlStructuresLevel ClassDefinitionFixer::class, SingleClassElementPerStatementFixer::class, + // control-flow normalization + IncludeFixer::class, + NoAlternativeSyntaxFixer::class, + NoSuperfluousElseifFixer::class, + SwitchContinueToBreakFixer::class, + // invasive control-flow / ordering changes YodaStyleFixer::class, NoUselessElseFixer::class, + SimplifiedIfReturnFixer::class, OrderedClassElementsFixer::class, ]; diff --git a/src/Config/Level/DocblockLevel.php b/src/Config/Level/DocblockLevel.php index 8564326936b..22cd53894e8 100644 --- a/src/Config/Level/DocblockLevel.php +++ b/src/Config/Level/DocblockLevel.php @@ -7,14 +7,21 @@ use PHP_CodeSniffer\Sniffs\Sniff; use PhpCsFixer\Fixer\Comment\NoTrailingWhitespaceInCommentFixer; use PhpCsFixer\Fixer\FixerInterface; +use PhpCsFixer\Fixer\Phpdoc\AlignMultilineCommentFixer; +use PhpCsFixer\Fixer\Phpdoc\NoBlankLinesAfterPhpdocFixer; use PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer; use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocIndentFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocInlineTagNormalizerFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocLineSpanFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocNoAccessFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocNoAliasTagFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocNoDuplicateTypesFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocNoEmptyReturnFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocNoPackageFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocOrderByValueFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocScalarFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocTagCasingFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimConsecutiveBlankLineSeparationFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer; @@ -71,10 +78,14 @@ final class DocblockLevel PhpdocTrimFixer::class, PhpdocTrimConsecutiveBlankLineSeparationFixer::class, PhpdocIndentFixer::class, + NoBlankLinesAfterPhpdocFixer::class, + AlignMultilineCommentFixer::class, // type / formatting normalization PhpdocTagCasingFixer::class, + PhpdocInlineTagNormalizerFixer::class, PhpdocNoDuplicateTypesFixer::class, + PhpdocScalarFixer::class, PhpdocTypesFixer::class, PhpdocLineSpanFixer::class, PhpdocVarWithoutNameFixer::class, @@ -82,6 +93,9 @@ final class DocblockLevel PhpdocOrderByValueFixer::class, // dropping content + PhpdocNoAliasTagFixer::class, + PhpdocNoAccessFixer::class, + PhpdocNoPackageFixer::class, NoEmptyPhpdocFixer::class, PhpdocNoEmptyReturnFixer::class, RemoveUselessDefaultCommentFixer::class, diff --git a/src/Config/Level/SpacesLevel.php b/src/Config/Level/SpacesLevel.php index 9c7ed11be56..04742a82d49 100644 --- a/src/Config/Level/SpacesLevel.php +++ b/src/Config/Level/SpacesLevel.php @@ -28,6 +28,7 @@ use PhpCsFixer\Fixer\Whitespace\NoSpacesAroundOffsetFixer; use PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer; use PhpCsFixer\Fixer\Whitespace\TypeDeclarationSpacesFixer; +use PhpCsFixer\Fixer\Whitespace\TypesSpacesFixer; use Symplify\CodingStandard\Fixer\Spacing\StandaloneLinePromotedPropertyFixer; /** @@ -65,6 +66,7 @@ final class SpacesLevel TernaryOperatorSpacesFixer::class, ReturnTypeDeclarationFixer::class, TypeDeclarationSpacesFixer::class, + TypesSpacesFixer::class, SuperfluousWhitespaceSniff::class, // configurable, more impactful diff --git a/src/Skipper/Contract/SkipVoterInterface.php b/src/Skipper/Contract/SkipVoterInterface.php index 2918d8962e5..8c914a01f3a 100644 --- a/src/Skipper/Contract/SkipVoterInterface.php +++ b/src/Skipper/Contract/SkipVoterInterface.php @@ -8,7 +8,7 @@ interface SkipVoterInterface { - public function match(string | object $element): bool; + public function match(string|object $element): bool; - public function shouldSkip(string | object $element, SplFileInfo | string $file): bool; + public function shouldSkip(string|object $element, SplFileInfo|string $file): bool; } diff --git a/src/Skipper/Matcher/FileInfoMatcher.php b/src/Skipper/Matcher/FileInfoMatcher.php index f38f880dff5..58f13454cda 100644 --- a/src/Skipper/Matcher/FileInfoMatcher.php +++ b/src/Skipper/Matcher/FileInfoMatcher.php @@ -21,7 +21,7 @@ public function __construct( /** * @param string[] $filePatterns */ - public function doesFileInfoMatchPatterns(SplFileInfo | string $fileInfo, array $filePatterns): bool + public function doesFileInfoMatchPatterns(SplFileInfo|string $fileInfo, array $filePatterns): bool { return array_any( $filePatterns, @@ -32,7 +32,7 @@ public function doesFileInfoMatchPatterns(SplFileInfo | string $fileInfo, array /** * Supports both relative and absolute $file path. They differ for PHP-CS-Fixer and PHP_CodeSniffer. */ - private function doesFileInfoMatchPattern(SplFileInfo | string $file, string $ignoredPath): bool + private function doesFileInfoMatchPattern(SplFileInfo|string $file, string $ignoredPath): bool { $filePath = $file instanceof SplFileInfo ? $file->getRealPath() : $file; diff --git a/src/Skipper/SkipVoter/ClassAndCodeSkipVoter.php b/src/Skipper/SkipVoter/ClassAndCodeSkipVoter.php index 59fbf7ecff1..83f063fb2f7 100644 --- a/src/Skipper/SkipVoter/ClassAndCodeSkipVoter.php +++ b/src/Skipper/SkipVoter/ClassAndCodeSkipVoter.php @@ -20,7 +20,7 @@ public function __construct( ) { } - public function match(string | object $element): bool + public function match(string|object $element): bool { if (! is_string($element)) { return false; @@ -29,7 +29,7 @@ public function match(string | object $element): bool return substr_count($element, '.') === 1; } - public function shouldSkip(string | object $element, SplFileInfo | string $file): bool + public function shouldSkip(string|object $element, SplFileInfo|string $file): bool { if (is_object($element)) { return false; diff --git a/src/Skipper/SkipVoter/ClassSkipVoter.php b/src/Skipper/SkipVoter/ClassSkipVoter.php index 3ad72af82a5..2829bf6d053 100644 --- a/src/Skipper/SkipVoter/ClassSkipVoter.php +++ b/src/Skipper/SkipVoter/ClassSkipVoter.php @@ -17,7 +17,7 @@ public function __construct( ) { } - public function match(string | object $element): bool + public function match(string|object $element): bool { if (is_object($element)) { return true; @@ -26,7 +26,7 @@ public function match(string | object $element): bool return class_exists($element) || interface_exists($element); } - public function shouldSkip(string | object $element, SplFileInfo | string $file): bool + public function shouldSkip(string|object $element, SplFileInfo|string $file): bool { $skippedClasses = $this->skippedClassResolver->resolve(); return $this->skipSkipper->doesMatchSkip($element, $file, $skippedClasses); diff --git a/src/Skipper/SkipVoter/MessageSkipVoter.php b/src/Skipper/SkipVoter/MessageSkipVoter.php index feb055bc365..7ae4f26c1ee 100644 --- a/src/Skipper/SkipVoter/MessageSkipVoter.php +++ b/src/Skipper/SkipVoter/MessageSkipVoter.php @@ -17,7 +17,7 @@ public function __construct( ) { } - public function match(string | object $element): bool + public function match(string|object $element): bool { if (is_object($element)) { return false; @@ -26,7 +26,7 @@ public function match(string | object $element): bool return substr_count($element, ' ') > 0; } - public function shouldSkip(string | object $element, SplFileInfo | string $file): bool + public function shouldSkip(string|object $element, SplFileInfo|string $file): bool { if (is_object($element)) { return false; diff --git a/src/Skipper/SkipVoter/PathSkipVoter.php b/src/Skipper/SkipVoter/PathSkipVoter.php index ffda0053984..4b8f974313c 100644 --- a/src/Skipper/SkipVoter/PathSkipVoter.php +++ b/src/Skipper/SkipVoter/PathSkipVoter.php @@ -17,12 +17,12 @@ public function __construct( ) { } - public function match(string | object $element): bool + public function match(string|object $element): bool { return true; } - public function shouldSkip(string | object $element, SplFileInfo | string $file): bool + public function shouldSkip(string|object $element, SplFileInfo|string $file): bool { $skippedPaths = $this->skippedPathsResolver->resolve(); return $this->fileInfoMatcher->doesFileInfoMatchPatterns($file, $skippedPaths); diff --git a/src/Skipper/Skipper/SkipSkipper.php b/src/Skipper/Skipper/SkipSkipper.php index eeaa8b12ab2..fb40a766c50 100644 --- a/src/Skipper/Skipper/SkipSkipper.php +++ b/src/Skipper/Skipper/SkipSkipper.php @@ -20,7 +20,7 @@ public function __construct( /** * @param array $skippedClasses */ - public function doesMatchSkip(object | string $checker, SplFileInfo | string $file, array $skippedClasses): bool + public function doesMatchSkip(object|string $checker, SplFileInfo|string $file, array $skippedClasses): bool { foreach ($skippedClasses as $skippedClass => $skippedFiles) { if (! is_a($checker, $skippedClass, true)) { diff --git a/src/Skipper/Skipper/Skipper.php b/src/Skipper/Skipper/Skipper.php index 5e82240bebb..f7cd23b1ffc 100644 --- a/src/Skipper/Skipper/Skipper.php +++ b/src/Skipper/Skipper/Skipper.php @@ -32,7 +32,7 @@ public function __construct( $this->skipVoters = [$classAndCodeSkipVoter, $classSkipVoter, $messageSkipVoter, $pathSkipVoter]; } - public function shouldSkipElement(string | object $element): bool + public function shouldSkipElement(string|object $element): bool { return $this->shouldSkipElementAndFilePath($element, __FILE__); } @@ -42,7 +42,7 @@ public function shouldSkipFilePath(string $filePath): bool return $this->shouldSkipElementAndFilePath(self::FILE_ELEMENT, $filePath); } - public function shouldSkipElementAndFilePath(string | object $element, string $filePath): bool + public function shouldSkipElementAndFilePath(string|object $element, string $filePath): bool { foreach ($this->skipVoters as $skipVoter) { if (! $skipVoter->match($element)) { diff --git a/src/ValueObject/Configuration.php b/src/ValueObject/Configuration.php index 1c2dfa900f4..1536eec2e4e 100644 --- a/src/ValueObject/Configuration.php +++ b/src/ValueObject/Configuration.php @@ -20,9 +20,9 @@ public function __construct( private string $outputFormat = ConsoleOutputFormatter::NAME, private bool $isParallel = false, private ?string $config = null, - private string | null $parallelPort = null, - private string | null $parallelIdentifier = null, - private string | null $memoryLimit = null, + private string|null $parallelPort = null, + private string|null $parallelIdentifier = null, + private string|null $memoryLimit = null, private bool $showDiffs = true, private bool $reportingWithRealPath = false ) { From 9bab8dd1aea77fe8b32e202630b1af082eb94eab Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 20 Jun 2026 16:38:50 +0200 Subject: [PATCH 4/5] merge operators to control structures --- config/set/common.php | 1 - config/set/common/operators.php | 23 --------------------- src/Config/Level/ControlStructuresLevel.php | 16 ++++++++++++++ src/Configuration/ECSConfigBuilder.php | 7 ------- src/ValueObject/Set/SetList.php | 5 ----- 5 files changed, 16 insertions(+), 36 deletions(-) delete mode 100644 config/set/common/operators.php diff --git a/config/set/common.php b/config/set/common.php index e5b72984343..8ae083f43d5 100644 --- a/config/set/common.php +++ b/config/set/common.php @@ -14,7 +14,6 @@ SetList::NAMESPACES, SetList::SPACES, SetList::CASING, - SetList::OPERATORS, SetList::CLEANUP, SetList::CLEAN_CODE, ]); diff --git a/config/set/common/operators.php b/config/set/common/operators.php deleted file mode 100644 index 2be8b9a8727..00000000000 --- a/config/set/common/operators.php +++ /dev/null @@ -1,23 +0,0 @@ -withRules([ - NoUselessConcatOperatorFixer::class, - NoUselessNullsafeOperatorFixer::class, - StandardizeNotEqualsFixer::class, - LongToShorthandOperatorFixer::class, - ObjectOperatorWithoutWhitespaceFixer::class, - TernaryToNullCoalescingFixer::class, - AssignNullCoalescingToCoalesceEqualFixer::class, - ]); diff --git a/src/Config/Level/ControlStructuresLevel.php b/src/Config/Level/ControlStructuresLevel.php index 28f82a83c57..b09a9be1b2f 100644 --- a/src/Config/Level/ControlStructuresLevel.php +++ b/src/Config/Level/ControlStructuresLevel.php @@ -22,8 +22,15 @@ use PhpCsFixer\Fixer\LanguageConstruct\ExplicitIndirectVariableFixer; use PhpCsFixer\Fixer\LanguageConstruct\FunctionToConstantFixer; use PhpCsFixer\Fixer\LanguageConstruct\IsNullFixer; +use PhpCsFixer\Fixer\Operator\AssignNullCoalescingToCoalesceEqualFixer; +use PhpCsFixer\Fixer\Operator\LongToShorthandOperatorFixer; use PhpCsFixer\Fixer\Operator\NewWithBracesFixer; +use PhpCsFixer\Fixer\Operator\NoUselessConcatOperatorFixer; +use PhpCsFixer\Fixer\Operator\NoUselessNullsafeOperatorFixer; +use PhpCsFixer\Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer; use PhpCsFixer\Fixer\Operator\StandardizeIncrementFixer; +use PhpCsFixer\Fixer\Operator\StandardizeNotEqualsFixer; +use PhpCsFixer\Fixer\Operator\TernaryToNullCoalescingFixer; use PhpCsFixer\Fixer\PhpUnit\PhpUnitMethodCasingFixer; use PhpCsFixer\Fixer\StringNotation\ExplicitStringVariableFixer; use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer; @@ -53,6 +60,15 @@ final class ControlStructuresLevel NewWithBracesFixer::class, NullableTypeDeclarationForDefaultNullValueFixer::class, + // operator spacing and simplification + ObjectOperatorWithoutWhitespaceFixer::class, + StandardizeNotEqualsFixer::class, + NoUselessConcatOperatorFixer::class, + NoUselessNullsafeOperatorFixer::class, + LongToShorthandOperatorFixer::class, + TernaryToNullCoalescingFixer::class, + AssignNullCoalescingToCoalesceEqualFixer::class, + // string and variable handling ExplicitStringVariableFixer::class, ExplicitIndirectVariableFixer::class, diff --git a/src/Configuration/ECSConfigBuilder.php b/src/Configuration/ECSConfigBuilder.php index 45db5340403..9fe12796c32 100644 --- a/src/Configuration/ECSConfigBuilder.php +++ b/src/Configuration/ECSConfigBuilder.php @@ -254,8 +254,6 @@ public function withPreparedSets( bool $controlStructures = false, /** @see SetList::CASING */ bool $casing = false, - /** @see SetList::OPERATORS */ - bool $operators = false, /** @see SetList::CLEANUP */ bool $cleanup = false, /** @@ -293,7 +291,6 @@ public function withPreparedSets( 'controlStructures' => $controlStructures, 'comments' => $comments, 'casing' => $casing, - 'operators' => $operators, 'cleanup' => $cleanup, ]))) !== []) { throw new SuperfluousConfigurationException( @@ -338,10 +335,6 @@ public function withPreparedSets( $this->sets[] = SetList::CASING; } - if ($operators) { - $this->sets[] = SetList::OPERATORS; - } - if ($cleanup) { $this->sets[] = SetList::CLEANUP; } diff --git a/src/ValueObject/Set/SetList.php b/src/ValueObject/Set/SetList.php index dd9cfde2d4e..5c236d985b2 100644 --- a/src/ValueObject/Set/SetList.php +++ b/src/ValueObject/Set/SetList.php @@ -76,11 +76,6 @@ final class SetList */ public const string CASING = __DIR__ . '/../../../config/set/common/casing.php'; - /** - * @api - */ - public const string OPERATORS = __DIR__ . '/../../../config/set/common/operators.php'; - /** * @api */ From 1935a9abf4a22a235e1af03a49e225c41201e9a9 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 20 Jun 2026 16:52:17 +0200 Subject: [PATCH 5/5] update README with new sets --- build/target-repository/README.md | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/build/target-repository/README.md b/build/target-repository/README.md index d828564ff63..0d3ef1d1e29 100644 --- a/build/target-repository/README.md +++ b/build/target-repository/README.md @@ -89,6 +89,42 @@ return ECSConfig::configure()
+### Prepared Sets + +`->withPreparedSets()` bundles curated rule sets. Enable the whole `common` set, or pick single topics: + +```php +use Symplify\EasyCodingStandard\Config\ECSConfig; + +return ECSConfig::configure() + ->withPaths([__DIR__ . '/src', __DIR__ . '/tests']) + ->withPreparedSets( + arrays: true, + spaces: true, + namespaces: true, + docblocks: true, + controlStructures: true, + comments: true, + casing: true, + cleanup: true, + ); +``` + +| Set | What it covers | +| --- | --- | +| `arrays` | array syntax, spacing, trailing commas, indentation | +| `spaces` | whitespace, operator/type spacing, blank lines | +| `namespaces` | imports ordering, unused/needless-alias imports | +| `docblocks` | phpdoc tags, types, alignment, cleanup | +| `controlStructures` | control flow, casing, operators, class structure | +| `comments` | comment style, spacing, empty-comment cleanup | +| `casing` | native function/type, magic method, literal casing | +| `cleanup` | dead statements, useless returns/casts, unused closure imports | + +Or enable everything at once with `->withPreparedSets(common: true)`. + +
+ Do you want to include one of sets from [php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/index.rst)? You can: