Releases: rectorphp/rector
Released Rector 0.12 with PHPStan 1.0 and lighter Kernel
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
andDowngradePhp80ResourceReturnToObjectRector
(#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 inPropertyFetchFinder
(#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
, removeConsoleShowOutputFormatter
(#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.
Released Rector 0.11 with Scoped and PHP 7.1 version by Default
- See full diff: 0.10.0...0.11.0
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 🎉
- rectorphp/rector-src#22 Added support for glob patterns for files - thanks @sabbelasichon
- #5784 (merged as rectorphp/rector-src#12) Added e2e test with intuitive design - thanks @mpdude
- #6272 Add file formatting based on
.editorconfig
- thanks @sabbelasichon - #6360 Nette to Symfony migration is decoupled to own package - https://github.com/rectorphp/rector-nette-to-symfony
- rectorphp/rector-src@2fa60fc Add
dump_node()
function for easier Rector developing - #6283 Add
never
upgrade to PHP 8.1 - see https://wiki.php.net/rfc/noreturn_type [PHP 8.1] - #6328 Add
CallUserFuncToMethodCallRector
to removecall_user_func()
magic [CodingStyle] - #6318 Add
FuncGetArgsToVariadicParamRector
to removefunc_get_args()
magic [CodingStyle] - #6316 Add variadic method call unpack to
CallUserFuncCallToVariadicRector
[CodingStyle]
Bugfixes 🐛
Released Rector 0.10.16 fixing version and allowing older php-parser
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
- NEW PACKAGE Rector Installer for easier extension installing - #6129 - thanks @sabbelasichon
- NEW PACKAGE Rector PHPStan Rules for rule developers - https://github.com/rectorphp/rector-phpstan-rules
- [DeadCode] Added
RemoveUnusedPrivateMethodParameterRector
- #6168 - Refactored file processors to make use of
File
object (similar toScope
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
- Added
DowngradeStrictTypeDeclarationRector
#6107 - thanks @samsonasik - Added
DowngradeArrayKeyFirstLastRector
- #6137 - Added
DowngradeAnonymousClassRector
- #6122 - thanks @samsonasik - Added
DowngradeNullCoalesceRector
- #6208 - thanks @samsonasik
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 usingrector/rector-prefixed
- f801c76 - Fixed
AUTOLOAD_PATHS
andBOOTSTRAP_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
New Features 🎉
- #5974 Refactor doctrine/annotations to static reflection - annotation classes don't have to be autoloaded anymore
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:
- https://getrector.org/blog/from-doctrine-annotations-parser-to-static-reflection
- https://tomasvotruba.com/blog/how-to-traverse-phpdoc-and-modify-it/
Bugfixes 🐛
Released Rector 0.10 with Static Reflection and PHP 7.1 version
- See full diff: 0.9.0...0.10.0
Added Static Reflection 🚀🚀🚀
Do you have files with side effects or missing classes in autoload?
function hi()
{
echo 'hello';
}
hi();
Static reflection finally refactors code without running it.
- Contributed in #5665
- Read more about how was Legacy Refactoring made Easy with Static Reflection
Do you still need to include files with constants or custom autoloader? Use BOOTSTRAP_FILES
parameter:
$parameters->set(Option::BOOTSTRAP_FILES, [
__DIR__ . '/constants.php',
__DIR__ . '/project/special/autoload.php',
]);
Prefixed Rector with min PHP 7.1 🐘
Previous version required at least PHP 7.3 to run or Docker. Both were an obstacle to run Rector out of the box on every project.
We changed that. Now you can run Rector with older PHP and conflicting dependencies with ease:
php --version
# PHP 7.1
composer require symfony/console:^2.8
composer require rector/rector-prefixed:^0.10
- Contribted in #5880
Other Changes
- Inspired by PHPStan, you can run Rector without "process" command if you have configured paths in
rector.php
:
vendor/bin/rector
13/260 [▓░░░░░░░░░░░░░░░░░░░░░░░░░░░] 5%
-
Rules split into Project repositories: rector-symfony, rector-phpunit, rector-doctrine, rector-nette, rector-cakephp and rector-laravel
-
Rector testing simplified to single config-based - see #5837
-
Do you want to know more? Check the Release post
Upgrade Today
composer require rector/rector:^0.10
# or prefixed version
composer require rector/rector-prefixed:^0.10
Released Rector 0.9
- See full diff: 0.8.56...0.9.0
New Features 🎉
- PHP 8 upgrade set
- Downgrade sets
- Debuggable scoped Rector
Do you want to know more? Check the Release post
0.8.46
Summary release for last 2 weeks, since 0.8.28
- See full diff: 0.8.28...0.8.46
New Features 🎉
- [#4490] [EarlyReturn] Brand new set
- [#4517] [Doctrine] Add a Doctrine DBAL 2.11 set, Thanks @chrisguitarguy
- [#4526] [CakePHP] Started ruleset for CakePHP 4.2, Thanks @markstory
- [#4468] [CodeQuality] Added
NewStaticToNewSelfRector
- [#4442] [DoctrineCodeQuality] Added
ImproveDoctrineCollectionDocTypeInEntityRector
- [#4471] [Restoratoin] Added
InferParamFromClassMethodReturnRector
- [#4457] [CodeQualityString] Added
MoveOutMethodCallInsideIfConditionRector
, Thanks @samsonasik - [#4489] [Performance] Add
CountArrayToEmptyArrayComparisonRector
, Thanks @samsonasik - [#4515] [Nette] Add
RemoveParentAndNameFromComponentConstructorRector
Changes ⌚
AbstractFileSystemRector
was dropped and replaced byFileNode
, this was a crappy part of Rector, that split node-based refatoring and file-based; now the logic is simplified to essential code, and to workwith file, we can useFileNode
- [#4510] [TypeDeclaration] We switched types from string
"int"
fully to @phpstan typesnew IntegerType()
- [#4513] Composer v2 was released, so we put it right into our GitHub Actions CI and cut install time to 50 %
Removed 🧹
- [#4451] [DynamicTypedAnalysis] Very narrow package with lack of practise didn't get any feedback. As unfinished and better suitable for tombstoning, this part was dropped to keep Rector's focus on automated refactoring
- [#4521] [Decouple] This had only 1 rule, it was hard to configure and use - the set was dropped, better use PHPStorm for local refactoring
They Write about Rector
- @freekmurze made practical 4-min video about upgrading to PHP 8
0.8.28
This is first release note list, so we included changes from the last month.
- See full diff: v0.8.7...0.8.28
New Features 🎉
Do you want to run Rector only on changed files?
# rector.php
use Rector\Core\Configuration\Option;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::ENABLE_CACHE, true);
};
- [#4311] Add
init
command, so you can createrector.php
config
vendor/bin/rector init
# "rector.php" created
- [#4336] [Restoration] Add
RestoreFullyQualifiedNameRector
to restore accidentaly shortened class names
-public \SomeClass $someProperty;
+public \App\Full\SomeClass $someProperty;
- [#4341] [Symfony] Add
AutoWireWithClassNameSuffixForMethodWithRequiredAnnotationRector
for class method names with@require
annotation, Thanks @samsonasik
- [#4348] [PHP 8.0] Add @required annotation to #[Required] attribute from Symfony 5.2
- [#4350] [PHP 8.0] Add @route annotation to #[Route] attribute in Symfony 5.2
- [#4391] [SimplePhpDocParser] Decoupled first split package - https://github.com/rectorphp/simple-php-doc-parser, can be installed as
composer require rector/simple-php-doc-parser
class SomeClass
{
public function canDrive(Car $car)
{
- if ($car->hasWheels && $car->hasFuel) {
- return true;
+ if (!$car->hasWheels) {
+ return false;
}
- return false;
+ if (!$car->hasFuel) {
+ return false;
+ }
+
+ return true;
}
}