Skip to content

Releases: rectorphp/rector

Released Rector 0.12.7

10 Dec 00:44
Compare
Choose a tag to compare

New Features 🎉

  • [DeadCode] Add RemoveUnusedParamInRequiredAutowireRector (#1225), Thanks @mallardduck!
  • [PHP 8.2] Add rule for AllowDynamicProperties attribute (#1225), Thanks @mallardduck!
  • [CodeQuality] Add ReplaceMultipleBooleanNotRector (#1319), Thanks @villfa!
  • [Renaming] Handle rename template tag of class on RenameClassRector (#1318), Thanks @samsonasik!
  • [TypeDeclaration] Add AddPropertyTypeDeclaration rule (#1317)
  • [DeadCode] Add support remove unused in between private method parameter for RemoveUnusedPrivateMethodParameterRector (#1321), Thanks @samsonasik!
  • [DeadCode] Add RemoveDeadContinueRector (#1323), Thanks @villfa!
  • [Renaming] Add generic rename annotation to RenameAnnotationRector (#1341)
  • [DX] make all configure() methods accept direct value object configuration (#1322)
  • [DX] Make use of configure() method (#1344)
  • [DX] Re-use configure() in docs + remove prefixing of ValueObjectInliner (#1410)
  • Array merge to unpacking (#1345), Thanks @Bl00D4NGEL!
  • [Php80] Add AddParamBasedOnParentClassMethodRector (#1431), Thanks @samsonasik!
  • Add SimpleStaticType for return type completion (#1441)
  • [Downgrade PHP 5.5] Add DowngradeBoolvalRector (#1292), Thanks @villfa!
  • [Downgrade PHP 7.0] Add DowngradeClosureCallRector (#1304), Thanks @villfa!
  • [DowngradePhp74] Add DowngradeReflectionGetTypeRector (#1407)
  • [DowngradePhp80] Add getAttributes() reflection downgrade (#1406)
  • [Downgrade PHP 80] Add DowngradeArbitraryExpressionsSupportRector (#1347), Thanks @villfa!
  • [DowngradePhp81] Add DowngradeArraySpreadStringKeyRector (#1369), Thanks @samsonasik!

Bugfixes 🐛

  • [Transform] Fix keep args on StaticCallToNewRector (#1326), Thanks @samsonasik!
  • do not show --debug output on json error formatter (#1343)
  • [Downgrade PHP 5.6] Fix DowngradeUseFunctionRector (#1348), Thanks @villfa!
  • [Php81] Skip has default value on ReadOnlyPropertyRector (#1355), Thanks @samsonasik!
  • [Php81] Skip no type property on ReadOnlyPropertyRector (#1354), Thanks @samsonasik!
  • [Php81] Skip no type param on ReadOnlyPropertyRector (#1365), Thanks @samsonasik!
  • [Php81] Skip non private modifier on ReadOnlyPropertyRector (#1364), Thanks @samsonasik!
  • strip empty starting/ending php tags (#1329), Thanks @staabm!

Removed 💀

  • [Core] Remove deprecated AbstractRector getObjectType method (#1295), Thanks @samsonasik!
  • [DX] Explicitly inject visibility manipulator service instead of parent constructor (#1298)
  • [League] Remove only League upgrade set from core, give space for community package with whole vendor (#1305)
  • [CodingStyle] Remove PreslashSimpleFunctionRector, let php-cs-fixer doing good work handle that (#1310)
  • [DeadCode] Remove RemoveAssignOfVoidReturnFunctionRector as unreliable, let PHPStan report and use handle various cases (#1313)
  • [Transform] Remove unused ClassConstFetchToValueRector (#1332)
  • [CodingStyle] Remove custom code rule ManualJsonStringToJsonEncodeArrayRector, not much generic (#1398)
  • [Cleanup] merge duplicated SplitStringClassConstantToClassConstFetchRector to UseClassKeywordForClassNameResolutionRector (#1401)
  • [Carbon] Remove fraction of few rules from history (#1408)

Bump to PHP 8.1 📈

New Symfony 6 Set 🥳

  • [Symfony 6] Extend return type set (#88
  • [Symfony] Add FrameworkExtraBundle with attributes set (#85)
  • [Symfony] Extend Symfony 5.3, 5.4 and 6.0 sets (#89)

Released Rector 0.12.5

23 Nov 17:43
Compare
Choose a tag to compare

New Features 🎉

  • [PHP 8.1] Add nested attributes support - part #1 (#1266)
  • [PHP 8.1] Add nested attributes arguments + keep short ORM* like aliases (#1278)
  • [PHP 8.1] Apply constructor promotion on NewInInitializerRector (#1288), Thanks @samsonasik!
  • [DX] Add configure() method to service configuration to make configuration easy again (#1276)
  • [DX] Use main configure() option directly (#1285)
  • [PHP 8.0] Extend DoctrineAnnotationClassToAttributeRector rule to cover short target annotations (#1260)
  • [Downgrade PHP 8.1] Add DowngradePureIntersectionTypeRector (#1281), Thanks @villfa!
  • [Downgrade PHP 8.1] Add DowngradeNewInInitializerRector (#1275), Thanks @villfa!
  • [Downgrade PHP 8.1] Add DowngradeFirstClassCallableSyntaxRector (#1267), Thanks @villfa!
  • [Downgrade PHP 8.1] Add DowngradeReadonlyPropertyRector (#1262), Thanks @villfa!
  • [Downgrade PHP 8.1] Add DowngradeNeverTypeDeclarationRector (#1259), Thanks @villfa!
  • [Downgrade PHP 5.4] Add DowngradeIndirectCallByArrayRector (#1247), Thanks @villfa!
  • [Downgrade PHP 5.5] Add DowngradeArbitraryExpressionArgsToEmptyAndIssetRector (#1250), Thanks @villfa!
  • [Downgrade PHP 5.5] Add DowngradeForeachListRector (#1256), Thanks @villfa!
  • [Php80] Handle schema on Table with UniqueConstraint on AnnotationToAttributeRector (#1252), Thanks @samsonasik!
  • [Compatibility] Add AttributeCompatibleAnnotationRector (#1263)
  • [Downgrade PHP 5.6] Add DowngradeUseFunctionRector (#1290), Thanks @villfa!

Bugfixes 🐛

  • Fix $this/self docblock compare removed on on-final class, as it can refer to child this type (#1246)
  • [Renaming] Handle var static docblock in union on RenameClassRector (#1248), Thanks @samsonasik!
  • Fix DowngradeArbitraryExpressionArgsToEmptyAndIssetRector (#1251), Thanks @villfa!
  • [EarlyReturn][Php73] Handle JsonThrowOnErrorRector + ChangeAndIfToEarlyReturnRector (#1272), Thanks @samsonasik!
  • [DeadCode][EarlyReturn] Handle RemoveUnusedVariableAssignRector + RemoveAlwaysElseRector (#1277), Thanks @samsonasik!
  • [Privatization] Skip with encapsed string part on ChangeReadOnlyVariableWithDefaultValueToConstantRector (#1287), Thanks @samsonasik!

Released Rector 0.12.4

15 Nov 14:15
Compare
Choose a tag to compare

New Features 🎉

  • [Downgrade PHP 7.0] Add DowngradeDirnameLevelsRector (#1209), Thanks @villfa!
  • [Downgrade PHP 5.4] Add DowngradeCallableTypeDeclarationRector (#1213), Thanks @villfa!
  • include doctrine odm classes to the exclude list (#1211), Thanks @bitgandtter!
  • [TypeDeclaration] Improve typed property (#1221)
  • [CodeQuality] Add DoWhileBreakFalseToIfElseRector (#1220)
  • [CodeQuality] Add do whlie rule to set (#1223)
  • [Downgrade PHP 5.6] Add DowngradeArgumentUnpackingRector (#1219), Thanks @villfa!
  • [PHP 8.1] Add NewInInitializerRector (#1224)
  • [Downgrade PHP 5.4] Add DowngradeInstanceMethodCallRector (#1225), Thanks @mallardduck!
  • [Naming] Add StaticPropertyFetch support on RenameForeachValueVariableToMatchExprVariableRector (#1232) (#1232), Thanks @samsonasik!
  • [PostRector][CodingStyle] Improve Auto import performance (#1233) (#1233), Thanks @samsonasik!
  • Add BOOTSTRAP_FILES hint to AutoloadExceptionMessage (#1236) (#1225), Thanks @mallardduck!
  • [PHP 8.1] Add IntersectionTypesRector (#1227) (#1227)

Bugfixes 🐛

  • [Php71] Skip property with array doc filled by __construct on CountOnNullRector (#1208), Thanks @samsonasik!
  • [NodeTypeResolver] Avoid error Uncaught TypeError: PHPStan\Type\Constant\ConstantIntegerType::__construct(): Argument #1 ($value) must be of type int, string given (#1210), Thanks @samsonasik!
  • [DeadCode] Do not remove parameter on RemoveUnusedPrivatePropertyRector on constructor only usage in the middle of parameter (#1212), Thanks @samsonasik!
  • [DeadCode] Skip RemoveUnusedPrivatePropertyRector on used in Assign expr (#1214), Thanks @samsonasik!
  • [TypeDeclaration] Skip conditional Throw_ on ReturnNeverTypeRector (#1217), Thanks @samsonasik!
  • [DeadCode] Skip clone and new self on RemoveUnusedPrivatePropertyRector (#1215), Thanks @samsonasik!
  • [DeadCode][TypeDeclaration] Handle Nullable Param on RemoveUnusedPrivateMethodParameterRector+RemoveUnreachableStatementRector+AddArrayParamDocTypeRector (#1216), Thanks @samsonasik!
  • fix: ignore specified words while making it singularized (#1222), Thanks @ishanvyas22!
  • [Php71] Skip with If always array on CountOnNullRector (#1229) (#1229), Thanks @samsonasik!
  • [Php80] Fix InverseJoinColumn Annotation to Attribute on AnnotationToAttributeRector (#1231) (#1231), Thanks @samsonasik!
  • [TypeDeclaration] Avoid error Rector\Core\Rector\AbstractRector::isObjectType() must implement interface PhpParser\Node, null given on AddParamTypeDeclarationRector (#1239) (#1239), Thanks @samsonasik!
  • [Php56] Skip AddDefaultValueForUndefinedVariableRector as coalesce left (#1238) (#1238), Thanks @samsonasik!
  • [Renaming] Handle error on RenameClassRector when method return static (#1243) (#1243), Thanks @samsonasik!
  • [Php74] Handle nested closure on ClosureToArrowFunctionRector (#1245) (#1245), Thanks @samsonasik!

Removed 💀

  • [NodeTypeResolver] Remove deprecated NodeTypeResolver getStaticType method (#1230) (#1230), Thanks @samsonasik!

Released Rector 0.12.3

11 Nov 10:21
Compare
Choose a tag to compare

New Features 🎉

  • [Downgrade PHP 5.4] Add DowngradeBinaryNotationRector (#1202), Thanks @villfa!

Bugfixes 🐛

  • [Scoped] Fix missing trigger_deprecatoin() in explicit preload (#1207)
  • [Scoped] Include scoped-autoload for tests too (#1207), #6798
  • [PHP 7.4] Fix AddLiteralSeparatorToNumberRector for null token (#1206)

Released Rector 0.12.2

10 Nov 18:54
Compare
Choose a tag to compare

Bugfixes 🐛

  • [TypeDeclaration] Skip Conditional on ReturnNeverTypeRector (#1200) (#1201), Thanks @zingimmick!
  • Add min PHP version for TypedPropertyFromStrictGetterMethodReturnTypeRector (#1201), Thanks @zingimmick!

New Features 🎉

  • [Downgrade PHP 5.5] Add DowngradeClassConstantToStringRector (#1194), Thanks @villfa!
  • [Downgrade PHP 5.4] Add ShortArrayToLongArrayRector (#1198), Thanks @villfa!

Released Rector 0.12.1

09 Nov 16:39
Compare
Choose a tag to compare

Bugfixes 🐛

  • [Php70] Avoid error Undefined property: PhpParser\Node\Stmt\Class_::$namespacedName on ThisCallOnStaticMethodToStaticCallRector (#1197), Thanks @samsonasik!

Released Rector 0.12 with PHPStan 1.0 and lighter Kernel

09 Nov 12:11
Compare
Choose a tag to compare

I'm proud to share the biggest Rector release yet built on work of dozen contributors!

Main focus of this release is on type-completing rules, PHP 7-8 upgrade rules, moving from node attributes to parent node relations and upgrade to PHPStan 1.0.

New Features 🎉

  • Upgrade to Symplify not using symfony/http-kernel (#1119) - Rector is now 10 Symfony packages lighter on every download
  • [Php80] Add Php8ResourceReturnToObjectRector (#1068), Thanks @samsonasik!
  • [Php81] Add Php81ResourceReturnToObjectRector (#1114), Thanks @samsonasik!
  • Extract ObjectReference enum for "self", "static" and "parent" keywords (#1056)
  • [TypeDeclaration] Add TypedPropertyFromStrictGetterMethodReturnTypeRector (#1048)
  • [DowngradePhp54] Add DowngradeStaticClosureRector (#1038), Thanks @Lctrs!
  • [DowngradePhp56] Add DowngradeExponentialOperatorRector (#1181), Thanks @villfa!
  • [DowngradePhp56] Add DowngradeExponentialAssignmentOperatorRector (#1142), Thanks @fezfez!
  • [DowngradePhp74] handle static arrow functions to static closures (#1036), Thanks @Lctrs!
  • [DowngradePhp74] Add DowngradePreviouslyImplementedInterfaceRector (#1159), Thanks @samsonasik!
  • [DowngradePhp74] Handle nested uses on ArrowFunctionToAnonymousFunctionRector (#1040), Thanks @samsonasik!
  • [DowngradePhp81][DowngradePhp80] Add DowngradePhp81ResourceReturnToObjectRector and DowngradePhp80ResourceReturnToObjectRector (#1190), Thanks @samsonasik!
  • [DowngradePhp80/81] Refactor Downgrade Resource Return to Object to use BooleanOr check (#1193), Thanks @samsonasik!
  • Add mask support for skip to StringClassNameToClassConstantRector (#1102)
 use \Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;

 $services->set(StringClassNameToClassConstantRector::class);
    ->call('configure', [[
        StringClassNameToClassConstantRector::CLASSES_TO_SKIP => [
-    		'Nette\Utils\String',
-    		'Nette\Neon\Neon',
-    		'Nette\Application\UI\Presenter',
+    		'Nette\*'
		],
    ]]);

Bugfixes 🐛

  • Fix inverseJoinColumns Doctrine annotation class mapping (#1142), Thanks @fezfez!
  • Fix type without class name mapping without substracted type (#1104)
  • [DeadCode] Skip Route annotation on RemoveDelegatingParentCallRector (#1138), Thanks @samsonasik!
  • [TypeDeclaration] Skip nullable self referencing param and return on AddArrayParamDocTypeRector and ReturnTypeDeclarationRector (#1183), Thanks @samsonasik!
  • [TypeDeclaratoin] Skip variadic param (rectorphp/rector-src@04354c2)
  • Skip union if parent type in ClassMethodParamTypeCompleter (#1103)
  • [DeadCode] Skip dynamic fetch method call on RemoveUnusedPrivateMethodRector (#1128), Thanks @samsonasik!
  • [Renaming] Handle rename property too when parent property renamed (#1031), #6758, Thanks @samsonasik!
  • [Php56] Skip AddDefaultValueForUndefinedVariableRector on has isset check (#1028), #6760, Thanks @samsonasik!
  • Check for ClassLike instance in PropertyFetchFinder (#1033), Thanks @canvural!
  • [AnonymousFunctionFactory] Do not pass variables defined in foreach or parameters list to closure uses (#1038), Thanks @Lctrs!
  • [Php71] Skip typed array property on CountOnNullRector (#1049), Thanks @samsonasik!
  • [Php73] Skip JsonThrowOnErrorRector on passed exact value (#1051), Thanks @samsonasik!
  • [Php80] Skip union callable on ClassPropertyAssignToConstructorPromotionRector (#1101), Thanks @samsonasik!
  • [CodeQuality] Skip Variable may be immutable via New_ or Clone_ on SimplifyUselessVariableRector (#1060), Thanks @samsonasik!
  • [DowngradePhp74] fix uses for nested arrow functions with same param names (#1090), Thanks @Lctrs!
  • [DeadCode] Handle bool var if cond return true next return bool var on RemoveDuplicatedIfReturnRector (#1136), Thanks @samsonasik!
  • fix intersection type with single type (#1086)
  • [TypeDeclaration] Skip ternary on ParamTypeByMethodCallTypeRector (#1131), Thanks @zingimmick!

PHPStan 1.0 Upgrade ⛺️

This Rector version depends on PHPStan more then ever. We're using its php-parser (many of them actually), class name visitor resolver and static/this/self types. That's why we had to take time to make sure the upgrade to PHPStan 1.0 is stable.

  • [PHPStan 1.0] upgrade deprecated getNativeMethods() method (#1069)
  • Improve self/static/parent object reference (#1071)
  • [PHPStan 1.0] Make SelfType, StaticType and ThisType use ClassReflection over string (#1072)
  • SelfType and StaticType are now handled in ObjectTypeSpecifier (#1077)
  • [PHPStan 1.0] Use processNodes() over processNodeStmts() (#1111)
  • [PHPStan 1.0] use selectFromArgs() for function reflectoin to get passed by reference positoins (#1113)
  • [PHPStan 1.0] Remove sorted union types, now handled by default (#1112)
  • [PHPStan 1.0] resolve FunctionReflection getFileName() from main interface (#1117)
  • [PHPStan 1.0] Remove ReflectionWithFilename (#1118)
  • Fix issue of parsing PHP 8 sources on PHP 7.x (#1184), Thanks @ondrejmirtes!
  • [PHPStan 1.0] Remove node naming visitors and re-use PHPStan ones (#1144)
  • PHPStan\Reflection\ClassReflection::getFileName() now returns null|string (rectorphp/rector-src@9686861)
  • PHPStan\Reflection\ClassReflection::getParentClass now returns null|class reflection (rectorphp/rector-src@1cc7dc3)
  • NativeFunctionReflection has new parameter (rectorphp/rector-src@ca82769)
  • Remove ClearReturnNewByReferenceRector, PHPStan cannot handle it (rectorphp/rector-src@051c751)

PHPStan 1.0-Related Changes

Class names are now available in the node itself:

-$className = $node->getAttribute(AttributeKey::CLASS_NAME);

↓

 // in case of class like
+$className = $classLike->namespacedName

 // in case of anonymous class
+$className = $classLike->name

 // or widely used method in AbstractRector
 $className = $this->getName($classLike)

Deprecated/Removed ⚰️

  • [CodingStyle] Deprecate RemoveUnusedAliasRector, job rather for coding standard tool and opinonated (#1157)
  • Remove FileNodeVisitor, available in AbstractRector (#1145)
  • [CodeQuality] Remove FixClassCaseSensitivityNameRector, conflicting with name node removal and edge case already handled by PHPStan reports (#1160)
  • remove deprecated AttributeKey::FILE_INFO const attribute (rectorphp/rector-src@8f7fea0)
  • Remove dead classes (#1133)
  • Remove dead classes #2, remove unused PlatformAgnosticAssertions, remove ConsoleShowOutputFormatter (#1134)
  • [Defluent] Remove often-breaking set (#1062)

Attribute Keys Changes 📈

This is not about PHP 8.0 attributes, but about helper php-parser attributes that allow to store mixed data in any node.

  • Move from CLASS_NODE attribute to more reliable parent node finder (#1162)
  • Move from CLASS_METHOD node attribute to parent finder (#1167)
  • De...
Read more

Released Rector 0.11 with Scoped and PHP 7.1 version by Default

13 May 17:00
Compare
Choose a tag to compare

United Release of Prefixed & Downgraded Version 🚀🚀🚀

For a long time, Rector published 2 releases. It was often confusing which to use when and how they differ. Last couple of month we tried to make them as similar as possible to make transition as smooth as possible.

Since 0.11 we're moving from 2 repositories rectorphp/rector and rectorphp/rector-prefixed to just one rectorphp/rector.
This repository is downgraded to PHP 7.1 and scoped.

Read more in Prefixed Rector by Default.

How to Upgrade?

composer remove rector/rector-prefixed
composer require rector/rector --dev

or

composer update rector/rector:^0.11 --dev

New Features 🎉


Bugfixes 🐛

  • #6390 Fix downgrade scalar types casting in PHP 7.0
  • #6384, #6385, #6386 Fix anonymous class downgrade in PHP 7.0
  • #6378 Fix generic type on in Typed property for PHP 7.4 - thanks @samsonasik

Released Rector 0.10.16 fixing version and allowing older php-parser

30 Apr 09:03
e615756
Compare
Choose a tag to compare

New Features 🎉

  • Added @changelog annotation above rule to explain why the rule does what it does in the output #6073 - thanks @sabbelasichon

Just add it to your Rector rule:

/**
 * @changelog https://wiki.php.net/rfc/typed_properties_v2#proposal
 */
final class TypedPropertyRector extends AbstractRector
{
}

Run Rector:

vendor/bin/rector ...

And if this rule changed the code, it will show the link too:

Applied Rectors:

* TypedPropertyRector - https://wiki.php.net/rfc/typed_properties_v2#proposal


  • [DeadCode] Added RemoveUnusedPrivateMethodParameterRector - #6168
  • Refactored file processors to make use of File object (similar to Scope concept from PHPStan) #6085
  • Added dump_node() helper function to see what node you have #6229 - thanks @ullique for inspiration
dump_node($string);
// change 2nd to increase depth
dump_node($string, 3);

New Downgrade Rules


Bugfixes 🐛

  • Fixed invalid doc block tag crashing #6068
  • Fixed parent, self, static prefixing on class name change #6159
  • Fixed use of AbstractRectorTestCase in tests while using rector/rector-prefixed - f801c76
  • Fixed AUTOLOAD_PATHS and BOOTSTRAP_FILES parameters in tests - #6239
  • Fixed displayed Rector version in rector/rector-prefixed 26d6fff
  • Fixed code conflicts with different php-parser version in rector/rector-prefixed - f15648e, thanks @phpstan for inspiration

Released Rector 0.10.4 with Static Annotation Parser

09 Apr 16:34
Compare
Choose a tag to compare

New Features 🎉

use Symfony\Component\Routing\Annotation\Route;

final class SomeController
{
    /**
     * @Route(path="/some_path", name="some_name")
     */
    public function some()
    {
    }
}
  • #6045 make use of PHPDocNodeTraverser to work with docblock changes

Read more about these features:


Bugfixes 🐛

  • #6057 Restore parent node connection on new node
  • #6064 Fix Php4ConstructorRector with non-stmts content
  • #5967 Fix printing files with fatal errorsage rector deps