Skip to content

Released Rector 2.9.3

Latest

Choose a tag to compare

@samsonasik samsonasik released this 04 Dec 16:51

Safer rules and smarter caching 🛡️

This release continues our effort towards safer and more reliable automated refactoring. More than 30 rules and internal analyzers now rely on native types where PHPDoc types alone cannot guarantee that a change preserves runtime behavior.

Caching also gets smarter: changes to parent classes, interfaces and traits now invalidate cached files that depend on them.

On top of that, we introduce a new dump-config command, Pest support, and switch to a new console framework.


New Features 🥳

  • [DX] Add dump-config command to print the resolved Rector configuration as JSON (#9071)
vendor/bin/rector dump-config
  • [DX] Support --config in dump-config, list-rules and validate-config commands (#9103)

  • [Php55] Extend StringClassNameToClassConstantRector to handle class method references, concatenated class method prefixes and references to the current class (#9066, #9068, #9069, #9070)

- $callback = 'App\Service\SomeService::run';
+ $callback = \App\Service\SomeService::class . '::run';
  • [Renaming] Support case-insensitive class and constant name matching in RenameClassRector and RenameConstantRector (#9111, #9112)

  • [Set] Add Pest support to composer-based sets (#9119, #9120)

return RectorConfig::configure()
    ->withComposerBased(pest: true);

Smarter Caching ⚡

  • Invalidate cached files when their parent class, interface or trait changes (#9090)
  • Track traits used by parent classes and nested traits as file dependencies (#9092)
  • Clear the cache before constructing rules when running with --clear-cache, so cache entries created during rule initialization are preserved (#9085)

Native types over PHPDoc assumptions 🛡️

PHPDoc types are valuable for static analysis, but they do not necessarily reflect the actual runtime types.

More than 30 rules and internal analyzers have been hardened to use native types where relying on PHPDoc types could introduce unexpected behavior.

This affects rules across CodeQuality, CodingStyle, DeadCode, TypeDeclaration and PHP upgrade sets.

Among others:

  • Keep necessary boolean casts in UnnecessaryTernaryExpressionRector (#9134)
  • Avoid removing instanceof assertions based solely on PHPDoc types in RemoveDeadInstanceOfAssertRector (#9124)
  • Keep conditions in RemoveAlwaysTrueIfConditionRector when their types are only guaranteed by PHPDoc (#9125)
  • Avoid removing potentially reachable loops in RemoveDeadLoopRector (#9139)
  • Avoid declaring return types based on PHPDoc-only array shapes in AddArrowFunctionReturnTypeRector (#9167)
  • Keep unused private method parameters when PHPDoc-only typed callers prevent safe removal (#9160, #9165)

The goal stays the same: prefer keeping code unchanged over making a potentially unsafe change.


Bugfixes 🐛

Core

  • Fix missing scope for unreachable statements after labels (#8971)
  • Fill scope on trait-level attribute arguments (#9091)
  • Keep necessary skips when two skipped rules would perform the same change (#9072)
  • Preserve tab indentation of reprinted nodes (#9087)
  • Preserve heredoc content indentation in BetterStandardPrinter (#9102)
  • Fix indentation of multiline method call arguments printed on a new line (#9117)

CodeQuality

  • Handle constant definitions in InlineIfToExplicitIfRector (#9078)
  • Skip floats in SimplifyTautologyTernaryRector (#9084)
  • Use || when converting negated multi-argument isset() in IssetOnPropertyObjectToPropertyExistsRector (#9098)

DeadCode

  • Preserve parentheses around cast expressions in RecastingRemovalRector (#9094)

CodingStyle and TypeDeclaration

  • [CodingStyle] Simplify shadowed function detection in FunctionFirstClassCallableRector (#9067)
  • [CodingStyle] Skip consecutive static assignments of the same class in NewlineBeforeNewAssignSetRector (#9118)
  • [TypeDeclaration] Skip non-array, possibly object and template types in AddArrowFunctionParamArrayWhereDimFetchRector (#9073, #9074)

PHP sets

  • [Php85] Skip increment, decrement, by-reference usage and other write contexts in ArrayFirstLastRector (#9079, #9080, #9081)
  • [Php83] Skip get_parent_class() in classes without a parent in RemoveGetClassGetParentClassNoArgsRector (#9101)
  • [Php81] Skip vendor MyCLabs enum method calls in MyCLabsMethodCallToEnumConstRector (#9086, #9088)
  • [Php80] Preserve loose comparison behavior in ChangeSwitchToMatchRector (#9065)
  • [Php74] Skip closures in constant expressions in ClosureToArrowFunctionRector (#9097)
  • [Php71] Limit BinaryOpBetweenNumberAndStringRector to arithmetic and bitwise operators (#9114)
  • Preserve surrounding string content when converting backreferences in PregReplaceEModifierRector (#9100)
  • Preserve the original create_function() scope in CreateFunctionToAnonymousFunctionRector (#9099)

Developer Experience ✨

  • Improve the deprecation message for per-version PHP sets registered through withSets() (#9089)
  • Include treatClassesAsFinal() and withSymfonyContainerXml() configuration in dump-config output (#9109, #9115)
  • Extend composer-based package detection for Symfony and Doctrine packages (#9093, #9110, #9113)

Removed 💀

  • Remove deprecated --rules-summary option (#9095)
  • Remove internal SetList::PHP_POLYFILLS constant (#9064)

Internals ⚙️

  • Replace symfony/console with the entropy/entropy console framework (#8787)
  • Bump PHP-Parser to 5.10 (#9082)
  • Bump PHPStan to 2.4 (#9166)
  • Bump PHPDoc Parser to 2.6 (#9168)
  • Use CallLike::getArg() for named and positional argument resolution across rules (#9075)
  • Restore static configuration parameters after ConfigDumperTest to prevent test isolation issues (#9077)

Full Changelog: 2.9.2...2.9.3