From 1c3a4d757184a056afa1a0ebe421b58dcc34bc7c Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 9 Aug 2026 18:21:48 +0200 Subject: [PATCH] [remove] Remove deprecated NewInInitializerRector Deprecated since 2026-04 in #7913. The rewrite is not equivalent: a promoted default only applies when the argument is omitted, so an explicit null argument lands as null instead of the coalesced fallback object. --- phpstan.neon | 2 - .../ClassMethod/NewInInitializerRector.php | 73 ------------------- 2 files changed, 75 deletions(-) delete mode 100644 rules/Php81/Rector/ClassMethod/NewInInitializerRector.php diff --git a/phpstan.neon b/phpstan.neon index 182522df8d4..0741d929a8e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -458,9 +458,7 @@ parameters: - tests/PhpParser/NodeTraverser/StopTraverseOnTypeChange/Class_ # deprecated rule - - '#Register "Rector\\Php81\\Rector\\ClassMethod\\NewInInitializerRector" service to "php81\.php" config set#' - '#Register "Rector\\Php70\\Rector\\StaticCall\\StaticCallOnNonStaticToInstanceCallRector" service to "php70\.php" config set#' - - '#Class "Rector\\Php81\\Rector\\ClassMethod\\NewInInitializerRector" is missing @see annotation with test case class reference#' - '#Class "Rector\\Php70\\Rector\\StaticCall\\StaticCallOnNonStaticToInstanceCallRector" is missing @see annotation with test case class reference#' - '#Class "Rector\\TypeDeclaration\\Rector\\ClassMethod\\StrictStringParamConcatRector" is missing @see annotation with test case class reference#' - '#Class "Rector\\CodingStyle\\Rector\\Enum_\\EnumCaseToPascalCaseRector" is missing @see annotation with test case class reference#' diff --git a/rules/Php81/Rector/ClassMethod/NewInInitializerRector.php b/rules/Php81/Rector/ClassMethod/NewInInitializerRector.php deleted file mode 100644 index fe1e4178e7c..00000000000 --- a/rules/Php81/Rector/ClassMethod/NewInInitializerRector.php +++ /dev/null @@ -1,73 +0,0 @@ -logger = $logger ?? new NullLogger; - } -} -CODE_SAMPLE - - , - <<<'CODE_SAMPLE' -class SomeClass -{ - public function __construct( - private ?Logger $logger = new NullLogger, - ) { - } -} -CODE_SAMPLE - ), - ]); - } - - /** - * @return array> - */ - public function getNodeTypes(): array - { - return [Class_::class]; - } - - /** - * @param Class_ $node - */ - public function refactor(Node $node): ?Node - { - throw new ShouldNotHappenException(sprintf( - '"%s" is deprecated as depends on context. Cannot be automated. Use manually or custom rule where needed instead', - self::class - )); - } - - public function provideMinPhpVersion(): int - { - return PhpVersionFeature::NEW_INITIALIZERS; - } -}