From 95e9f3deed6d23306304c8eba74bb3846177f0d1 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 9 Aug 2026 18:41:47 +0200 Subject: [PATCH] [remove] Drop nette/utils set, deprecate withComposerBased(netteUtils:) argument The only third-party-library rule in core, delivering a named-argument label on 2 methods of one package. The netteUtils: argument is kept as a no-op with a runtime warning, following the withAttributesSets() precedent. --- config/set/named-args.php | 2 - config/set/nette-utils/composer-based.php | 12 --- .../Fixture/fixture.php.inc | 33 ------- .../Fixture/skip_already_filled.php.inc | 14 --- .../Fixture/skip_no_second_arg.php.inc | 14 --- .../UtilsJsonStaticCallNamedArgRectorTest.php | 28 ------ .../config/configured_rule.php | 9 -- .../UtilsJsonStaticCallNamedArgRector.php | 97 ------------------- src/Configuration/Option.php | 5 + src/Configuration/RectorConfigBuilder.php | 4 +- src/Console/Command/ProcessCommand.php | 1 + src/Reporting/DeprecatedRulesReporter.php | 15 +++ src/Set/ValueObject/SetList.php | 6 -- 13 files changed, 23 insertions(+), 217 deletions(-) delete mode 100644 config/set/nette-utils/composer-based.php delete mode 100644 rules-tests/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector/Fixture/fixture.php.inc delete mode 100644 rules-tests/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector/Fixture/skip_already_filled.php.inc delete mode 100644 rules-tests/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector/Fixture/skip_no_second_arg.php.inc delete mode 100644 rules-tests/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector/UtilsJsonStaticCallNamedArgRectorTest.php delete mode 100644 rules-tests/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector/config/configured_rule.php delete mode 100644 rules/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector.php diff --git a/config/set/named-args.php b/config/set/named-args.php index cf4480a4786..ae54d0d150a 100644 --- a/config/set/named-args.php +++ b/config/set/named-args.php @@ -9,7 +9,6 @@ use Rector\CodeQuality\Rector\FuncCall\SortCallLikeNamedArgsRector; use Rector\Config\RectorConfig; use Rector\DeadCode\Rector\MethodCall\RemoveNullNamedArgOnNullDefaultParamRector; -use Rector\NetteUtils\Rector\StaticCall\UtilsJsonStaticCallNamedArgRector; return static function (RectorConfig $rectorConfig): void { $rectorConfig->rules([ @@ -19,6 +18,5 @@ SortCallLikeNamedArgsRector::class, SortAttributeNamedArgsRector::class, ExplicitAttributeNamedArgsRector::class, - UtilsJsonStaticCallNamedArgRector::class, ]); }; diff --git a/config/set/nette-utils/composer-based.php b/config/set/nette-utils/composer-based.php deleted file mode 100644 index 28d9436e92a..00000000000 --- a/config/set/nette-utils/composer-based.php +++ /dev/null @@ -1,12 +0,0 @@ -rules([UtilsJsonStaticCallNamedArgRector::class]); -}; diff --git a/rules-tests/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector/Fixture/fixture.php.inc b/rules-tests/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector/Fixture/fixture.php.inc deleted file mode 100644 index e60376b94c7..00000000000 --- a/rules-tests/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,33 +0,0 @@ - ------ - diff --git a/rules-tests/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector/Fixture/skip_already_filled.php.inc b/rules-tests/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector/Fixture/skip_already_filled.php.inc deleted file mode 100644 index eb8157d87b1..00000000000 --- a/rules-tests/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector/Fixture/skip_already_filled.php.inc +++ /dev/null @@ -1,14 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector/config/configured_rule.php b/rules-tests/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector/config/configured_rule.php deleted file mode 100644 index 81f622bfc1c..00000000000 --- a/rules-tests/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector/config/configured_rule.php +++ /dev/null @@ -1,9 +0,0 @@ -withRules([UtilsJsonStaticCallNamedArgRector::class]); diff --git a/rules/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector.php b/rules/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector.php deleted file mode 100644 index 0f932ec050b..00000000000 --- a/rules/NetteUtils/Rector/StaticCall/UtilsJsonStaticCallNamedArgRector.php +++ /dev/null @@ -1,97 +0,0 @@ -=4.0'); - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition('Change `' . Json::class . '::encode()` and `decode()` to named args', [ - new CodeSample( - <<<'CODE_SAMPLE' -use Nette\Utils\Json; - -$encodedJson = Json::encode($data, true); -$decodedJson = Json::decode($json, true); - -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -use Nette\Utils\Json; - -$encodedJson = Json::encode($data, pretty: true); -$decodedJson = Json::decode($json, forceArrays: true); -CODE_SAMPLE - ), - ]); - } - - public function getNodeTypes(): array - { - return [StaticCall::class]; - } - - /** - * @param StaticCall $node - */ - public function refactor(Node $node): ?Node - { - if (! $this->isName($node->class, NetteClassName::JSON)) { - return null; - } - - if ($node->isFirstClassCallable()) { - return null; - } - - if (count($node->getArgs()) < 2) { - return null; - } - - if (! $this->isNames($node->name, ['encode', 'decode'])) { - return null; - } - - // flip 2nd arg from true/false to named arg - // check if 2nd arg is named arg already - $secondArg = $node->getArgs()[1]; - - // already set → skip - if ($secondArg->name instanceof Identifier) { - return null; - } - - if ($this->isName($node->name, 'encode')) { - $secondArg->name = new Identifier('pretty'); - return $node; - } - - $secondArg->name = new Identifier('forceArrays'); - return $node; - } -} diff --git a/src/Configuration/Option.php b/src/Configuration/Option.php index 0ff8efb5925..6c3ddb126fe 100644 --- a/src/Configuration/Option.php +++ b/src/Configuration/Option.php @@ -260,6 +260,11 @@ final class Option */ public const string DEPRECATED_ATTRIBUTES_SETS_ARGS = 'deprecated_attributes_sets_args'; + /** + * @internal For reporting deprecated withComposerBased() arguments + */ + public const string DEPRECATED_COMPOSER_BASED_ARGS = 'deprecated_composer_based_args'; + /** * @internal For collect skipped start with short open tag files to be reported */ diff --git a/src/Configuration/RectorConfigBuilder.php b/src/Configuration/RectorConfigBuilder.php index b6424132a97..8569aef678f 100644 --- a/src/Configuration/RectorConfigBuilder.php +++ b/src/Configuration/RectorConfigBuilder.php @@ -765,9 +765,9 @@ public function withComposerBased( $this->sets[] = SymfonySetList::COMPOSER_BASED; } + // deprecated, no longer applied - it only added named args to 2 methods of a single package if ($netteUtils) { - // single set, as every rule inside is bound to the installed nette/utils version on its own - $this->sets[] = SetList::NETTE_UTILS_COMPOSER_BASED; + SimpleParameterProvider::addParameter(Option::DEPRECATED_COMPOSER_BASED_ARGS, 'netteUtils'); } return $this; diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index 8d85b358272..488bb8bb15b 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -187,6 +187,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->deprecatedRulesReporter->reportDeprecatedCacheMetaExtensions(); $this->deprecatedRulesReporter->reportDeprecatedPhpSetsMethods(); $this->deprecatedRulesReporter->reportDeprecatedAttributesSetsArgs(); + $this->deprecatedRulesReporter->reportDeprecatedComposerBasedArgs(); $this->missConfigurationReporter->reportSkippedNeverRegisteredRules(); $this->missConfigurationReporter->reportSkippedNonRectorClasses(); diff --git a/src/Reporting/DeprecatedRulesReporter.php b/src/Reporting/DeprecatedRulesReporter.php index 3a05e6437c0..97dc68d929d 100644 --- a/src/Reporting/DeprecatedRulesReporter.php +++ b/src/Reporting/DeprecatedRulesReporter.php @@ -99,6 +99,21 @@ public function reportDeprecatedAttributesSetsArgs(): void } } + public function reportDeprecatedComposerBasedArgs(): void + { + /** @var string[] $deprecatedComposerBasedArgs */ + $deprecatedComposerBasedArgs = SimpleParameterProvider::provideArrayParameter( + Option::DEPRECATED_COMPOSER_BASED_ARGS + ); + + foreach (array_unique($deprecatedComposerBasedArgs) as $deprecatedComposerBasedArg) { + $this->symfonyStyle->warning(sprintf( + 'The "->withComposerBased(%s: true)" argument is deprecated and no longer applied. It only added named args to 2 methods of a single package, register the rule directly if needed.', + $deprecatedComposerBasedArg + )); + } + } + public function reportDeprecatedRectorUnsupportedMethods(): void { // to be added in related PR diff --git a/src/Set/ValueObject/SetList.php b/src/Set/ValueObject/SetList.php index ef99d8ede9f..c6fa325f779 100644 --- a/src/Set/ValueObject/SetList.php +++ b/src/Set/ValueObject/SetList.php @@ -30,12 +30,6 @@ final class SetList public const string NAMED_ARGS = __DIR__ . '/../../../config/set/named-args.php'; - /** - * Applies to any installed nette/utils version, the rules inside are bound - * to the exact version they are available from - */ - public const string NETTE_UTILS_COMPOSER_BASED = __DIR__ . '/../../../config/set/nette-utils/composer-based.php'; - /** * Opinionated rules that match rector coding standard */