github rectorphp/rector 2.6.2
Released Rector 2.6.2

2 hours ago

The 2.6.0 release introduced composer-based sets. This release finishes the job: every extension package now ships a single composer-based set, and the per-version set providers behind the old guessing game are gone.

use Rector\Config\RectorConfig;

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

Each rule inside checks composer.json/installed.json on its own and runs only if the installed package version matches its constraint. No SymfonySetList::SYMFONY_63, no picking a PHPUnit version by hand. We're working hard to bring Drupal and Laravel community packages to the same system.


Run only the PHP rules (#8322)

A new --php option on the process command runs only rules bound to a minimal PHP version — those implementing MinPhpVersionInterface. Useful to split a PHP upgrade from the rest, without a second config:

vendor/bin/rector process src --php --dry-run

New features 🥳

  • [Process] Add --php option to run only PHP version rules (#8322)
  • [Configuration] Resolve the composer-based set of extension packages in withComposerBased() (#8332), load Doctrine and Twig composer-based sets (#8313)
  • [Configuration] Report explicit error when the --only rule exists but is not registered in rector.php (#8300)
  • [DX] Warn on skipped classes that are not Rector rules (#8323), include the skipped class name in the message (#8325)
  • [DX] Show previous exceptions during bootstrap (#8287)
 [WARNING] This skipped class is not a Rector rule, so it can never be skipped.
           Only classes that implement "Rector\Contract\Rector\RectorInterface"
           can be used in "->withSkip()"

New rules 🎉

rector-src

  • [DeadCode] RemoveRedundantTypeCheckRector (#8307)
 $securityExpression = $operation->getSecurity();
-if (null === $securityExpression || ! is_string($securityExpression)) {
+if (null === $securityExpression) {
     return;
 }

rector-symfony

  • [Configs] EnableValidationAttributesRector (#1004)
  • [Symfony 2.8] Rename Simple(Pre|Form)AuthenticatorInterface from Core to Http namespace (#1031)

rector-phpunit

  • [PHPUnit 12.0] AnyMatcherToNewAnyInvokedCountRector for the deprecated any() matcher (#764)

Bugfixes 🐛

  • [VersionBonding] Cap polyfill rules by the explicitly picked withPhpSets() version (#8315) — withPhpSets(php82: true) with symfony/polyfill-php83 installed no longer produces PHP 8.3 code
  • [CodeQuality] Skip InlineConstructorDefaultToPropertyRector on non-final class (#8310) and on a property defined in the parent when parent::__construct() is called (#8297)
  • [CodeQuality] Skip SimpleXMLElement on IssetOnPropertyObjectToPropertyExistsRector (#8284)
  • [DeadCode] Skip RemoveParentDelegatingConstructorRector on protected parent constructor (#8309)
  • [DeadCode] Skip assert() enforcement that produces NeverType on NarrowWideUnionReturnTypeRector (#8282)
  • [Php71] Skip AssignArrayToStringRector on a variable re-assigned as string (#8293)
  • [Php81] Skip ArrayToFirstClassCallableRector when the arg type does not accept a Closure (#8288), drop the Symfony PHP closure check (#8291)

Set changes 📈

  • [Php84] Remove DeprecatedAnnotationToDeprecatedAttributeRector from the PHP 8.4 set and polyfills (#8326)
  • [Php83] Remove AddOverrideAttributeToOverriddenMethodsRector from the PHP 8.3 and polyfill sets (#8321)
  • [CodeQuality] Move 4 early-return rules to the code quality set (#8301)
  • [DeadCode] Move RemoveReadonlyPropertyVisibilityOnReadonlyClassRector (#8289), SimplifyBoolIdenticalTrueRector and UnwrapSprintfOneArgumentRector (#8285) to the dead-code set
  • [rector-symfony] Convert the last version sets to the composer-based set (#1021), drop per-version composer-triggered sets (#1010), remove unused version-based set constants and configs (#1019)
  • [rector-phpunit] Move every per-version rule into the composer-based set (#758), remove per-version set configs and constants (#760), register PropertyExistsWithoutAssertRector in the composer-based set (#761)
  • [rector-symfony] Add JMS attribute rules to the set, bond three attribute rules to package versions (#1029)

Deprecations 💀

Deprecated rules run without any effect, and print a warning 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. The goal is to keep Rector valuable and reliable for the every day user.

rector-src

  • DeprecatedAnnotationToDeprecatedAttributeRector and ConstAndTraitDeprecatedAttributeRector (#8347)
  • AddInterfaceByTraitRector (#8346)
  • RemoveAnnotationRector (#8345)
  • ScalarValueToConstFetchRector (#8344)
  • FuncCallToMethodCallRector (#8343)
  • AddReturnArrayDocblockBasedOnArrayMapRector (#8342)
  • AddAssertArrayFromClassMethodDocblockRector (#8341)
  • AddParamArrayDocblockBasedOnArrayMapRector (#8340)
  • AddReturnDocblockForDimFetchArrayFromAssignsRector (#8338)
  • AddSensitiveParameterAttributeRector (#8337)
  • PropertyHookRector — property hooks are a matter of preference (#8331)
  • JsonThrowOnErrorRector — can cause BC breaks (#8327)
  • CoalesceToTernaryRector — risky (#8324)
  • [EarlyReturn] ChangeNestedIfsToEarlyReturnRector (#8304), ChangeNestedForeachIfsToEarlyContinueRector (#8303), ReturnBinaryOrToEarlyReturnRector (#8302), ChangeOrIfContinueToMultiContinueRector (#8299)
  • [Strict] DisallowedEmptyRuleFixerRector (#8290)
  • [Php85] NestedFuncCallsToPipeOperatorRector and SequentialAssignmentsToPipeOperatorRector (#8286)
  • [CodeQuality] SwitchNegatedTernaryRector (#8283)
  • cacheClass() — the file-vs-memory cache storage choice moved into CacheFactory; only FileCacheStorage is ever useful to end users (#8311)
  • symfonyRoute and symfonyValidator args in withAttributesSets() (#8317)
  • ComposerTriggeredSet in favor of ComposerPackageConstraintInterface (#8296)
  • withComposerBased(netteUtils:) argument (#8329)

rector-symfony

  • ActionSuffixRemoverRector (#1022)
  • ControllerMethodInjectionToConstructorRector (#1020)
  • TraitGetByTypeToInjectRector (#1002)
  • RemoveDefaultGetBlockPrefixRector (#1017)
  • SwiftMailer to Symfony Mailer set (#1026)

rector-doctrine

  • RemoveEmptyTableAttributeRector (#505)
  • MoveCurrentDateTimeDefaultInEntityToConstructorRector, drop the force_nullable option (#504)

Removals 💀

  • Drop the nette/utils set and its single UtilsJsonStaticCallNamedArgRector rule (#8329) — the only third-party-library rule left in rector-src, readability only
  • Remove deprecated NewInInitializerRector (#8328)
  • [Sets] Remove the PHP and core set providers (#8320), the Symfony per-version providers (#8292), SymfonySetProvider, PHPUnitSetProvider (#8295) and DoctrineSetProvider (#8298) from the collector
  • [rector-symfony] Remove TwigSetProvider (#1015) and the empty Symfony per-version set providers (#1012)
  • [rector-phpunit] Remove deprecated PHPUnitSetProvider (#759)
  • [rector-doctrine] Remove DoctrineSetProvider (#501), drop the unused symfony/yaml dependency (#500)

rectorphp/rector-symfony 🎵

  • [Symfony 7.3] Merge AsTwigFilter/AsTwigFunction rules into a single rule, add getTests() support (#1027), restore the merged rules as deprecated (#1028)
  • [CodeQuality] ControllerMethodInjectionToConstructorRector: re-use the parent protected property (#1003), skip event and session params (#1005), use #[Required] autowire() when the parent has a constructor (#1006), skip type-guarded classes and use a unique autowire method name (#1007), re-use an existing #[Required] method (#1008)
  • [CodeQuality] LoadValidatorMetadataToAttributeRector: skip non-constant constraint args (#1000) and constraints without their own constructor (#1001)
  • [Sets] Fix AddParamTypeDeclaration to nullable types where the upstream param defaults to null (#1023)
  • [Symfony30] Skip methods without return in GetRequestRector (#1013), move it to the Symfony 2.5 set (#1009)
  • [Twig] Fix truncated Twig_Tests_EnvironmentTest_Extension rename (#1016)

rectorphp/rector-phpunit 🧪

  • [PHPUnit 6.0] AddDoesNotPerformAssertionToNonAssertingTestRector: add the attribute directly and skip traits (#765), remove addToAssertionCount() calls (#763), skip Twig IntegrationTestCase children (#762)

Internals and CI 🧰

  • [Testing] Check fixtures use the *.php.inc suffix, not bare *.inc (#8306)
  • [e2e] Trim low-value e2e tests, fold --only quote variants, revive the orphaned rules-summary test (#8334), remove the attributes e2e test (#8333)
  • [Scripts] Add list-non-composer-based-rules.php (#8276)
  • [ci] Bump actions/checkout to v5 for Node.js 24 (#8335), bump outdated actions to current majors (#8336), bump lock-threads, stale and typos actions (#8339)

Don't miss a new rector release

NewReleases is sending notifications on new releases.