Skip to content

[NetteUtils] Bind nette/utils rules to installed package version - #8275

Merged
TomasVotruba merged 2 commits into
mainfrom
tv-nette-utils
Aug 3, 2026
Merged

[NetteUtils] Bind nette/utils rules to installed package version#8275
TomasVotruba merged 2 commits into
mainfrom
tv-nette-utils

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Aug 3, 2026

Copy link
Copy Markdown
Member

Follows the approach of rectorphp/rector-symfony#979 for nette/utils.

Rules bound to a nette/utils version now declare the constraint themselves via ComposerPackageConstraintInterface, instead of relying on the version-named set they live in:

final class UtilsJsonStaticCallNamedArgRector extends AbstractRector implements ComposerPackageConstraintInterface
{
    public function provideComposerPackageConstraint(): ComposerPackageConstraint
    {
        return new ComposerPackageConstraint('nette/utils', '>=4.0');
    }
}

The bool $pretty / bool $forceArrays params exist from nette/utils 4.0; before that both methods took int $flags, so the named args would produce broken code.

The nette-utils4.php set becomes composer-based.php, registered as a single set - same as PHPUnit and Symfony - as every rule inside is bound to the installed nette/utils version on its own:

         if ($symfony) {
             // single set, as every rule inside is bound to the installed Symfony package version on its own
             $this->sets[] = SymfonySetList::COMPOSER_BASED;
         }
+
+        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;
+        }

With that, the ComposerTriggeredSet in CoreSetProvider and the now unused SetGroup::NETTE_UTILS group are dropped.

Side effect: the rule is also part of named-args.php, a plain set with no composer trigger. There it now skips itself on nette/utils 3 and lower, where it used to produce broken code:

 use Nette\Utils\Json;

-$encodedJson = Json::encode($data, true);
+$encodedJson = Json::encode($data, pretty: true);

Verified with withComposerBased(netteUtils: true):

  Rule                                Package       Requires   Installed   Active
  UtilsJsonStaticCallNamedArgRector   nette/utils   >=4.0      4.1.5.0     yes

Same approach as rectorphp/rector-symfony#979: rules declare their own
composer package constraint, the set is triggered by any installed
nette/utils version.
@TomasVotruba
TomasVotruba merged commit da48be8 into main Aug 3, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the tv-nette-utils branch August 3, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant