Skip to content

[dx] Extend common sets + Levels with mature non-PSR-12 rules#30

Merged
TomasVotruba merged 5 commits into
mainfrom
tv-extended-common-sets
Jun 20, 2026
Merged

[dx] Extend common sets + Levels with mature non-PSR-12 rules#30
TomasVotruba merged 5 commits into
mainfrom
tv-extended-common-sets

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Jun 20, 2026

Copy link
Copy Markdown
Member

What

Broaden the ECS common sets with mature, non-risky PHP-CS-Fixer rules that are not part of the bundled PSR-12 set — extending the four gradual-adoption Levels and adding two new flat sets.

2 new sets · 42 new rules. Every added rule below shows a before→after example.


New set: casing.php (SetList::CASING) — 5 rules

-STRLEN($name);                 // NativeFunctionCasing
+strlen($name);
-function foo(): INT {}          // NativeTypeDeclarationCasing
+function foo(): int {}
-$x = 0Xff; $y = 0B11;           // IntegerLiteralCase
+$x = 0xFF; $y = 0b11;
-$obj->__ToString();            // MagicMethodCasing
+$obj->__toString();
-throw new \exception();         // ClassReferenceNameCasing
+throw new \Exception();

New set: cleanup.php (SetList::CLEANUP) — 5 rules

-$a = 1;;                        // NoEmptyStatement
+$a = 1;
 function f() {
-    doThing();
-    return;                     // NoUselessReturn
 }
-$fn = function () use ($unused) { return 1; };   // LambdaNotUsedImport
+$fn = function () { return 1; };
-public ?int $x = null;          // NoNullPropertyInitialization
+public ?int $x;
-$b = !!$x;                      // NoShortBoolCast
+$b = (bool) $x;

SpacesLevel — +1 rule

-function f(int | string $x) {}  // TypesSpaces
+function f(int|string $x) {}

ArrayLevel — +3 rules

-$a = [ ];                       // NoWhitespaceInEmptyArray
+$a = [];
-$a = [1   =>   'x'];            // NoMultilineWhitespaceAroundDoubleArrow
+$a = [1 => 'x'];
-list($a, $b) = $data;           // ListSyntax (short)
+[$a, $b] = $data;

DocblockLevel — +10 rules

-/** @Param int $x */            // PhpdocTagCasing
+/** @param int $x */
-/** @var int|int|string $x */   // PhpdocNoDuplicateTypes
+/** @var int|string $x */
-/** @return integer */          // PhpdocScalar
+/** @return int */
 /** @var int $x */
-
 $x = 1;                         // NoBlankLinesAfterPhpdoc (drops blank line)
-/** @type int $x */             // PhpdocNoAliasTag (@type→@var, @link→@see)
+/** @var int $x */
-/** @access private */          // PhpdocNoAccess (removed)
-/** @package Foo */             // PhpdocNoPackage (removed)
-/** {{ @link }} */              // PhpdocInlineTagNormalizer
+/** {@link} */

Plus PhpdocOrderByValueFixer (sorts annotations like @covers by value) and AlignMultilineCommentFixer (aligns leading * column).

ControlStructuresLevel — control-flow (+6 rules)

-include("file.php");            // Include
+include "file.php";
-if ($x): echo 1; endif;         // NoAlternativeSyntax
+if ($x) { echo 1; }
-else { if ($x) {} }             // NoSuperfluousElseif
+elseif ($x) {}
 switch ($x) {
-    case 1: continue;           // SwitchContinueToBreak
+    case 1: break;
 }
-if ($x) { return true; } return false;   // SimplifiedIfReturn
+return (bool) $x;
-function f(int $x = null) {}     // NullableTypeDeclarationForDefaultNullValue (PHP 8.4)
+function f(?int $x = null) {}

ControlStructuresLevel — operators, merged from former operators set (+7 rules)

-$this ->foo();                  // ObjectOperatorWithoutWhitespace
+$this->foo();
-if ($a <> $b) {}                // StandardizeNotEquals
+if ($a != $b) {}
-$s = 'a' . 'b';                 // NoUselessConcatOperator
+$s = 'ab';
-echo $this?->parentMethod();    // NoUselessNullsafeOperator
+echo $this->parentMethod();
-$a = $a + 1;                    // LongToShorthandOperator
+$a += 1;
-$x = isset($a) ? $a : $b;       // TernaryToNullCoalescing
+$x = $a ?? $b;
-$a = $a ?? $b;                  // AssignNullCoalescingToCoalesceEqual
+$a ??= $b;

Extended flat sets

comments.php — +4 rules

-//                              // NoEmptyComment (removed)
-//comment                       // SingleLineCommentSpacing
+// comment
-# comment                       // SingleLineCommentStyle
+// comment
-/******* foo ******/            // MultilineCommentOpeningClosing
+/* foo */

namespaces.php — +1 rule

-use Foo\Bar as Bar;             // NoUnneededImportAlias
+use Foo\Bar;

Wiring

  • SetList: new @api consts CASING, CLEANUP
  • common.php: both new sets aggregated
  • withPreparedSets(): new named args casing, cleanup + "already in common" conflict check + else-branch handling

Notes / decisions

  • Operators merged into ControlStructuresLevel instead of a standalone set/level.
  • Dropped the originally-proposed strings and operators standalone sets.
  • scoper.php left untouched (matches main).
  • All added rules are deterministic / safe, outside PSR-12, not previously covered by any common set or level.
  • Skipped as opinionated/risky: NumericLiteralSeparator, AttributeEmptyParentheses, ModernSerializationMethods, OrderedTypes, OrderedTraits, FullyQualifiedStrictTypes, PhpdocAlign, plus the whole risky family.

Totals

  • 2 new sets (casing, cleanup)
  • 42 new rules: casing 5 · cleanup 5 · Spaces 1 · Array 3 · Docblock 10 · ControlStructures 13 (control-flow 6 + operators 7) · comments 4 · namespaces 1

Checks

phpstan ✅ · rector ✅ · ecs ✅ · phpunit ✅ (254 tests, 354 assertions)

@TomasVotruba TomasVotruba force-pushed the tv-extended-common-sets branch from 80b8849 to a18769f Compare June 20, 2026 14:27
@TomasVotruba TomasVotruba changed the title [dx] Add new common sets (casing, operators, strings, cleanup) + extend existing [dx] Extend common sets + Levels with mature non-PSR-12 rules Jun 20, 2026
@TomasVotruba TomasVotruba enabled auto-merge (squash) June 20, 2026 14:53
@TomasVotruba TomasVotruba merged commit 9ead380 into main Jun 20, 2026
7 checks passed
@TomasVotruba TomasVotruba deleted the tv-extended-common-sets branch June 20, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant