github rectorphp/rector 0.17.0
Released Rector 0.17

latest releases: 1.1.0, 1.0.5, 1.0.4...
12 months ago

Preparing for Rector 1.0

In this release, we focus on architecture improvements before reaching Rector 1.0. We want to lower the memory usage and make Rector run faster.

This include removing next/previous nodes - this will most likely not affect you, as Rector rules were upgraded, but if you do you use them, switch to StmtsAwareInterface instead

We follow PHPStan 1.6 move from April 2022, where you can learn more: https://phpstan.org/blog/preprocessing-ast-for-custom-rules

  • Replace NodeConnectingVisitor with ParentConnectingVisitor (#3900)

To see how to refactor to StmtsAwareInterface, check these PRs:

  • Remove NEXT_NODE dependency in ChangeAndIfToEarlyReturnRector, narrow to only closed scope function likes (#3913)
  • Remove NEXT_NODE from SimplifyIfReturnBoolRector (#3915)
  • [DeadCode] Remove next attribute on RemoveUnusedVariableAssignRector ([#3917](https://github.com/rectorphp/
  • [CodingStyle] Refactor CatchExceptionNameMatchingTypeRector to use StmtsAwareInterface (#3788)

Add/remove nodes directly 👍

The next improvement focuses on explicit node adding/removal. Thanks to StmtsAwareInterface we can add nodes directly. This makes Rector refactor() method contain all the code you need.

  • Cleanup usage of NodesToAddCollector, return nodes directly instead (#4003)
  • Cleanup removeNodeFromStatements(), removeArg(), removeParam(), removeStmt() methods and remove nodes directly (#4012)
  • Remove unused addNodeAfterNode(), return nodes instead (#4023)
  • Remove unused method addNodesBeforeNode() (#4024)

New Features 🥳

  • [PHP 7.0] Add IfIssetToCoalescingRector (#3878)
  • Support attributes in RemoveFinalFromEntityRector (#3727), Thanks @alexndlm!
  • Add SwapMethodCallArgumentsRector (#3726), Thanks @gaydamakha!
  • [CodeQuality] Add CleanupUnneededNullsafeOperatorRector (#3767)
  • Make ReturnNeverTypeRector work with type declaration, add it to PHP 8.1 set (#3852)
  • [TypeDeclaration] Add BoolReturnTypeFromStrictScalarReturnsRector (#3898)
  • Make ChangeGlobalVariablesToPropertiesRector add properties directly, remove Nette inject methods (#3957)
  • Utilize MinPhpVersionInterface in more rules (#3752), Thanks @staabm!
  • Dump dependency container and re-use it - 35% faster test-suite (#3809), Thanks @staabm!
  • Defer type-resolving in RemoveJustPropertyFetchRector (#3761), Thanks @staabm!

Bugfixes 🐛

  • [TypeDeclaration] Skip Arg unpack on AddMethodCallBasedStrictParamTypeRector (#3787)
  • [CodeQuality] Add typed property support to IssetOnPropertyObjectToPropertyExistsRector (#3876)
  • [CodeQuality] Skip non-array type on SimplifyForeachToArrayFilterRector (#3738)
  • Fix ShortenedObjectType not resolving to correct class reflection (#3397), Thanks @jackbentley!
  • Extend code-quality set (#3773)
  • Don't neon-decode phpstan configs over and over again (#3796), Thanks @staabm!
  • [Console] Allow https url instead of git:// on SetupCICommand (#3799)
  • Fix integer range phpdoc types being treated as useless (#3825), Thanks @jlherren!
  • Fix nullable param in ClassPropertyAssignToConstructorPromotionRector (#3842)
  • Fix PrivatesAccessor: use selectFromArgs() instead (#3923), Thanks @staabm!

Removed rules 💀

We've also remove bunch of rules, that were added in early days of Rector for demo purposes. They were not used as of any set for non-reliable cases. PHPStan and coding standards replace some of those.

  • [CodeQuality] Remove ForToForeachRector, as overly deatiled and not reliable (#3747)
  • [CodeQuality] Remove SimplifyIfExactValueReturnValueRector, as overly defensive + InlineSimplePropertyAnnotationRector as purely coding standard area (#3764)
  • [CodingStyle] Remove RemoveDoubleUnderscoreInMethodNameRector, as naming is not handled for breaking reasons (#3765)
  • Remove RemoveUnusedVariableAssignRector, as could be breaking code in order of excution and hard to do reliable (#3793)
  • [CodingStyle] Remove ConsistentPregDelimiterRector as not much practical, importance of regex is a testing it matches expectationg, area of static analysis (#3797)
  • Remove ToStringToMethodCallRector as not practical and only for demo, FalseReturnClassMethodToNullableRector, as requires detailed custom refactoring (#3854)
  • Remove ChangeOrIfReturnToEarlyReturnRector as makes code harder to read by duplication, rather use PHSPtan and extract method (#3916)
  • [DeadCode] Remove RemoveDuplicatedIfReturnRector as can lead to unexpeced consequences, better use static analysis and contextual handling (#3926)
  • [DeadCode] Remove RemoveDuplicatedInstanceOfRector as hardly practical (#3936)
  • [CodeQuality] Remove ExplicitMethodCallOverMagicGetSetRector designed for nette smart object migration only, not useful for general projects (#3948)
  • Remove GetAndSetToMethodCallRector, as not practical and used for single legacy job (#3953)
  • Remove ChangeReadOnlyVariableWithDefaultValueToConstantRector overly complex and risky, better job for PHPStan (#3954)
  • Remove IsObjectOnIncompleteClassRector as blindly turns all incomplete checks to negated, better examine manually (#3969)
  • Remove ReservedObjectRector as requires explicit configuration and is handled by RenameClassRector already (#3975)
  • Remove ChangeReadOnlyPropertyWithDefaultValueToConstantRector as overly detailed checks, better use PHPStan and refactor individually (#4028)
  • Remove NewToMethodCallRector as unused core and no other extension, niche to use, better handle by PHPStorm (#4029)
  • [CodingStyle] Remove AddFalseDefaultToBoolPropertyRector, as works with unrelaible docblocks (#3856)
  • Remove UpdateFileNameByClassNameFileSystemRector niche rule that was added just for example sake (#3849)
  • [Transform] Remove ArgumentFuncCallToMethodCallRector as never used (#3774)
  • [Transform] Remove DimFetchAssignToMethodCallRector as unused (#3775)
  • [Transform] Remove FileGetContentsAndJsonDecodeToStaticCallRector as only for demo purposes (#3776)
  • [Transform] Remove MethodCallToAnotherMethodCallWithArgumentsRector as unused (#3777)
  • [CodeQuality] Remove SimplifyUselessLastVariableAssignRector as overly complex and should be handled individually (#3784)
  • Remove AddPregQuoteDelimiterRector as very narrow area and has not context awareness, better handle manually (#3927)
  • Remove TokenGetAllToObjectRector, as rare to use and leaky to handle, better handle in controller manual way (#4001)
  • Remove ChangeReflectionTypeToStringToGetNameRector as niche and overly detailed, better refactor reflectio na as a whole (#3976)
  • Remove RenameNamespaceRector, better handle by IDE or explicit RenameClassRector (#3979)
  • [CodeQuality] Deprecate NarrowUnionTypeDocRector as focused on docblocks, and moving to type declarations (#3848)
  • Remove MakeTypedPropertyNullableIfCheckedRector as old fix of TypedPropertyRector rule, removed months ago (#3851)
  • [PHP 8.0] Deprecate old UnionTypesRector that is dangerously moving docblocks, use type declaration rules instead (#3846)
  • [CodingStyle] Remove OrderAttributesRector, as rather coding standard and does not have specific PSR example (#3838)
  • Remove unused PregMatchTypeCorrector, the 3rd param in preg_match_* is now handled natively by PHPStan (#3824)
  • [Restoration] Remove RemoveFinalFromEntityRector as used only to revert very old Rector bug (#3847)

Don't miss a new rector release

NewReleases is sending notifications on new releases.