github rectorphp/rector 2.6.0
Released Rector 2.6.0

4 hours ago

Composer-based sets - let Rector handle upgrade from composer.json 🥳

The main theme of this release: rules that turn themselves on based on the package versions you actually have installed.

Instead of picking a Symfony or PHPUnit set by version number and guessing what applies, register the composer-based set once. Every rule inside checks composer.json/installed.json and only runs if the installed package version matches its constraint.

use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withComposerBased(
        doctrine: true,
        phpunit: true,
        symfony: true,
        twig: true,
    );

We're working on full coverage. At the moment, PHPUnit and Symfony rules are already migrated to this approach. Not only rules, but also rule configuration can be bound to a package version:

$rectorConfig->ruleWithConfigurationComposerVersionBound(
    SomeRector::class,
    [...],
    'phpunit/phpunit',
    '>=11.0'
);

To see what is active and why, there is a new command:

vendor/bin/rector composer-based
 Composer package bound rules
 ------------------------------- ----------------- ---------- ----------- --------
  Rule                            Package           Requires   Installed   Active
 ------------------------------- ----------------- ---------- ----------- --------
  RemoveExpectAnyFromMockRector   phpunit/phpunit   >=11.0     11.5.2      yes
  RedirectToRouteRector           symfony/...       >=2.6      7.2.1       yes
 ------------------------------- ----------------- ---------- ----------- --------

 ! [NOTE] 2 of 2 composer package bound items are active

And to run only those rules in a single process:

vendor/bin/rector process --composer-based

New features 🥳

  • [Config] Add ruleWithConfigurationComposerVersionBound() (#8244)
  • [composer-based] Add composer-based command (#8246)
  • [composer-based] Report rule configuration bound to installed package version (#8247)
  • [composer-based] Register each rule only once, add --composer-based process filter (#8248)
  • [Configuration] Load single composer-based PHPUnit set in withComposerBased() (#8255)
  • [Configuration] Load single composer-based Symfony set in withComposerBased() (#8259)
  • [Console] Print composer-based rule configuration on separate full-width line (#8256)
  • [Testing] Allow a test case to resolve package versions from a standalone composer.json (#8264)

New rules 🎉

rector-src

  • [DeadCode] RemoveTestsOverriddenPrivateMethodParameterRector (#8254)

rector-phpunit

  • [CodeQuality] AddIntersectionParamToMockObjectParamRector (#755)
  • [PHPUnit 11.0] ExpectsParamToMockObjectRector — for private test method params (#753)
  • [PHPUnit 11.0] MockObjectArgCreateStubToCreateMockRector (#741)
  • [PHPUnit 11.5] AssertContainsOnlyMethodCallRector (#738)

rector-symfony

  • [CodeQuality] LoadValidatorMetadataToAttributeRector (#988)

Bugfixes 🐛

  • [DeadCode] Skip RecastingRemovalRector on array dim fetch value (#8262)
  • [DeadCode] Skip RemoveDefaultValueFromAssignedPropertyRector on early return in constructor-called method (#8261)
  • [DeadCode] Skip static property in RemoveDefaultValueFromAssignedPropertyRector (#8240)
  • [DeadCode] Remove whole assign statement on unused createStub() in tests (#8257)
  • [NodeAnalyzer] Detect always terminated stmts with statements before the return (#8260)
  • [Configuration] Resolve --only rule name with shell-eaten backslashes (#8267)
  • [rector-symfony] Add try/catch fixtures with statements before the return (#986)
# before: quotes were needed to match rule
vendor/bin/rector p --only="\Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector"

# after: simple class name works as well
vendor/bin/rector p --only \Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector
  • [Composer] Prefer composer.json constraint over outdated installed.json version (#8242)
  • Fix InstalledPackageResolver cwd fallback lost by promoted property (#8237)
  • [rector-phpunit] Fix swapped preCondition and postCondition attribute mapping (#746)
  • [rector-phpunit] Handle test traits in DataProviderAnnotationToAttributeRector (#751, #752)

Set changes 📈

  • [Config] Move 3 rules from coding style set to their proper sets — ExplicitPublicClassMethodRector to PHP 5.3, plus one each to code quality and dead code (#8266)
  • [CodingStyle] Remove MinMaxToClampRector from coding style level (#8270)
  • [rector-symfony] Add SymfonySetList::COMPOSER_BASED (#982)
  • [rector-phpunit] Register composer-based set in PHPUnitSetProvider (#748)

Deprecations 💀

Deprecated rules still run, but print a w and will be removed in a future major release.
These were deprecated as not part of any set, risky, opinionated or excluded by most users. Goal is to make Rector useful more to masses and every day user by having valuable and reliable rules.

rector-src

  • EncapsedStringsToSprintfRector (#8265)
  • SimplifyRegexPatternRector (#8263)
  • BinaryOpStandaloneAssignsToDirectRector (#8269)
  • NullableCompareToNullRector (#8268)
  • NestedTernaryToMatchRector (#8241)
  • AddReturnDocblockFromMethodCallDocblockRector (#8239)
  • Gmagick to Imagick set (#8252)
  • withPhp53Sets() ... withPhp74Sets() — use withPhpLevel() instead (#8253)
  • cacheMetaExtension() — reports a warning when used (#8251)

rector-doctrine

  • YamlToAttributeDoctrineMappingRector (#492)
  • DoctrineSetList::YAML_TO_ANNOTATIONS set (#493)

rector-symfony

  • TemplateAnnotationToThisRenderRector (#989)
  • ReturnDirectJsonResponseRector (#987)
  • AutowireAttributeRector (#981)

rector-phpunit

  • WillReturnCallbackFallbackToThrowRector (#740)
  • ReplaceTestFunctionPrefixWithAttributeRector (#739)

Removals 💀

  • [depre] Remove strict-booleans set, deprecated since 2025-10 (#8243)
  • [ChangesReporting] Remove junit output format (#8250)
  • [rector-doctrine] Remove DoctrineDocBlockResolver, deprecated since 2025-05 (#491)
  • [rector-symfony] Remove StringExtensionToConfigBuilderRector, deprecated since 2025-10 (#978)
  • [rector-phpunit] Remove 4 rules deprecated since 2025-10 (#743)
  • [rector-phpunit] Remove deprecated AssertPropertyExistsRector (#742)

Package bonding (composer-based rollout)

  • [rector-symfony] Bond version-specific rules to composer package constraints (#979), include all configured rules in the composer-based set (#980), bond AddViolationToBuildViolationRector to symfony/validator 2.5 (#983), add AuthorizationCheckerIsGrantedExtractorRector to the composer-based set (#985), bond RedirectToRouteRector to symfony/framework-bundle 2.6 (#991)
  • [rector-phpunit] Bond version-specific rules to composer package constraints (#754), bond stub and mock rules to phpunit/phpunit >=11.0 (#750), bond annotation-to-attribute rules to phpunit/phpunit >=10.0 (#744, #745), move composer version bound rules to composer-based set (#747)

Don't miss a new rector release

NewReleases is sending notifications on new releases.