Instant Upgrades and Instant Refactoring of any PHP 5.3+ code

Overview

Rector - Speedup Your PHP Development

Downloads


Rector helps you with 2 areas - major code changes and in daily work.

  • Do you have a legacy code base? Do you want to have that latest version of PHP or your favorite framework? → Rector gets you there with instant upgrade.

  • Do you have code quality you need, but struggle to keep it with new developers in your team? Do you wish to have code-reviews for each member of your team, but don't have time for it? → Add Rector to you CI and let it fix your code for you. Get instant feedback after each commit.

It's a tool that we develop and share for free, so anyone can automate their refactoring.

Hire us to speed up learning Rector, AST and nodes, to educate your team about Rectors benefits and to setup Rector in your project, so that you can enjoy the 300 % development speed 👍


Open-Source First

Rector instantly upgrades and refactors the PHP code of your application. It supports all versions of PHP from 5.3 and major open-source projects:


Drupal Rector rules


What Can Rector Do for You?


Documentation

Advanced

Contributing


Install

composer require rector/rector --dev
  • Having conflicts during composer require? → Use the Rector Prefixed
  • Using a different PHP version than Rector supports? → Use the Docker image

Running Rector

There a 2 main ways to use Rector:

To use them, create a rector.php in your root directory:

vendor/bin/rector init

And modify it:

// rector.php
use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    // here we can define, what sets of rules will be applied
    $parameters = $containerConfigurator->parameters();
    $parameters->set(Option::SETS, [SetList::CODE_QUALITY]);

    // register single rule
    $services = $containerConfigurator->services();
    $services->set(TypedPropertyRector::class);
};

Then dry run Rector:

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

Rector will show you diff of files that it would change. To make the changes, drop --dry-run:

vendor/bin/rector process src

Note: rector.php is loaded by default. For different location, use --config option.


Full Config Configuration

// rector.php
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    $parameters = $containerConfigurator->parameters();

    // paths to refactor; solid alternative to CLI arguments
    $parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/tests']);

    // Rector is static reflection to load code without running it - see https://phpstan.org/blog/zero-config-analysis-with-static-reflection
    $parameters->set(Option::AUTOLOAD_PATHS, [
        // autoload specific file
        __DIR__ . '/file-with-functions.php',
        // or full directory
        __DIR__ . '/project-without-composer',
    ]);

    // do you need to include constants, class aliases or custom autoloader? files listed will be executed
    $parameters->set(Option::BOOTSTRAP_FILES, [
        __DIR__ . '/constants.php',
        __DIR__ . '/project/special/autoload.php',
    ]);

    // is your PHP version different from the one your refactor to? [default: your PHP version], uses PHP_VERSION_ID format
    $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_72);

    // auto import fully qualified class names? [default: false]
    $parameters->set(Option::AUTO_IMPORT_NAMES, true);

    // skip root namespace classes, like \DateTime or \Exception [default: true]
    $parameters->set(Option::IMPORT_SHORT_CLASSES, false);

    // skip classes used in PHP DocBlocks, like in /** @var \Some\Class */ [default: true]
    $parameters->set(Option::IMPORT_DOC_BLOCKS, false);

    // Run Rector only on changed files
    $parameters->set(Option::ENABLE_CACHE, true);

    // Path to phpstan with extensions, that PHPSTan in Rector uses to determine types
    $parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, getcwd() . '/phpstan-for-config.neon');
};

Symfony Container

To work with some Symfony rules, you now need to link your container XML file

// 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::SYMFONY_CONTAINER_XML_PATH_PARAMETER,
        __DIR__ . '/var/cache/dev/AppKernelDevDebugContainer.xml'
    );
};

How to Contribute

See the contribution guide.


Debugging

You can use --debug option, that will print nested exceptions output:

vendor/bin/rector process src/Controller --dry-run --debug

Or with Xdebug:

  1. Make sure Xdebug is installed and configured
  2. Add --xdebug option when running Rector
vendor/bin/rector process src/Controller --dry-run --xdebug

To assist with echo-style debugging rector provides a print_node() helper method which is useful to pretty-print AST-nodes:

/**
 * @param Class_ $node
 */
public function refactor(Node $node): ?Node
{
    print_node($node);
    die;
}

Community Packages

Do you use Rector to upgrade your code? Add it here:


Known Drawbacks

How to Apply Coding Standards?

Rector uses nikic/php-parser, built on technology called an abstract syntax tree (AST). An AST doesn't know about spaces and when written to a file it produces poorly formatted code in both PHP and docblock annotations. That's why your project needs to have a coding standard tool and a set of formatting rules, so it can make Rector's output code nice and shiny again.

We're using ECS with this setup.

Comments
  • [Help wanted] Add PHAR

    [Help wanted] Add PHAR

    Closes https://github.com/rectorphp/rector/issues/177

    On the Menu

    • [ ] prepare composer script to install and make phar

    • [ ] prepare own phar build script

    • [ ] make local rector.phar run work

    • box and php-scoper shown as projects WIP not usable in state to this day

    Related Sources

    • https://github.com/fprochazka/phpstan-compiler
    • https://github.com/composer/composer/blob/master/src/Composer/Compiler.php
    • https://github.com/ApiGen/ApiGen/pull/788 (revert of PHAR)
    • http://php.net/manual/en/phar.construct.php
    • https://stackoverflow.com/questions/15750913/generating-a-phar-for-a-simple-application
    • https://github.com/koto/phar-util/blob/master/phar-build.php
    opened by TomasVotruba 53
  • Prefixed Rector PHAR not working

    Prefixed Rector PHAR not working

    | Subject | Details | | :------------- | :-------------------------------------------------------------------- | | Rector version | Rector 0.6.x-dev@262e8d8 | | PHP version | 7.2.18 | | Full Command | See below | | Demo link | https://github.com/infection/infection | | rector.yaml | See below |

    $ php rector.phar process /Users/tfidry/Project/Humbug/infection/src/Config/Exception/InvalidConfigException.php --dry-run --set=dead-classes -vvv
    
    rector.yaml
    parameters:
        paths:
            - 'src'
            - 'tests'
    
        exclude_rectors:
            - 'Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector'
    
        autoload_paths:
            - 'vendor/autoload.php'
    
        exclude_paths:
            - 'tests/e2e/**/*'
    
    

    Current behaviour

    Rector 0.6.x-dev@262e8d8
    Config file: rector.yaml
    
    [parsing] src/Config/Exception/InvalidConfigException.php
    PHP Fatal error:  Uncaught Error: Class '_HumbugBox60f4f031e4cc\JetBrains\PHPStormStub\PhpStormStubsMap' not found in phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php:67
    Stack trace:
    #0 phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php(38): _HumbugBox60f4f031e4cc\Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber->generateClassStub('self')
    #1 phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php(31): _HumbugBox60f4f031e4cc\Roave\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator->getClassSource(Object(_HumbugBox60f4f031e4cc\Roave\BetterReflection\Identifier\Identifier))
    #2 phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/Abst in phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php on line 67
    Fatal error: Uncaught Error: Class '_HumbugBox60f4f031e4cc\JetBrains\PHPStormStub\PhpStormStubsMap' not found in phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php:67
    Stack trace:
    #0 phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php(38): _HumbugBox60f4f031e4cc\Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber->generateClassStub('self')
    #1 phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/PhpInternalSourceLocator.php(31): _HumbugBox60f4f031e4cc\Roave\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator->getClassSource(Object(_HumbugBox60f4f031e4cc\Roave\BetterReflection\Identifier\Identifier))
    #2 phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/Abst in phar:///path/to/infection/rector.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php on line 67
    
    opened by theofidry 43
  • How does one add a failing test case?

    How does one add a failing test case?

    Question

    I earlier asked another question here, but then that question morphed to something totally different so thought it best to create a new issue which is on topic. I am trying to gain a better understand how to perform https://github.com/rectorphp/rector/blob/main/docs/how_to_add_test_for_rector_rule.md, and have a few questions.

    1. Should Symfony be installed first (i.e. new symfony my_project)
    2. Should phpunit be installed first (i.e. composer require --dev phpunit/phpunit ^9)
    3. Is PhpStorm required? Note that I do not use it.
    4. Is there any other software (other than composer require rector/rector --dev of course) that needs to be installed?
    5. Must content from rector-src be used? Reason I ask is it has rules-tests/Privatization/Rector/Class_/FinalizeClassesWithoutChildrenRector/Fixture.
    6. When performing Step 3 Find the Rector Test Case, where are these directories and files located, and are they somehow automatically created by Rector (which they are not being done so for me) or do I manually add them? If I must manually add them, how do I know what content to include other than copying what is in rector-src?
    7. If PHPUnit fails and I've successfully added a test case, where do I find it so I can include with any bugs I might find?

    I ended up copying rules-tests from rector-src to my project and then added add_final.php.inc to match the the script shown in step 4 Add Change or No-Change Test Fixture File. But when executing vendor/bin/phpunit rules-tests/Privatization/Rector/Class_/FinalizeClassesWithoutChildrenRector/FinalizeClassesWithoutChildrenRectorTest.php, got some errors that /src/constants.php and /preload.php were missing so just copied them from rector-src, and then that Class Symfony\Bridge\PhpUnit\SymfonyTestsListener does not exist and concluded I am obviously doing something wrong :(

    Appreciate any help and apologize if I should already know how to do this.

    opened by NotionCommotion 38
  • Parallel run speedup feature

    Parallel run speedup feature

    Inspiration

    • https://github.com/phpstan/phpstan-src/commit/9124c66dcc55a222e21b1717ba5f60771f7dda92
    • https://github.com/phpstan/phpstan-src/pull/125
    • https://github.com/symplify/symplify/pull/3325

    Notes

    • https://tomasvotruba.com/blog/introducing-up-to-16-times-faster-easy-coding-standard/
    feature 
    opened by TomasVotruba 34
  • #2824: Automatically add to DocBlock comments the thrown `\Throwables`.

    #2824: Automatically add to DocBlock comments the thrown `\Throwables`.

    #2824: Automatically add to DocBlock comments the thrown \Throwables.

    Was PR https://github.com/rectorphp/rector/pull/2828

    • [x] Support methods
    • [x] Support functions

    Todo in next release

    • [ ] Support \Throwables assigned to variables ($value = new \Exception())[https://github.com/rectorphp/rector/pull/2833#discussion_r377556485]
    • [ ] Support \Throwables generated by methods or functions (throw $this->createException() and throw createException())
    • [ ] Aliased imports (two exceptions with the same name, but different namespaces and one of them is aliased)
    opened by Aerendir 33
  • [Parallel]: Class was not found while trying to analyse it

    [Parallel]: Class was not found while trying to analyse it

    Bug Report

    | Subject | Details | | :------------- | :---------------------------------------------------------------| | Rector version | 0.12.10 |

    Minimal PHP Code Causing Issue

    When enable parallel option, it can got error:

     [ERROR] Could not process "tests/system/Files/FileCollectionTest.php" file, due to:                                    
             "System error: "Class FileCollectionTest was not found while trying to analyse it - discovering symbols is     
             probably not configured properly."                                                                             
             Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new". On 
             line: 45     
    

    Step to reproduce:

    1. Clone repo
    git clone [email protected]:codeigniter4/CodeIgniter4.git
    
    1. Run composer install
    composer install
    
    1. Open rector.php, add option parall:
    $parameters->set(Option::PARALLEL, true);
    
    1. Run against tests directory:
    vendor/bin/rector process tests
    

    Expected Behaviour

    It should show [OK] Rector is done! without diff and error:

    vendor/bin/rector process tests 
     257/257 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
    
                                                                                                                            
     [OK] Rector is done!                                                                                    
    
    bug 
    opened by samsonasik 32
  • How to run a sinlge rule?

    How to run a sinlge rule?

    I just need to run one rule from rector, nothing else. Can't find how to do it in neither readme nor vendor/bin/rector help process.

    According to https://github.com/rectorphp/rector/issues/2213 there was a --rule option in the past but it seems to have been removed since. What can I use instead?

    opened by enumag 30
  • Prepare for PHPStan 1.0

    Prepare for PHPStan 1.0

    Hello everyone 👋

    I announced today that PHPStan 1.0 is going to be released on November 1st 2021.

    I'm approaching you as one of the most popular projects using PHPStan internally. I'd love if you could prepare your code for PHPStan 1.0 in advance so that it's ready to release on the same day.

    Here's a brief guide how to approach the upgrade:

    1. Create a branch 🌴
    2. Update your composer.json to "phpstan/phpstan": "^1.0", add "minimum-stability": "dev" and "prefer-stable": true if necessary.
    3. Update your code with the BC breaks below in mind. 🔧
    4. Fix the code so that it passes PHPStan's analysis 🤓
    5. Wait for PHPStan 1.0 release on November 1st, merge your branch and tag the next major version 👍

    Thank you!


    Here are the BC breaks. The list is huge but most of those have very little impact.

    There are new rules around using PHPStan internals in regard to backward compatibility promise: https://phpstan.org/developing-extensions/backward-compatibility-promise

    It's possible that not everything you use is covered by it - so I'm here to help you to transition to correct usage, or add some @api annotations in PHPStan itself so that more is covered by the promise. Let me know!

    BC breaks for end-users

    • Level max is now level 9. Feel free to update max to 8 if your code isn't ready.
    • Description of some types was updated to match the syntax in PHPDocs. This includes numeric-string (it was previously described as string&numeric), and also array shapes.
    • Removed baselineNeon error formatter, use --generate-baseline CLI option instead (https://github.com/phpstan/phpstan-src/commit/492cfbcd74b540eda1520e11b67d7be00cbc7c31)
    • Removed polluteCatchScopeWithTryAssignments config parameter (https://github.com/phpstan/phpstan-src/commit/8933c7e28c2ebb1fd69584c031f579cd53ddf4ae)
    • Removed deprecated autoload_files parameter - use Discovering Symbols instead (https://github.com/phpstan/phpstan-src/commit/7a21246cae9dd7968bf7bef92223b53f5d681b72)
    • Removed deprecated autoload_directories parameter - use Discovering Symbols instead (https://github.com/phpstan/phpstan-src/commit/f67b48a71220b295a1704fe9749492e5de9ee18f)
    • Removed bootstrap parameter - use bootstrapFiles instead (https://github.com/phpstan/phpstan-src/commit/1baa29425d2e170af8ac53e4e579c34c25b640e4)
    • Moved implicitThrows configuration parameter to exceptions.implicitThrows (https://github.com/phpstan/phpstan-src/commit/96b7c48025dcbd5a709cea71ee4e9e73770e0d54)
    • Removed --paths-file CLI option (https://github.com/phpstan/phpstan-src/commit/5670cf221723eb652643623ad487351cb187f6c3)
    • Removed dump-deps command (https://github.com/phpstan/phpstan-src/commit/9c7017c697c29668f8a7c766236e597737f99f91)
    • Deprecated excludes_analyse option, use excludePaths instead (https://github.com/phpstan/phpstan-src/commit/d25c5e5a6c62a4537d4a108707ff26b5bea687d9)

    The following are interesting only if you create a custom ruleset in your configuration file:

    • Removed DeadCatchRule, replaced by CatchWithUnthrownExceptionRule (https://github.com/phpstan/phpstan-src/commit/4dba60bacbf3ac0efe8627fa32177ee21cdd3eca)
    • Removed VariableCertaintyInIssetRule, replaced by IssetRule (https://github.com/phpstan/phpstan-src/commit/2e858dee389d4843e4d1a7dc1bc565c264be247f)
    • Removed MissingClosureNativeReturnTypehintRule, no longer needed thanks to type inference (https://github.com/phpstan/phpstan-src/commit/1c34d8dc855cb5f4cf5c8b033b7155eeed0e277b)
    • Rename rules with typos (https://github.com/phpstan/phpstan-src/commit/003ab1aea558085cd27636a0b95a4c9f0e062e9a)

    BC breaks for extension developers

    • Extensions are checked with rules for correct usage of PHPStan internals according to backward compatibility promise.
    • Removed CompoundTypeHelper (https://github.com/phpstan/phpstan-src/commit/145c4e3af4045b074b1d6e697022a835433cd5f2)
    • Removed CommentHelper (https://github.com/phpstan/phpstan-src/commit/ebad6f61b9a65b68c200f7ac3a444ce198149396)
    • Removed DependencyDumper (https://github.com/phpstan/phpstan-src/commit/9c7017c697c29668f8a7c766236e597737f99f91)
    • Removed PHPStan\Reflection\Generic\ResolvedFunctionVariant, replaced by PHPStan\Reflection\ResolvedFunctionVariant (https://github.com/phpstan/phpstan-src/commit/1cc6c8175a6d92cf717cd553506c9da8a2dd72cc)
    • Removed ClassReflection::getNativeMethods(), use getNativeReflection() instead (https://github.com/phpstan/phpstan-src/commit/d2c1446b3b0f581502019c522ccb521b37e7dc15)
    • Removed PhpPropertyReflection::hasPhpDoc(), replaced by hasPhpDocType() (https://github.com/phpstan/phpstan-src/commit/bedd5be99107254f42efb7728c9ce3a7b958e33e)
    • NodeDependencies no longer iterable (https://github.com/phpstan/phpstan-src/commit/f76875a84d8dcca8f9d67c08b6492c609e9aff98)
    • Renamed TestCase to PHPStanTestCase (#634), thanks @frankdejonge!
    • StaticType and ThisType - require ClassReflection in constructor (https://github.com/phpstan/phpstan-src/commit/7aabc848351689f18a1db99598df8d5b4944aa87)
    • PHPStanTestCase - extensions can no longer be provided by overriding methods from PHPStanTestCase. Use getAdditionalConfigFiles() instead. (https://github.com/phpstan/phpstan-src/commit/65efd93f764e9db076851ef262179fe670f1ab38, https://github.com/phpstan/phpstan-src/commit/239291a91089da6684d8c52e58b9a77ceb178071)
    • Removed some unused internal helper methods from Broker (https://github.com/phpstan/phpstan-src/commit/d57815103091d8f25347b8441da3ed099f70d7af)
    • Changed return types of various methods that had |false to |null (https://github.com/phpstan/phpstan-src/commit/629ccf6b02146e1cbf0499982358c595e3d6edd5)
    • Type generalization precision is now a required argument (https://github.com/phpstan/phpstan-src/commit/65681033ff625c67a478212a0cd6da29cd5ab5fa)
    • Some constructor parameters are now required (https://github.com/phpstan/phpstan-src/commit/1f4062fe2d0d5406e9b8a782f99b6da61eceafde)
    • Deprecated BrokerAwareExtension (https://github.com/phpstan/phpstan-src/commit/db2f7fb9e7928de68665ca09a3e1002d8a329b33)
    • Deprecated PHPStanTestCase::createBroker(). Use createReflectionProvider() instead. (https://github.com/phpstan/phpstan-src/commit/1e5cf58e07446e634803c3be87e7c41fdd903c7c)
    • Deprecated PHPStan\Broker\Broker. Use PHPStan\Reflection\ReflectionProvider instead. (https://github.com/phpstan/phpstan-src/commit/c7755948c124cfbcb1220ab912a6eaa863cdf5fb)
    • Deprecated PHPStan\Broker\Broker::getInstance(). Use PHPStan\Reflection\ReflectionProviderStaticAccessor instead. (https://github.com/phpstan/phpstan-src/commit/4e7d60d74b3fda7dc4d3e0c0798b7fd55a7b32f2)
    feature 
    opened by ondrejmirtes 28
  • Syntax error in unknown file

    Syntax error in unknown file

    Bug Report

    | Subject | Details | | :------------- | :---------------------------------------------------------------| | Rector version | e.g. v0.11.40 |

    I am struggling with finding root cause of the problem with "syntax error" when I analyse files with Rector. I get:

    vendor/bin/rector process -vvv --dry-run packages/Ecommerce/tests/Unit/Common/EcommerceCommandTest.php
    [parsing] packages/Ecommerce/tests/Unit/Common/EcommerceCommandTest.php
    [refactoring] packages/Ecommerce/tests/Unit/Common/EcommerceCommandTest.php
        [applying] Rector\CodeQuality\Rector\Name\FixClassCaseSensitivityNameRector
        [applying] Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector
        [applying] Rector\Php52\Rector\Property\VarToPublicPropertyRector
        [applying] Rector\Php74\Rector\Property\TypedPropertyRector
        [applying] Rector\Php74\Rector\Property\RestoreDefaultNullToNullableTypePropertyRector
    
    In ParserAbstract.php line 269:
    
      [PhpParser\Error]
      Syntax error, unexpected '}', expecting T_VARIABLE on line 792
    
    
    Exception trace:
      at ./vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php:269
     PhpParser\ParserAbstract->doParse() at ./vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php:143
     PhpParser\ParserAbstract->parse() at ./vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/Parser/Multiple.php:48
     PhpParser\Parser\Multiple->tryParse() at ./vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/Parser/Multiple.php:31
     PhpParser\Parser\Multiple->parse() at ./vendor/rector/rector/packages/FamilyTree/Reflection/FamilyRelationsAnalyzer.php:114
     Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer->getPossibleUnionPropertyType() at ./vendor/rector/rector/rules/Php74/Rector/Property/TypedPropertyRector.php:139
     Rector\Php74\Rector\Property\TypedPropertyRector->refactor() at ./vendor/rector/rector/src/Rector/AbstractRector.php:248
     Rector\Core\Rector\AbstractRector->enterNode() at ./vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:176
     PhpParser\NodeTraverser->traverseArray() at ./vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:105
     PhpParser\NodeTraverser->traverseNode() at ./vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:196
     PhpParser\NodeTraverser->traverseArray() at ./vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:105
     PhpParser\NodeTraverser->traverseNode() at ./vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:196
     PhpParser\NodeTraverser->traverseArray() at ./vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:85
     PhpParser\NodeTraverser->traverse() at ./vendor/rector/rector/src/PhpParser/NodeTraverser/RectorNodeTraverser.php:52
     Rector\Core\PhpParser\NodeTraverser\RectorNodeTraverser->traverse() at ./vendor/rector/rector/src/Application/FileProcessor.php:54
     Rector\Core\Application\FileProcessor->refactor() at ./vendor/rector/rector/src/Application/FileProcessor/PhpFileProcessor.php:135
     Rector\Core\Application\FileProcessor\PhpFileProcessor->Rector\Core\Application\FileProcessor\{closure}() at ./vendor/rector/rector/src/Application/FileProcessor/PhpFileProcessor.php:147
     Rector\Core\Application\FileProcessor\PhpFileProcessor->tryCatchWrapper() at ./vendor/rector/rector/src/Application/FileProcessor/PhpFileProcessor.php:136
     Rector\Core\Application\FileProcessor\PhpFileProcessor->refactorNodesWithRectors() at ./vendor/rector/rector/src/Application/FileProcessor/PhpFileProcessor.php:91
     Rector\Core\Application\FileProcessor\PhpFileProcessor->process() at ./vendor/rector/rector/src/Application/ApplicationFileProcessor.php:76
     Rector\Core\Application\ApplicationFileProcessor->processFiles() at ./vendor/rector/rector/src/Application/ApplicationFileProcessor.php:57
     Rector\Core\Application\ApplicationFileProcessor->run() at ./vendor/rector/rector/src/Console/Command/ProcessCommand.php:145
     Rector\Core\Console\Command\ProcessCommand->execute() at ./vendor/rector/rector/vendor/symfony/console/Command/Command.php:274
     RectorPrefix20210725\Symfony\Component\Console\Command\Command->run() at ./vendor/rector/rector/vendor/symfony/console/Application.php:870
     RectorPrefix20210725\Symfony\Component\Console\Application->doRunCommand() at ./vendor/rector/rector/vendor/symfony/console/Application.php:266
     RectorPrefix20210725\Symfony\Component\Console\Application->doRun() at ./vendor/rector/rector/src/Console/ConsoleApplication.php:71
     Rector\Core\Console\ConsoleApplication->doRun() at ./vendor/rector/rector/vendor/symfony/console/Application.php:162
     RectorPrefix20210725\Symfony\Component\Console\Application->run() at ./vendor/rector/rector/bin/rector.php:61
     require_once() at ./vendor/rector/rector/bin/rector:5
    
    process [-n|--dry-run] [-a|--autoload-file AUTOLOAD-FILE] [-o|--output-format [OUTPUT-FORMAT]] [--no-progress-bar] [--no-diffs] [--clear-cache] [--] [<source>...]
    

    The point is that analyzed file doesn't have line 792. Looking at inheritance tree there are 2 files with this line, but each looks fine. I don't know how to find out what's the problem.

    Minimal PHP Code Causing Issue

    Not known.

    Expected Behaviour

    Rector should be more helpful with finding the real problem (logs, exception's message).

    bug 
    opened by Wirone 27
  • [Meta] [PHP 7.1 do 5.6] Plan to downgrade PHP

    [Meta] [PHP 7.1 do 5.6] Plan to downgrade PHP

    After Rector 0.10 with PHP 7.1 downgraded code, we want to go even deeper. Next stop is PHP 5.6, as that's where most legacy projects are stuck. Right before the huge wall of PHP 7.0 :)

    This is meta issue to reference downgrade rules. To kick of with few.

    From PHP 7.1 to PHP 7.0 -

    RFC links: https://wiki.php.net/rfc#php_71

    • [x] Downgrade Symmetric array destructuring to list() function ( https://github.com/rectorphp/rector/blob/main/rules/DowngradePhp71/Rector/Array_/SymmetricArrayDestructuringToListRector.php )
    • [x] Downgrade class constant visibility ( https://github.com/rectorphp/rector/blob/main/rules/DowngradePhp71/Rector/ClassConst/DowngradeClassConstantVisibilityRector.php )
    • [x] Remove the iterable pseudo type params and returns, add @param and @return tags instead ( https://github.com/rectorphp/rector/blob/main/rules/DowngradePhp71/Rector/FunctionLike/DowngradeIterablePseudoTypeDeclarationRector.php )
    • [x] Remove the nullable type params, add @param tags instead ( https://github.com/rectorphp/rector/blob/main/rules/DowngradePhp71/Rector/FunctionLike/DowngradeNullableTypeDeclarationRector.php )
    • [x] Remove void type - https://wiki.php.net/rfc/void_return_type ( https://github.com/rectorphp/rector/blob/main/rules/DowngradePhp71/Rector/FunctionLike/DowngradeVoidTypeDeclarationRector.php )
    • [x] Downgrade negative string offset to strlen ( https://github.com/rectorphp/rector/blob/main/rules/DowngradePhp71/Rector/String_/DowngradeNegativeStringOffsetToStrlenRector.php )
    • [x] Downgrade single one | separated to multi catch exception(https://github.com/rectorphp/rector/blob/main/rules/DowngradePhp71/Rector/TryCatch/DowngradePipeToMultiCatchExceptionRector.php)
    • [x] Downgrade keys in list ( https://github.com/rectorphp/rector/pull/6170 )

    From PHP 7.0 to PHP 5.6

    RFC link: https://wiki.php.net/rfc#php_70

    • [x] Remove anonymous classes https://wiki.php.net/rfc/anonymous_classes
    • [x] Remove scalar type declarations - https://wiki.php.net/rfc/scalar_type_hints_v5 ( https://github.com/rectorphp/rector/blob/main/rules/DowngradePhp70/Rector/FunctionLike/DowngradeTypeDeclarationRector.php )
    • [x] Remove strict_types declaration - https://wiki.php.net/rfc/scalar_type_hints_v5
    • [x] Remove Null coalescing - https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
    • [x] Change Spaceship to invokable anonymous function with if equal, then return ternary ( https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.spaceship-op )
    • [x] Change define array constant to const ( https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.define-array )
    • [x] Move array options in session_start to before statement ini_set ( https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.session-options )
    feature 
    opened by TomasVotruba 27
  • [PHPUnit] Migrate stubs to `createStub`

    [PHPUnit] Migrate stubs to `createStub`

    Stubs are mocks with zero expectations.

    Diff

    The following diff should be applied iff no expectations are performed later on on $service.

    - $service = $this->createMock(Service::class);
    + $service = $this->createStub(Service::class);
    

    So it should be applied iff expects() is never called. expects() appears in the interface of MockObject: https://github.com/sebastianbergmann/phpunit/blob/5e523bdc7dd4d90fed9fb29d1df05347b3e7eaba/src/Framework/MockObject/MockObject.php#L24 and not in the interface of Stub.

    $this->createMock(Service::class)->method('something')->willReturn('something else');
    // should be left untouched
    

    But after reading this line I think it can be applied if only method() is called (it's not an expectation)

    - $this->createMock(Service::class)->method('something');
    + $this->createStub(Service::class)->method('something');
    

    Implemented in https://github.com/sebastianbergmann/phpunit/pull/3810 , since 8.4.0

    opened by greg0ire 27
  • Rector sys_get_temp_dir() bug in PHP 8.x

    Rector sys_get_temp_dir() bug in PHP 8.x

    Bug Report

    I think I brought this up already, In a shared hosting environment, there is trouble on the horizon.

    Rector can't make a cache dir when using sys_get temp() as part of the string that is instructing PHP 8 to make a cache dir. In most cases, permission is denied when it comes to deleting the cache as well. Catch 22, I moved the Rector cache but the PHPstan injection dependency cache has to be manually deleted. Very time-consuming...

    It seems that the sys_get_temp_dir() function in PHP 8.x currently has a bug! When it returns the tmp dir in the string it is somehow sending false permission. It can write the cache but cannot delete it in some cases, In other cases, it can do neither and it is only in shared hosting environments, which most of us are using.

    Super users can't run it either which makes no sense at all...

    I have had to modify and do a manual delete of the dependency injection cache for PHPstan and also had to move my Rector cache dir. I can find no way to move the PHPstan cache so I have to delete it every so often so I do not get errors.

    The problem is with the sys_get_temp_dir() function in PHP 8.x - root has no problem... running it as a regular user with or without open_base dir protection on PHP 8 is a problem.

    I would normally use Fixkit7 to replace the function but that does not work in PHP 8.x

    https://www.php-nuke-titanium.86it.us/modules.php?name=Forums&file=viewtopic&p=293#293 https://stackoverflow.com/questions/13186069/sys-get-temp-dir-in-shared-hosting-environment

    I have faith in you Tom and know the next composer update that I do will have this fixed as it seems relatively simple. I appreciate all your hard work so I have not minded manually deleting the injection cache and moving the Rector Cach dir over and over :)

    You are awesome and I tell everyone I know about Rector, When they tell me about their computer God friends, I tell them they have nothing on you as you are the best! You are my brother in code and I thank you for your service, hard work, and efforts to make our lives more simple.

    Cheers Tom

    P.S. I sent you an e-mail trying to get in touch, some things I wanted to say would have taken far too long to type. you can txt me if you like and I will call you 1+ 813-846-2865

    bug 
    opened by ernestbuffington 0
  • ArrayKeysAndInArrayToArrayKeyExistsRector revmoves variables that are used later

    ArrayKeysAndInArrayToArrayKeyExistsRector revmoves variables that are used later

    Bug Report

    | Subject | Details | | :------------- | :---------------------------------------------------------------| | Rector version | 0.15.2 | | Rule | ArrayKeysAndInArrayToArrayKeyExistsRector |

    Variables that are used later are ignored.

    For example below phpstan now complains about ...

    249    Undefined variable: $tableAliases                
    

    Minimal PHP Code Causing Issue

    https://getrector.org/demo/85d78e6e-df97-485e-9412-e90550777ee5

    Expected Behaviour

    Skip it. (in this case)

    bug 
    opened by sreichel 0
  • Incorrect behavior of IntvalToTypeCastRector, LongArrayToShortArrayRector, TernaryToNullCoalescingRector, ListToArrayDestructRector, ReplaceEachAssignmentWithKeyCurrentRector, NullToStrictStringFuncCallArgRector

    Incorrect behavior of IntvalToTypeCastRector, LongArrayToShortArrayRector, TernaryToNullCoalescingRector, ListToArrayDestructRector, ReplaceEachAssignmentWithKeyCurrentRector, NullToStrictStringFuncCallArgRector

    Bug Report

    | Subject | Details | | :------------- | :--------------------| | Rector version | last dev-main | | Installed as | composer dependency |

    Minimal PHP Code Causing Issue

    See https://getrector.org/demo/63e67a74-5e27-442a-98b7-4b396e3c642a

    <?php
    
    // function block
    function get_topic_id($topic)
    {
        global $db;
        $topic_id = 0;
    
        // is this a direct value ?
        $num_topic = intval($topic);
        if ($topic == "$num_topic")
        {
            $topic_id = intval($topic);
        }
    
        // is it an url with topic id or post id ?
        else
        {
            $name = explode('?', $topic);
            $parms = ( isset($name[1]) ) ? $name[1] : $name[0];
            parse_str($parms, $parm);
            $found = false;
            $topic_id = 0;
            while ((list($key, $val) = each($parm)) && !$found):
            
                $vals = explode('#', $val);
                $val = $vals[0];
                if (empty($val)) $val = 0;
                switch($key)
                {
                    case POST_POST_URL:
                        $sql = "SELECT topic_id FROM " . POSTS_TABLE . " WHERE post_id=$val";
                        if ( !($result = $db->sql_query($sql)) ) message_die(GENERAL_ERROR, 'Could not get post informations', '', __LINE__, __FILE__, $sql);
                        if ($row = $db->sql_fetchrow($result))
                        {
                            $val = $row['topic_id'];
                            $found = true;
                        }
                        break;
                    case POST_TOPIC_URL:
                        $found = true;
                        break;
                }
                if ($found)
                {
                    $topic_id = intval($val);
                }
            endwhile;
        }
    
        return $topic_id;
    }
    

    Responsible rules

    • IntvalToTypeCastRector

    • LongArrayToShortArrayRector

    • TernaryToNullCoalescingRector

    • ListToArrayDestructRector

    • ReplaceEachAssignmentWithKeyCurrentRector

    • NullToStrictStringFuncCallArgRector

    Expected Behavior

    I should not get the following error after it modifies my code syntax error, unexpected token ")", expecting "="

    bug 
    opened by scottybcoder 4
  • TypedPropertyFromAssignsRector - intersection types PHP 7.4.30

    TypedPropertyFromAssignsRector - intersection types PHP 7.4.30

    Bug Report

    | Subject | Details | | :------------- | :---------------------------------------------------------------| | Rector version | 0.15.1 | | PHP version | 7.4.30 | | Applied rules | RenameClassRector, TypedPropertyFromAssignsRector|

    <?php
    
    declare(strict_types=1);
    
    namespace Tests;
    
    use DateTime;
    use PHPUnit\Framework\MockObject\MockObject;
    use PHPUnit\Framework\TestCase;
    
    class ExampleTest extends TestCase
    {
        /**
         * @var DateTime&MockObject
         */
        private $property;
    
        public function testExample(): void
        {
            $this->property = $this->createMock(DateTime::class);
            $this->property->expects(self::once())->method('format');
            $this->property->format('Y');
        }
    }
    
    

    Current modification

    -    /**
    -     * @var DateTime&MockObject
    -     */
    -    private $property;
    +    private ?MockObject $property = null;
    

    Expected Behaviour

    Rector should not change this file with this rules

    bug 
    opened by puniserv 10
  • Paths with spaces not supported on command line

    Paths with spaces not supported on command line

    Bug Report

    | Subject | Details | | :------------- | :---------------------------------------------------------------| | Rector version | 0.14.8 |

    Passing paths with spaces to the command line causes an error indicating the path does not exist.

    Minimal PHP Code Causing Issue

    The command rector process -- '/my files/file.php' throws the error The "files/file.php" directory does not exist..

    Expected Behaviour

    Expected the command to analyze the file specified as an argument.

    I identified that Rector\Core\Configuration\ConfigurationFactory::resolvePaths(...) splits paths on spaces. When I disable that, the command line works.

    Changing from this:

    if ($commandLinePaths !== []) {
        return $this->correctBashSpacePaths($commandLinePaths);
    }
    

    to this:

    if ($commandLinePaths !== []) {
        return $commandLinePaths;
    }
    

    ...fixes the issue, but of course this must be here for some reason. However, it breaks for me (on Mac).

    I should also note that when I specify multiple files in the command line, the logic in resolvePaths will replace all paths with the first path found with a space and uses the split values as the new list of source files. That logic is also wrong.

    bug 
    opened by joelvh 1
  • Improve behavior of RemoveSoleValueSprintfRector

    Improve behavior of RemoveSoleValueSprintfRector

    Bug Report

    | Subject | Details | | :------------- | :--------------------| | Rector version | last dev-main | | Installed as | composer dependency |

    Minimal PHP Code Causing Issue

    See https://getrector.org/demo/79cecc12-043b-48ad-80e9-f831f70eec59

    <?php
    
    $myStringVar = 'test';
    $myStringVarFormatted = \sprintf('%s', $myStringVar);
    
    $myIntVar = 1;
    $myIntVarFormatted = \sprintf('%s', $myIntVar);
    

    Responsible rules

    • RemoveSoleValueSprintfRector

    Expected Behavior

     <?php
     
     $myStringVar = 'test';
    -$myStringVarFormatted = \sprintf('%s', $myStringVar);
    +$myStringVarFormatted = $myStringVar;
     
     $myIntVar = 1;
    -$myIntVarFormatted = \sprintf('%s', $myIntVar);
    +$myIntVarFormatted = (string) $myIntVar;
    

    I think RemoveSoleValueSprintfRector should also remove sole value sprintf calls when the argument is not a string, but just cast as string (which is the behavior of sprintf if the format is %s).

    feature 
    opened by gisostallenberg 1
Releases(0.15.2)
  • 0.15.2(Dec 24, 2022)

    New Features :partying_face:

    • [TypeDeclaration] Add FalseReturnClassMethodToNullableRector (#3229)
    • [DeadCode] Add TargetRemoveClassMethodRector (#3240)
    • Adapt PrivateConstantToSelfRector to work on non-final classes, too (#3198), Thanks @alfredbez!
    • [CodingStyle] Add NullifyUnionNullableRector (#3231)
    • [TypeCoverage] Add EmptyOnNullableObjectToInstanceOfRector (#3230)
    • RenameClassRector with callback support (#3023), Thanks @dorrogeray!

    Bugfixes :bug:

    • [Php82] Handle parent already readonly on ReadOnlyClassRector (#3199)
    • [DeadCode] Skip append array data on RemoveJustPropertyFetchRector (#3201)
    • [DeadCode] Skip standalone @return false or true on RemoveUselessReturnTagRector (#3202)
    • Fix wrong reference to replacement rule (#3203), Thanks @jlherren!
    • [Privatization] Do not remove comment on ChangeReadOnlyPropertyWithDefaultValueToConstantRector (#3204)
    • [Naming] Skip Doctrine collection with @var Collection<int, Checkbox> on RenamePropertyToMatchTypeRector (#3209)
    • [Core] Performance improvement: Remove unnecessary re-call FileFactory::createFileInfosFromPaths() (#3210)
    • [Php71] Skip defer() function on RemoveExtraParametersRector (#3211)
    • [Core] Improve performance: remove repetitive currentFileProvider->setFile() call on PhpFileProcessor (#3213)
    • [Php81] Allow explicit mixed processed on trait on NullToStrictStringFuncCallArgRector (#3212)
    • [Privatization] Skip used by heredoc on ChangeReadOnlyVariableWithDefaultValueToConstantRector (#3216)
    • [Parallel] Fix missing process RemovedAndAddedFilesProcessor->run() on parallel process on WorkerRunner (#3218)
    • [parallel] Improve performance: Run RemovedAndAddeedFileProcessor after loop (#3219)
    • [CodeQuality] Add empty() check to FlipTypeControlToUseExclusiveTypeRector (#3224)
    • [CodeQuality][TypeDeclaration] Handle default value from constructor removed on InlineConstructorDefaultToPropertyRector+TypedPropertyFromStrictConstructorRector (#3225)
    • [TypeDeclaration] Skip yield return on AddClosureReturnTypeRector (#3227)
    • [TypeDeclaration] Skip optional yield on AddReturnTypeDeclarationFromYieldsRector (#3228)
    • [NodeTraverser] Use NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN instead of NodeTraverser::DONT_TRAVERSE__CHILDREN (#3233)
    • [Core] Improve performance on AstResolver and ClassLikeAstResolver (#3234)
    • [Php81] Skip ReadOnlyPropertyRector on read only class (#3236)
    • [CodingStyle] Skip new line /\r\n|\r|\n/i on ConsistentPregDelimiterRector (#3241)
    • [CodingStyle] Skip EncapsedStringsToSprintfRector on heredoc (#3242)
    Source code(tar.gz)
    Source code(zip)
  • 0.15.1(Dec 14, 2022)

    New Features :partying_face:

    • [CodingStyle] Split SplitGroupedConstantsAndPropertiesRector to SplitGroupedClassConstantsRector and SplitGroupedPropertiesRector (#3158)
    • Add compatible phpstan/phpdoc-parser 0.15 (#3157)

    Bugfixes :bug:

    • Skip short class names in UseClassKeywordForClassNameResolutionRector (#3156)
    • [Core] Fix crash indentation on indent(\t, 1) config (#3155)
    • [TypeDeclaration] Skip union mixed on TypedPropertyFromAssignsRector (#3160)
    • [TypeDeclaration] Handle Anonymous class extends existing class in union (#3161)
    • Add skipped Rectors to list-rules (#3162)
    • [TypeDeclaration] Remove PhpDocTypeChanger->changeVarType() on TypedPropertyFromAssignsRector (#3163)
    • [TypeDeclaration] Skip multi return types on ReturnTypeFromReturnDirectArrayRector (#3164)
    • [CodeQuality] Skip stdClass in IssetOnPropertyObjectToPropertyExistsRector, as always nested (#3166)
    • Do not apply property promotion to parameters with the SensitiveParameter attribute (#3165), Thanks @mbabker!
    • [TypeDeclaration] Skip void return on AddArrowFunctionReturnTypeRector (#3167)
    • [Php82] Skip ReadOnlyClassRector on has parent non-readonly class (#3169), Thanks @Yoann-TYT!
    • [CodeQuality] Handle BooleanNot on SimplifyEmptyCheckOnEmptyArrayRector (#3170)
    • [Core] Use FullyQualifiedObjectType and ThisType detection for local property fetch on PropertyFetchAnalyzer (#3172)
    • [CodeQuality] Skip non typed property no default value never assigned on SimplifyEmptyCheckOnEmptyArrayRector (#3171)
    • [PHPStanStaticTypeMapper] Handle Nullable Type on UnionType on UnionTypeMapper when possible (#3173)
    • [CodeQuality][CodingStyle] Handle crash on SimplifyIfReturnBoolRector+NewlineAfterStatementRector+StringClassNameToClassConstantRector (#3175)
    • [DeadCode] Skip Class Constant used in Enum on RemoveUnusedPrivateCla… (#3174), Thanks @eliashaeussler!
    • [Php80] Do not remove Parameter attribute on ClassPropertyAssignToConstructorPromotionRector (#3179)
    • [PHP 8.1] Skip trait in NullToStrictStringFuncCallArgRector as unknown context (#3180)
    • Fix trait property visibility in PrivatizeFinalClassPropertyRector (#3182)
    • [Php81] Allow normal variable in trait on NullToStrictStringFuncCallArgRector (#3181)
    Source code(tar.gz)
    Source code(zip)
  • 0.15.0(Dec 4, 2022)

    We released a new getrector.org website, including new documentation - https://getrector.org/documentation :tada: You can already find a few new sections there.


    This release brings the most significant changes in type safety. Few rules in type declaration worked with docblock types and completed type as strict. These rules lead to crashing code with invalid types. Instead, we've been splitting these rules into smaller and specific ones (Unix style!) that handle exact strict type declarations. This release finalizes the removal of these weak rules.


    Welcome new type declaration rules that are safe and work with 100 % known strict types ↓

    New Features :partying_face:

    • [TypeDeclaration] Add AddParamTypeBasedOnPHPUnitDataProviderRector + remove too narrow KnownArrayParamTypeInferer (#3104)
    • [TypeDeclaration] Add AddParamTypeSplFixedArrayRector (#3105)
    • [TypeDeclaration] Add AddReturnTypeDeclarationFromYieldsRector (#3114)
    • [TypeDeclaration] Add ReturnTypeFromReturnDirectArrayRector, ReturnTypeFromStrictConstantReturnRector, ReturnTypeFromStrictTypedCallRector (#3125)
    • [TypeDeclaration] Add AddParamTypeFromPropertyTypeRector (#3109)
    • Add list-rules command for tool interoperabtility (#3087)
    • Add SimplifyEmptyCheckOnEmptyArrayRector #7485 (#3069), Thanks @JohJohan!
    • [Php80] Add ClassOnThisVariableObjectRector (#3093)

    Bugfixes :bug:

    • [Php80] Skip possible numeric string switch cond with all integer case cond on ChangeSwitchToMatchRector (#3067)
    • Skip MakeTypedPropertyNullableIfCheckedRector for constructor assigment. (#3074), Thanks @Wohlie!
    • Fix StrContainsRector when strpos offset is set (#3086), Thanks @ajgarlag!
    • [TypeDeclaration] Handle return self on TypedPropertyFromStrictGetterMethodReturnTypeRector on php 8.0 feature enabled (#3088)
    • [Php80] Do not remove existing attribute on NestedAnnotationToAttributeRector (#3116)
    • [CodeQuality] Skip from non-typed param on SimplifyEmptyCheckOnEmptyArrayRector (#3115)
    • [DeadCode] Fix RemoveJustPropertyFetchRector to skip concat assigns (#3123)
    • [DeadCode] Skip re-assigned variable in RemoveJustPropertyFetchRector (#3124)
    • [Php74] Register TypedPropertyFromAssignsRector to php74 config set (#3127)
    • docs (https://github.com/rectorphp/rector-src/commit/571a1e6067342b21c2baaa10976103915299b0c6)
    • [TypeDeclaration] Skip property names in TypedPropertyFromStrictConstructorRector (#3128)
    • [TypeDeclaration] Skip doctrine collection type (#3130)
    • [TypeDeclaration] Use existing MakePropertyTypedGuard on TypedPropertyFromStrictConstructorRector (#3131)
    • [PHP 8.1] Add other methods to ClassFromEnumFactory (https://github.com/rectorphp/rector-src/commit/d2064068055fb25da2c245515a6c6260fbe6a597)
    • simplify PHPStanStaticTypeMapper (#3143), Thanks @staabm!
    • Fix foreach key evaluation for SimplifyForeachToArrayFilterRector. (#3100), Thanks @Wohlie!
    • [Php55] Handle crash on curly parentheses delimiter on PregReplaceEModifierRector (#3144)
    • [Php73] Add closure bindings for SimplifyForeachToArrayFilterRector. (#3146), Thanks @Wohlie!

    Removed Weak Doc Type Rules :skull:

    • Deprecated type-declaration-strict to type-declaration set, as single group of rules (#3103)
    • Remove deprecated ParamTypeDeclarationRector, that treated docs as strict types to keep type declaration set reliable (#3111)
    • Deprecated and remove AddArrayParamDocTypeRector to work with strict type declarations only (#3112)
    • [TypeDeclaration] Remove and disable breaking ReturnTypeDeclarationRector, use split rules instead (#3120)
    • deprecate generic and breaking PropertyTypeDeclarationRector (https://github.com/rectorphp/rector-src/commit/dd44b98fd9da53cdc02797a8b6400df514bf2438)
    • [TypeDeclaration] Disable and deprecate PropertyTypeDeclarationRector and TypedPropertyRector, to avoid breaks; use split strict rules instead (#3122)
    • [TypeDeclaration] Deprecate unreliable AddArrayReturnDocTypeRector, used split strict typed rules instead (#3133)

    Removed Features :skull:

    • Remove auto import on changed files only to avoid too detailed setup and making ambiguous code (#3132)
    • [config] Deprecate and remove @noRector annotation, as not reliable DX choice; use skip() method instead (#3148)
    • Remove deprecated RectorConfig::disableImportShortClasses(), use importShortClasses(false) instead (https://github.com/rectorphp/rector-src/commit/750758971cd05a576eb9928d5dbbad6fbc36d0d4)
    • Remove deprecated RectorConfig::disableImportNames(), use importNames(false, false) instead (#3147)
    • Remove deprecated APPLY_AUTO_IMPORT_NAMES_ON_CHANGED_FILES_ONLY option (https://github.com/rectorphp/rector-src/commit/a4e7a4371a1a85f2dd3fcb9ec7d9de2a8a04d3b9)
    • Make Rector PHPOffice optional package, as only migrates ~7 years old version (#3061)
    Source code(tar.gz)
    Source code(zip)
  • 0.14.8(Nov 14, 2022)

    New Features :partying_face:

    • Update PHP-Parser to ^4.15.2 (#3057)
    • [Php80] Add $object::class support on GetDebugTypeRector (#3039)
    • [Php81] Register uniqid function on NullToStrictStringFuncCallArgRector (#3045), Thanks @bkosun!
    • [Init] Add smart paths detection to "init" command to make first Rector experience better (#3050)
    • [Core] Improve performance: only reindex Node Attributes when Original Node is not null (#3043)
    • [Core] Improve performance: only update and connect parent Node when different Node (#3044)
    • [Core] Improve performance: remove unnecessary loop StmtsAwareInterface to fill Scope on PHPStanNodeScopeResolver (#3048)
    • [Core] Improve performance on NodeComparator (#3049)
    • [Core] Improve performance: verify consecutive execute same Rector Rule when Original Node is Null (#3047)
    • [Core] Improve performance: remove unnecessary loop on SimpleCallableNodeTraverser (#3053)

    Bugfixes :bug:

    • [Caching] Fix cache consecutive run rector with --dry-run (#3060)
    • [Php80][CodeQuality] Handle crash on ExplicitMethodCallOverMagicGetSetRector+ChangeSwitchToMatchRector (#3034)
    • [Php55] Handle crash on ([[:upper:]]+) regex on PregReplaceEModifierRector (#3037)
    • Apply node->isFirstCallable() check early before ->getArgs() when possible on CallLike (#3038)
    • Fix var/property usage for RemoveUnusedNonEmptyArrayBeforeForeachRector. (#3040), Thanks @Wohlie!
    • [Php81][Restoration] Handle crash on ReadOnlyPropertyRector+MakeTypedPropertyNullableIfCheckedRector (#3046)
    • Re-print on constructor promotion (#3051), Thanks @greg0ire!
    • remove NodeTypeAnalyzer (#3055), Thanks @staabm!
    • [Core] Fix resolve scope handling when parent Node just re-printed (#3056)
    Source code(tar.gz)
    Source code(zip)
  • 0.14.7(Nov 7, 2022)

    New Features :partying_face:

    • Move Rector Laravel to the community (#3019) - thanks to @driftingly for taking package further :clap:
    • [CodeQuality] Add TernaryEmptyArrayArrayDimFetchToCoalesceRector (#3027)
    • NullToStrictStringFuncCallArgRector - Register a few more functions (#2994), Thanks @craigfrancis!
    • Update all classlike pseudo rector (#3002), Thanks @webmaster777!
    • Register Ctype functions (#3008), Thanks @bkosun!
    • Compatibility with BetterReflection 6.x (#2999), Thanks @ondrejmirtes!

    Bugfixes :bug:

    • [CodeQuality] Skip different array_filter value on SimplifyEmptyArrayCheckRector (#3000)
    • [CodeQuality] Skip different value left and right on SimplifyEmptyArrayCheckRector (#2998)
    • [Php70] Handle crash on First class callable on ThisCallOnStaticMethodToStaticCallRector (#3003)
    • [Down_To_PHP71] Handle Downgrade Param Widening + Downgrade Reflection Get on DowngradeLevelSetList::DOWN_TO_PHP_71 (#3001)
    • Add real path to filePaths when not false (#3004), Thanks @jamwid07!
    • [DeadCode] Handle RemoveUnusedPrivateMethodRector+RemoveDuplicatedIfReturnRector when private method used in FuncCall with ArrowFunction (#3007)
    • [Php80] Handle crash on extends \mysqli on AddParamBasedOnParentClassMethodRector (#3009)
    • [Php80] Skip callable type different definition on ClassPropertyAssignToConstructorPromotionRector (#3010)
    • [EarlyReturn] Handle crash on RemoveAlwaysElseRector+ReturnEarlyIfVariableRector (#3011)
    • [DeadCode] Handle crash on has first class callable on RemoveUnusedConstructorParamRector (#3015)
    • [Php80] Handle nested annotation not end with () on AnnotationToAttributeRector (#3017)
    • [TypeDeclaration] Skip intersection with iterable on ReturnTypeDeclarationRector on php 8.1 feature enabled (#3022)
    • InlineConstructorDefaultToPropertyRector fix code example (#7465) (#3028), Thanks @GeniJaho!
    • [Php81] Skip on Array Destructuring on ReadOnlyPropertyRector (#3030)
    Source code(tar.gz)
    Source code(zip)
  • 0.14.6(Oct 15, 2022)

    New Features :partying_face:

    • Move cakephp Rector from the core to the community (#2966)
    • Use better composer-unused (#2972)

    Bugfixes :bug:

    • [DeadCode][Privatization] Handle crash on RemoveDeadZeroAndOneOperationRector+ChangeReadOnlyPropertyWithDefaultValueToConstantRector (#2962)
    • [DeadCode][EarlyReturn] Handle RemoveUnusedVariableAssignRector+RemoveAlwaysElseRector (#2964)
    • Fix wrong results in ExactCompareFactory (#2973), Thanks @jlherren!
    • [Php81] Skip assigned after defined as constructor promotion on ReadOnlyPropertyRector (#2976)
    • [Php80] Handle crash on nullable scalar with mixed param on MixedTypeRector (#2977)
    • [Core] Set compatible with latest BetterReflection usage to handle assert($startLine > 0) notice (#2978)
    • [TypeDeclaration] Handle Parent ClassMethod has no Return_ stmt on ReturnTypeDeclarationRector (#2980)
    • [Privatization] Skip Property unsetted on ChangeReadOnlyPropertyWithDefaultValueToConstantRector (#2981)
    • fix symfony deprecation reports (https://github.com/rectorphp/rector-src/commit/e58f390c5e98542f12d559ee1c30dd46716d7286)
    • [Core] Remove second param on ClassLikeAstResolver::resolveClassFromClassReflection() (#2975)
    • [Core] Ensure refresh Scope Nodes when AbstractRector refactor() return array of Nodes (#2979)
    • [Core][Symfony] Handle crash on get dynamic value ClassConstFetch by method call on ChangeStringCollectionOptionToConstantRector (#2984)
    • [Php80] Handle crash after transform with trait-string on UnionTypesRector (#2985)
    • Fix multi property default assign (#2986)
    • Add new rule to simplify a last useless variable assignment. (#2963), Thanks @Wohlie!
    • Fix missing extra import on NestedAnnotationToAttributeRector (#2989)
    • Assert JoinColumns in CPP should be converted (#2991)
    Source code(tar.gz)
    Source code(zip)
  • 0.14.5(Sep 29, 2022)

  • 0.14.4(Sep 27, 2022)

    New Features :partying_face:

    • [Naming] Add TwigEnvironment special name to RenameParamToMatchTypeRector to keep the context (#2951)
    • Add support for interface in AnnotationToAttributeRector rule (#2958), Thanks @astronom!

    Bugfixes :bug:

    • Skip short class names on StringClassNameToClassConstantRector, as mostly internal classes or strings (#2950)
    • [CodeQuality] Skip nullable mixed on ReturnTypeFromStrictScalarReturnExprRector (#2947), Thanks @thomasschiet!
    • [Php81] Handle crash insensitive function name on NullToStrictStringFuncCallArgRector (#2953)
    • [AutoImport] Add support for auto import in alias same last name (#2952)
    • [Php80] Skip no default next indirect in return Expr on ChangeSwitchToMatchRector (#2959)
    Source code(tar.gz)
    Source code(zip)
  • 0.14.3(Sep 23, 2022)

    New Features :partying_face:

    • Add rector/rector-php-parser - https://github.com/rectorphp/rector-php-parser

    Bugfixes :bug:

    • [Down_To_PHP71] Handle both parent and child typed for trailing comma downgrade on DowngradeLevelSetList::DOWN_TO_PHP_71 (#2910)
    • [PHP 8.1] Do not process static methods from Enum class (#2911)
    • [PHP 7.4] Fix literator separator string/int missmatch in PHPStan type (#2913)
    • [Doctrine] Handle Partial removal annotation has annotation below on RemoveRedundantDefaultPropertyAnnotationValuesRector (#2914)
    • [DeadCode] Handle assign empty array on if cond on RemoveUnusedNonEmptyArrayBeforeForeachRector (#2917)
    • [DeadCode] Skip assign if cond on RemoveUnusedNonEmptyArrayBeforeForeachRector (#2918)
    • Skip first class callables in NullToStrictStringFuncCallArgRector (#2919), Thanks @thomasschiet!
    • [Skipper] Handle provide direct relative path in Skipper (#2921)
    • Fix VarAnnotationIncorrectNullableRector, add support for closure params when generating php doc (#2922), Thanks @dorrogeray!
    • [CodingStyle] Skip has non-printable chars on SymplifyQuoteEscapeRector (#2926)
    • [Php80] Handle crash on Nested Annotation to Attribute setting PhpVersion::PHP_80 (initializer - 1) (#2929)
    • [Visibility] Does not turn abstraction into static from implicit public abstractions in ExplicitPublicClassMethodRector (#7483) (#2930), Thanks @Goral64!
    • [Php55] Allow alias name on StringClassNameToClassConstantRector (#2931)
    • [TypeDeclaration] Add AddArrowFunctionReturnTypeRector (#2933)
    • [DeadCode] Skip nullable array on not empty on RemoveUnusedNonEmptyArrayBeforeForeachRector (#2935)
    • [AutoImport] Allow auto import to use existing alias in use statement (#2937)
    • Skip properties with default values for MakeTypedPropertyNullableIfCheckedRector (#2936), Thanks @Wohlie!
    • [AutoImport] Add GroupUse support on auto import (#2939)
    • [AutoImport] Skip multiple namespaces on single file on auto imports (#2940)
    • Skip method of abstract class for StaticCallOnNonStaticToInstanceCallRector. (#2938), Thanks @Wohlie!
    • Skip magic methods for StaticCallOnNonStaticToInstanceCallRector. (#2941), Thanks @Wohlie!
    • Add refactorings for ...val() (#2942), Thanks @Wohlie!
    • [DeadCode] Handle crash on RemoveUnusedPrivatePropertyRector+RemoveJustPropertyFetchForAssignRector (#2943)
    • Fix type error on downgraded version. (#2946), Thanks @Wohlie!
    • [TypeDeclaration] Skip intersection array on ReturnTypeDeclarationRector on PHP 8.1 feature enabled (#2948)
    • [Php56] Skip after exit() on AddDefaultValueForUndefinedVariableRector (#2949)
    • ParamAnalyzer: Accept all FunctionLike (#2945), Thanks @jtojnar!
    Source code(tar.gz)
    Source code(zip)
  • 0.14.2(Sep 4, 2022)

    Bugfixes :bug:

    • [Php74] Skip Nested ternary parenthesized multiline on ParenthesizeNestedTernaryRector (#2902)
    • Update nikic/php-parser to 4.15.1 (#2903)
    • [Php55] Handle pre-slash string on StringClassNameToClassConstantRector (#2905)
    • Explain how to persist Rector caches between CI runs (#2906), Thanks @CodeCasterNL!
    • Fix missing FileSystem class in Symfony project (#7449)
    Source code(tar.gz)
    Source code(zip)
  • 0.14.1(Sep 3, 2022)

    New Features :partying_face:

    Read on the blog: Support for Nested Doctrine Annotation to Flat Attributes in Rector 0.14

    • [PHP 8.0] Add NestedAnnotationToAttributeRector (#2781)
    • [PHP 8.0] Add way to adjust specifics attribute arguments (#2834)

    • [BetterPhpDocParser] Add ArrayItemNode to improve value transfer in annotation curly lists (#2786) (#2795)
    • + 20 % performance improvement by lazy loading resources (#2774), Thanks @ossinkine!
    • [PHP 8.0] Refactor ChangeSwitchToMatchRector to StmstAwareInterface (#2801)
    • [Naming] Add ArrowFunction support on RenameParamToMatchTypeRector (#2818)
    • Support for ConstFetch (true, false, null) in NodeFactory::createArrayItem (#2778), Thanks @xorik!
    • [PHP 7.4] Add MoneyFormatToNumberFormatRector (#2727)
    • [DX] Make tracy debug functions part of dev-only, so developers can use own debug style (#2848)
    • Add rector-debugging to require-dev (#2857)
    • Support for ConstFetch (true, false, null) in NodeFactory::createArrayItem (#2778), Thanks @xorik!
    • [PHP 8.0] Add custom JMS AccesorOrder explicit key (#2895)

    Bugfixes :bug:

    • Handle crash on RenameFunctionRector+ForRepeatedCountToOwnVariableRector+CountOnNullRector+NullToStrictStringFuncCallArgRector (#2777)
    • [CodeQuality] Fix out-of-order items removal in UnusedForeachValueToArrayKeysRector (#2779)
    • [PHP 8.0] Keep quoted string with doublecolon in AnnotationToAttributeRector (#2784)
    • [PHP 8.0] Fix ChangeSwitchToMatchRector for next new variable re-use (#2798)
    • Fix generics and intersection in TypedPropertyRector (#7392) (#2800), Thanks @Khartir!
    • [CodeQuality] Add StaticCall support on OptionalParametersAfterRequiredRector (#2817)
    • [PHP 5.5] Make StringClassNameToClassConstantRector skip lcfirst (#2888)
    • [AutoImport] Handle auto import crash on docblock @SuppressWarnings(PHPMD.ElseExpression) inside anonymous class (#2808)
    • [CodingStyle] Skip translation functions on EncapsedStringsToSprintfRector (#2809)
    • [PHP 8.1] Handle crash backed Enum not implemented on FirstClassCallableRector (#2815)
    • [EarlyReturn] Do not remove previous If_ stmts on ChangeNestedIfsToEarlyReturnRector (#2820)
    • [EarlyReturn] Handle crash on assign in if else before on RemoveAlwaysElseRector (#2822)
    • [EarlyReturn] Skip ChangeAndIfToEarlyReturnRector in case of simple scalar return (#2826)
    • [EarlyReturn] Skip indirect return with define variable after parent else on ChangeAndIfToEarlyReturnRector (#2836)
    • [DeadCode] Skip object shape pseudo-type in RemoveNonExistingVarAnnotationRector (#2837)
    • [PHP 8.0] Handle single quoted is_granted on AnnotationToAttributeRector (#2842)
    • [DowngradePhp80/72] Handle DowngradeTrailingCommasInParamUseRector+DowngradeParameterTypeWideningRector (#2843)
    • [CodingStyle] Handle multiple assigns on SplitDoubleAssignRector (#2873)
    • [Testing] Use own FixtureFileFinder to keep dependency low (#2858)
    • [PHP 7.4] Add ParenthesizeNestedTernaryRector (#2859)
    • Fix class not found from Easy-Testing package (#2864)
    • [phpstan] Resolve duplicated methods (#2869)
    • [EarlyReturn] Skip else has inline html on RemoveAlwaysElseRector (#2870)
    • [Php55] Skip StringClassNameToClassConstantRector on case insensitive (#2896)
    • [Transform] Skip transitional interface in AddInterfaceByTraitRector (#2898)
    • [CodeQuality] Skip static::class on InlineConstructorDefaultToPropertyRector (#2899)

    Inline Symplify Packages to Allow Changes in Single Place :+1:

    Based on community feedback, we've narrowed down few dependencies that Rector uses actively, but were maintained in external repository. Inlining only the classes we need makes Rector easier to contribute as the code is available in the repository.

    • symplify/astral
    • symplify/package-builder
    • symplify/smart-file-system
    • symplify/symplify-kernel
    • symplify/skipper

    Read on the blog: Tests Made Simpler

    Apart making contributions simpler, the vendor is 10 % smaller, narrow from 1949 files to 1765 :+1:

    • [DX] Inline Skipper (#2877)
    • [DX] Remove internally SmartFileInfo, to save memory for every single file + service (#2876)
    • [DX] Reduce inner use of SmartFileInfo, and injected SmartFileSystem (#2847)
    • [DX] Inline symplify/astral to use only active classes (#2851)
    • [DX] Make use of FilePathHelper over inner magic of FileSystem in SmartFileInfo (#2862)
    • [tests] Use file paths over value objects in tests to improve performance (#2878)
    • [DX] Use own path normalizer (#2881)
    • [DX] Localize few PackageBuilder classes (#2884)
    • [DX] Remove PackageBuilder classes (#2885)

    Removed :skull:

    • [DeadCode] Merge RemoveDeadConstructorRector, to RemoveEmptyClassMethodRector with same behavior (#2829)
    • [DeadCode] Remove RemoveUnusedParamInRequiredAutowireRector, as one time job for private project; not useful for generic (#2830)
    • [CodeQuality] Remove SimplifyIfIssetToNullCoalescingRector, as overly complex and should be handled by manual context (#2828)
    • [Restoration] Remove CompleteImportForPartialAnnotationRector, one time custom job, not useful for generic rules (#2831)
    • [Transform] Remove ServiceGetterToConstructorInjectionRector, only for risky doctrine case, that should be handled manually (#2832)
    • [DX] Remove upgrade RectorConfig set, as last 2 version use only PHP (#2852)
    • [DX] Cleanup of text file processor, unused MultipleFilesChangedTrait and misc (#2861)
    • [DX] Remove composer-json-manipulator (#2871)
    • [DX] Remove the composer upgrade as unused to narrow focus back to PHP (#2871)

    Symfony Rector :musical_score:

    • [Symfony 2.8] Make ServiceSetStringNameToClassNameRector skip classes used twice to avoid autowiring error (#232)

    Doctrine Rector :orange_circle:

    • Improve MakeEntitySetterNullabilityInSyncWithPropertyRector (#121), Thanks @alexander-schranz
    Source code(tar.gz)
    Source code(zip)
  • 0.14.0(Aug 17, 2022)

    First, we're just passed great achievement. Rector has pased over 10 000 000 downloads :tada: :partying_face:

    Thank you for joining us on this adventurous journey. Slowly but surely we're removing legacy code from codebases all over the world :pray: :+1:


    2 Community Packages

    In Rector 0.14, 2 Rector extensions have matured enough to become standalone packages. We've decided to move them from the core closer to their own communities. Where they can grow faster and with inline of their community standards :+1: :family:

    Typo3 and Nette are now moved from Rector core to their own repositories:

    • https://github.com/sabbelasichon/typo3-rector
    • https://github.com/efabrica-team/rector-nette

    Read more about it in a post from our blog.


    New Features :partying_face:

    • [tests] Add Ability to yield files with names (#2732), Thanks @Wirone!
    • [TypedDeclaration] Add MockObject property type support to TypedPropertyFromAssignsRector (#2737)
    • [TypeDeclaration] Make anonymous class return specific type, if implements (#2738)
    • Improve ReturnTypeWillChangeRector to handle any method of defined type; move PhpDocFromTypeDeclarationDecorator to Downgrade rules (#2754)
    • [Php73] Add Method Call support on on IsCountableRector (#2762)

    Bugfixes :bug:

    • [Php80] Skip default no stmt next is case on ChangeSwitchToMatchRector (#2728)
    • [DeadCode] Skip RemoveAlwaysTrueIfConditionRector on property use by @var docblock on Trait (#2729)
    • [Php80][TypeDeclaration] Handle UnionTypesRector+AddArrayReturnDocTypeRector on auto import FullyQualified doc (#2730)
    • [DeadCode] Handle assign in If_ cond on RemoveUnusedNonEmptyArrayBeforeForeachRector (#2734)
    • [Php80] Preserve int key defined not start from 0 on AnnotationToAttributeRector (#2735)
    • [TypeDeclaration] Skip data providers in AddArrayReturnDocTypeRector, they're overly complex and not helpful to type (#2736)
    • [CodingStyle] Fix re-print of self in PreferThisOrSelfMethodCallRector (#2759)
    • [Php54][Php80] Handle no scope on LongArrayToShortArrayRector+AnnotationToAttributeRector (#2749)
    • [Php81] Skip Encapsed on NullToStrictStringFuncCallArgRector (#2744)
    • [CodeQuality] Skip not ArrayType on ForeachItemsAssignToEmptyArrayToAssignRector (#2752)
    • AddReturnTypeDeclarationBasedOnParentClassMethodRector fix mixed return type by parent interface (#2755), Thanks @MartinMystikJonas!
    • [Php73] Skip escaped Dash on RegexDashEscapeRector (#2753), Thanks @ebrigham1!
    • [CodeQuality][Up_TO_PHP_81] Handle crash indentation on combination LevelSetList::UP_TO_PHP_81 with SetList::CODE_QUALITY (#2760)
    • [Php81] Handle crash on Crypt() single arg on NullToStrictStringFuncCallArgRector (#2767)
    • [Php80] Handle trailing comma on AnnotationToAttributeRector on Doctrine JoinColumn (#2766)
    • [CodeQuality][Up_TO_PHP_81] Handle crash indentation on combination LevelSetList::UP_TO_PHP_81 with SetList::CODE_QUALITY - take 2 (#2763)
    • [DeadCode] Fix RemoveUnusedPrivateMethodParameterRector args keys re-order (#2770)
    • [Php55] Handle no quote in backslash on PregReplaceEModifierRector (#2771)
    • Make ServiceGetterToConstructorInjectionRector report only if node has changed, retarget to Class_ node with higher priority (#2772)

    Doctrine Rector :orange_circle:

    • Add set to convert gedmo annotations to attributes (#117) - Thanks @acrobat
    • Add DoctrineTargetEntityStringToClassConstantRector (#98) - Thanks @dritter

    Symfony Rector :musical_score:

    • Skip non-direct inheritors for AbstractType in RemoveDefaultGetBlockPrefixRector (#219)
    • Handle single action with __construct on InvokableControllerRector (#218)
    • [Symfony 2.5] Add AddViolationToBuildViolationRector (#211)
    • [Symfony 2.8] Add ServiceSetStringNameToClassNameRector for fluents configs (#213)
    • [Symfony60] Fix added return type for Router::getRouteCollection (#207) - Thanks @kick-the-bucket
    Source code(tar.gz)
    Source code(zip)
  • 0.13.10(Aug 3, 2022)

    New Features :tada:

    • [Php80] Add MixedTypeRector (#2701)
    • [CodingStyle] Skip has static call call non static method on StaticArrowFunctionRector and StaticClosureRector (#2713)
    • [Doc] Add documentation for parallel troubleshooting (#2722), Thanks @rafaelbernard!
    • Add class-string typehint to MethodCallRename (#2726), Thanks @alexander-schranz!

    Bugfixes :bug:

    • [Php81] Skip Doctrine ORM MappedSuperClass attribute on ReadOnlyPropertyRector (#2712)
    • [CodeQuality][CodingStyle] Handle crash assert($subStartPos >= 0 && $subEndPos >= 0) on combination CodeQuality and CodingStyle rules (#2707)
    • [DeadCode] Handle crash on negation class const fetch with static:: and parent:: on RemoveDeadZeroAndOneOperationRector (#2714)
    • [DowngradePhp81] Handle no scope on DowngradeFirstClassCallableSyntaxRector inside ArrayItem (#2709)
    • Fix/do not inline constructor default when readonly (#2720), Thanks @kpn13!
    • Fix/early return inline constructor default 7319 (#2716), Thanks @kpn13!
    • [TypeDeclaration] Handle crash on intersection in Union type on AddMethodCallBasedStrictParamTypeRector (#2704)
    • [DeadCode] Skip RemoveAlwaysTrueIfConditionRector on property use by @var docblock (#2717)
    • Apply ParametersAcceptorSelectorVariantsWrapper::select() take 2 (#2718)
    • ExplicitMethodCallOverMagicGetSetRector fix (#2719), Thanks @MartinMystikJonas!
    • [Php56] Skip already initialized on next Stmt on AddDefaultValueForUndefinedVariableRector (#2721)
    • [Php56] Ensure return null on empty variable initialization after check with existing stmts on AddDefaultValueForUndefinedVariableRector (#2723)
    • [Php56] Handle jump not Expression stmt next initialized on AddDefaultValueForUndefinedVariableRector (#2725)
    Source code(tar.gz)
    Source code(zip)
  • 0.13.9(Jul 23, 2022)

    New Features :tada:

    • [CodingStyle] Add StaticArrowFunctionRector (#2657)
    • [CodingStyle] Add StaticClosureRector (#2658)
    • [Php80] Add implements interface support on single file on AddParamBasedOnParentClassMethodRector (#2660
    • [PHP 8.1] Extend MyCLabsMethodCallToEnumConstRector with getValue() and static call (#2695)
    • [PHP 8.1] Keep use stmts in MyCLabsClassToEnumRector enum (#2696)
    • Add AddReturnTypeDeclarationBasedOnParentClassMethodRector (#2666), Thanks @MartinMystikJonas!
    • [DX] Add input validation for method, property and function name to avoid invalid output ast (#2668)
    • Improve namespace names validation (#2670)

    Bugfixes :bug:

    • [DeadCode] Skip global and static variable on RemoveJustVariableAssignRector (#2641)
    • [DeadCode] Skip global and static variable on ReturnEarlyIfVariableRector (#2642)
    • [StrictTypes] Add MethodCall/StaticCall to ExclusiveNativeCallLikeReturnMatcher (#2646)
    • [TypeDeclaration] Add assigned new to variable in ReturnTypeFromReturnNewRector (#2647)
    • DependencyClassMethodDecorator: Prevent duplication of arguments (#2643), Thanks @jtojnar!
    • [TypeDeclaration] Skip Type modified between Assign and Return_ on ReturnTypeFromReturnNewRector (#2650)
    • [TypeDeclaration] Skip modififed type between assign and return on ReturnTypeFromStrictNewArrayRector (#2651)
    • [Php74] Skip TypedPropertyRector on final class by @final docblock (#2654)
    • [DeadCode] Handle crash on indirect parent BinaryOp on RemoveDuplicatedInstanceOfRector (#2656), #7293
    • [TypeDeclaration] Skip property exists in parent on TypedPropertyFromStrictConstructorRector (#2659)
    • Fix test to only resolve to known classes (#2663), Thanks @dritter!
    • Fix getter method property substitution when the readable types don't match. (#2667), Thanks @mad-briller!
    • [CodeQuality] Handle crash attribute used on trait on CallableThisArrayToAnonymousFunctionRector (#2675)
    • Attempt to fix incorrect doctrine table attribute values on php 8.1 (#2699), Thanks @acrobat!
    • [Transform] Handle crash string in EnumCase on StringToClassConstantRector (#2680)
    • Fix InlineArrayReturnAssignRector and ChangeReadOnlyPropertyWithDefaultValueToConstantRector collision (#2701)

    Removed :wastebasket:

    • move ReturnTypeFromStrictTypedCallRector to enterprise (#2685)
    • [DX] Cleanup, Remove RepeatedLiteralToClassConstantRector, as very narrow use case; use rather phpstan + Remove ChangeLocalPropertyToVariableRector, as buggy and unreliable; better use PHPStan (#2686)
    • Remove UnwrapFutureCompatibleIfFunctionExistsRector as very niche and specific (#2688)
    • [CodingStyle] Deprecate PHPStormVarAnnotationRector, rather tokens responsibility (#2677)
    Source code(tar.gz)
    Source code(zip)
  • 0.13.8(Jul 7, 2022)

    New Features :tada:

    • [CodeQuality] Add TernaryFalseExpressionToIfRector (#2590)
    • [TypeDeclaration] Add ReturnTypeFromStrictScalarReturnExprRector (#2601)
    • [EarlyReturn] Add ReturnEarlyIfVariableRector (#2609)
    • [Php54] Add ArrayToShortArrayRector (#2615), Thanks @edsrzf!
    • [DeadCode] Add RemoveJustVariableAssignRector (#2618)
    • [TypeDeclaration] Add TypedPropertyFromStrictSetUpRector (#2636)

    Bugfixes :bug:

    • [DeadCode] Handle always terminated Switch_ on RemoveUnreachableStatementRector (#2591)
    • [DeadCode] Handle collection of Case_ on RemoveUnreachableStatementRector (#2593)
    • [DeadCode] Handle anonymous and arrow function uses in RemoveJustPropertyFetchRector (#2592), Thanks @kick-the-bucket!
    • [Naming] Skip used in arrow function args on RenameVariableToMatchMethodCallReturnTypeRector (#2599)
    • [TypeDeclaration] Skip AddArrayReturnDocTypeRector on custom phpstan type (#2608)
    • [DeadCode] Handle edge cases on RemoveJustVariableAssignRector (#2621)
    • [Php71] Skip First Class Callable on RemoveExtraParametersRector (#2622)
    • [CodeQuality] Fix CompactToVariablesRector to resolve values when the compact() is called (#2627)
    • [DX] Improve direct return of Stmt arrays in Rector rules, remove NodesToAddCollector from AbstractRector (#2623)
    • [CodingStyle] Handle VarConstantCommentRector+NewlineAfterStatementRector (#2629)
    • [Php80] Skip no default on case collection assign on ChangeSwitchToMatchRector (#2631)
    • [DeadCode] Do not remove first class callable VariadicPlaceholder arg on RemoveUnusedPrivateMethodParameterRector (#2634)
    • [TypeDeclaration] Do not change more detailed return doc on ReturnTypeFromStrictNewArrayRector (#2638)

    Removed :wastebasket:

    • Remove RemoveOverriddenValuesRector as flow of control is not reliable and could cause invalid removal (#2614)
    • [CodeQuality] Remove DateTimeToDateTimeInterfaceRector as mostly opinionated and way too much generics (#2598)
    • [EarlyReturn] Remove ReturnAfterToEarlyOnBreakRector as risky and turning around next/previous nodes (#2624)
    • [Transform] Remove CallableInMethodCallToVariableRector as very narrow use case and sensitive to wrong change (#2625)
    Source code(tar.gz)
    Source code(zip)
  • 0.13.7(Jun 29, 2022)

    New Features :tada:

    • Decouple new Downgrade PHP package: https://github.com/rectorphp/rector-downgrade-php
    • [TypeDeclaration] Add ReturnTypeFromStrictReturnExprRector (#2563)
    • [TypeDeclaration] Add ReturnTypeFromStrictNativeFuncCallRector (#2570)
    • [TypeDeclaration] Add ReturnTypeFromStrictNewArrayRector (#2572)
    • [DowngradePhp80] Add DowngradeMixedTypeTypedPropertyRector (#2579)
    • [Parallel] Display stack trace on --debug on parallel (#2561)
    • Bump PHPStan to 1.8 (#2588)

    Bugixes :bug:

    • [PSR4] Do not remove declare(strict_types=1) on NormalizeNamespaceByPSR4ComposerAutoloadRector (#2551)
    • [Php54] Add MethodCall and StaticCall support on RemoveReferenceFromCallRector (#2553)
    • Clean MethodToMethodCallRector (#2554) , Thanks @SelrahcD!
    • [DowngradePhp80] Do not change correct Union array docblock to mixed[] on DowngradeUnionTypeDeclarationRector (#2555)
    • [CodeQuality] Drop ArrayThisCallToThisMethodCallRector as changes behavior and better handled by FirstClassCallableRector (#2571)
    Source code(tar.gz)
    Source code(zip)
  • 0.13.6(Jun 21, 2022)

    New Features :tada:

    • [Core] AbstractScopeAwareRector is ready to be used in custom rules (#2537)
    • [PHP 8.1] Add FirstClassCallableRector (#2544)
    • [Php81] NullToStrictStringFuncCallArgRector - Register more functions (#2543), Thanks @hungtrinh!
    • Improve RectorConfig import methods (#2526), Thanks @alexndlm!

    Bugfixes :bug:

    • [Renaming] Do not rename docblock same name not found in use inside namespace (#2471)
    • [TypeDeclaration] Skip generic on ReturnTypeDeclarationRector (#2469)
    • [DeadCode] Skip using coealesce assign operator on return on RemoveUnusedPrivatePropertyRector (#2476)
    • [DeadCode] Skip has return reassign Coalesce Op on RemoveUnusedPrivatePropertyRector (#2477)
    • [Php55] Handle crash on concat variable single quote on PregReplaceEModifierRector (#2483)
    • [PSR4] Handle invalid missing ; on NormalizeNamespaceByPSR4ComposerAutoloadRector with GroupUse (#2488)
    • [Php70] Refactor MultiDirnameRector by moving nestingLevel check to separate method (#2492)
    • [Php81] Fix crash on redis->set() on ReadOnlyPropertyRector (#2494)
    • [TypeDeclaration] Skip implements mixed, and already has typed return on AddReturnTypeDeclarationRector (#2509)
    • [Php81] Skip param reassign on ReadOnlyPropertyRector (#2498)
    • [CodeQuality] Fix default array param in CallableThisArrayToAnonymousFunctionRector (#2527)
    • [Transform] Handle with this->method() from current class on MethodCallToMethodCallRector (#2531)
    • [PHP 7.0] skip non-existing method in StaticCallOnNonStaticToInstanceCallRector (#2532)
    • [PHP 7.4] Skip default expr type on property, if there is mixed assign (#2534)
    • [Php56] Skip multiple catch with same variable on AddDefaultValueForUndefinedVariableRector (#2533)
    • [Php80] Skip Assign on its var not directly used in next return on ChangeSwitchToMatchRector (#2535), #7247
    • [Php81] Skip str_replace() pass array subject on NullToStrictStringFuncCallArgRector (#2541)
    Source code(tar.gz)
    Source code(zip)
  • 0.13.5(Jun 9, 2022)

    New Features :tada:

    • [DeadCode] Add RemoveJustPropertyFetchRector (#2433)
    • [DX] Make ClassAnnotationMatcher differentiate between known and unknown classes (#2319), Thanks @dritter!
    • [CS] Fix dynamic and broken indent detection, allow to configure spacing via RectorConfig::indent() method (#2442)
    • [DX] Add deprecation exception about old ContainerConfigurator, to prepare for removal even in CI (#2463)
    • use PHPStan 1.7.12, with phpdoc-parser 1.6.0 to fix endline issue (https://github.com/rectorphp/rector-src/commit/56651d0190ca04cdf0c33484d359ae197b455a15)
    • [DX] Detach typo3 from core to allow stable growth of both packages (#2446)
    • [scoped] Build with Scoper 0.17.2 (#2445)

    Bugfixes :bug:

    • [DX] Remove too detailed --type in init command, use fw documentation instead (#2430)
    • [Renaming] Keep comment on RenameClassRector (#2439)
    • [Renaming] Do not Rename Docblock inner Namespace on RenameClassRector (#2441)
    • [Renaming] Handle crash on FuncCall with Arg class name conflict with use statement or namespace on RenameClassRector with auto import enabled (#2431)
    • [DX] Remove symlinks option to require safe way of providing explicit paths (#2443)
    • [Php74] Remove ReservedFnFunctionRector (#2447)
    • [Renaming] Skip rename docblock on conflict with alias on RenameClassRector (#2450)
    • [DeadCode][PHPUnit] handle crash on RemoveJustPropertyFetchForAssignRector+SimplifyForeachInstanceOfRector (#2453)
    • [CodingStyle] Skip non-empty-string on VarConstantCommentRector (#2451)
    • [Renaming] Do not rename class with same name inside different namespace on RenameClassRector (#2455)
    • [Php72] Handle crash on PreInc usage on CreateFunctionToAnonymousFunctionRector (#2456)
    • [Php70] Handle crash on EregToPregMatchRector (#2460)
    Source code(tar.gz)
    Source code(zip)
  • 0.13.4(Jun 4, 2022)

    New Features :tada:

    • Update to php-parser 4.14.0 to work with literal _ number separator (#2321)
    • Update to PHPStan 1.7.10 (#2424)
    • [DowngradePhp82] Add DowngradeReadonlyClassRector to downgrade readonly class (#2322)
    • [PHP 8.0] Add ConstantListClassToEnumRector (#2404)
    • [DowngradePhp80] Add DowngradeEnumToConstantListClassRector (#2416)
    • [DeadCode] Add RemoveJustPropertyFetchForAssignRector (#2423)

    Bugfixes :bug:

    • [PHP 8.0] Fix double annotation change on annotation to attribute (#2403)
    • [Attribute] Fix UseAliasNameMatcher for the last part of use import rename (#2402)
    • [Core] Fix bootstrap stubs load on PHP 7.2 when vendor/ excluded via skip() (#2394)
    • [Php74] Skip nullable mixed on Php 8.0 feature enabled on TypedPropertyRector (#2414)
    • [Php80] Mirror additional docblock on importNames() on ClassPropertyAssignToConstructorPromotionRector (#2410)
    • [Renaming] Skip docblock rename different namespace on RenameClassRector (#2419)
    Source code(tar.gz)
    Source code(zip)
  • 0.13.3(May 31, 2022)

    Rector release downgrade is now handled in single run and with parallel run :zap: It's faster and vendor includes only the packages it really uses.


    New Features :tada:

    • [Laravel] Add set for Laravel 9.x (#49), Thanks @hirenkeraliya
    • [Attribures] Add annotation to attribute core rename in AnnotationToAttributeRector (#2384)

    This now allows annotation to attribute rename with change in the namespace:

    -use Project\Annotation\Security as SC;
    +use Project\Attribute\Security as SC;
    
    -/**
    - * @SC\LoggedIn
    - */
    +#[SC\LoggedIn]
    final class PrivateController
    {
    }
    

    Bugfixes :bug:

    • [Transform] Skip different method on CallableInMethodCallToVariableRector (#2395)
    • [CodeQuality] Add empty array support to InlineArrayReturnAssignRector (#2397)
    • [PHP 8.2] Skip readonly class on property without type in ReadOnlyClassRector (#2398)
    • Add annotation to attribute core rename in AnnotationToAttributeRector (#2380)
    • [DowngradePhp81] Handle crash parent Arg is missing scope on DowngradeFirstClassCallableSyntaxRector (#2387)

    Changes :calendar:

    • remove working-dir option as not compatible with parallel run, better handle via CI working-dir options (#2387)
    Source code(tar.gz)
    Source code(zip)
  • 0.13.2(May 27, 2022)

  • 0.13.1(May 27, 2022)

    New Features :tada:

    • [CodeQuality] Add InlineIsAInstanceOfRector (#2364)
    • [DX] Move configure to direct call in RectorConfig (#2367)
    • [DX] Various config merge, improve RectorConfig methods (#2371)
    • [DX] Remove non-PHP file formatting based on editorconfig, rather let external coding standard tools handle the file format (#2378)

    Bugfixes :bug:

    • [Php73] Skip Encapsed on StringifyStrNeedlesRector (#2352), Thanks @samsonasik!
    • [TypeDeclaration] Skip curly {@inheritdoc} on AddArrayReturnDocTypeRector (#2359), Thanks @samsonasik!
    • Allow to rename method if in interface (#2362)
    • [Php81] Skip ArrayDimFetch from ArrayObject in Assign var on ReadOnlyPropertyRector (#2363), Thanks @samsonasik!
    • [PhpDocInfo] Fixes Partial value update got duplicated on DoctrineAnnotationTagValueNode change (#1862), Thanks @samsonasik!
    Source code(tar.gz)
    Source code(zip)
  • 0.13.0(May 23, 2022)

    New Features :tada:

    • [Php82] Add ReadOnlyClassRector (#2296), Thanks @samsonasik!
    • [Order] Add a-z ordering feature to OrderAttributesRector (#2243), Thanks @Lenny4!
    • [Symfony] Add CommandPropertyToAttributeRector (#163), Thanks @stephanvierkant
    • [Experimental] Add refactorWithScope() method to get typed Scope easily and required (#2227)
    • Add Scope refresh for changed or new nodes (#2292)

    From YAML routes to Annotations :rocket:

    • [Symfony] Add new rule to add annotations from router configuration to symfony controllers (#169), Thanks @malteschlueter
    -foo_baz:
    -    path: /foo/{baz}
    -    defaults: { _controller: FooBundle:Bar:baz, _format: json }
    -    methods: [ GET, POST ]
    
    +/**
    + * @Route(name="foo_baz", path="/foo/{baz}", methods={"GET","POST"}, defaults={_format="json"})
    + */
     public function bazAction(string $baz)
    

    New StmtsAwareInterface node

    • [DX] Add StmtsAwareInterface to catch node by type (#2269)

    Do you need to iterface all rules with stmts in them? Hook in one node type:

       /**
         * @return array<class-string<Node>>
         */
        public function getNodeTypes(): array
        {
            return [StmtsAwareInterface::class];
        }
    

    Bugfixes :bug:

    • [CodeQuality] Skip CallableThisArrayToAnonymousFunctionRector when inside of Attribute (#2212), #6910, Thanks @samsonasik!
    • Added new functions to NullToStrictStringFuncCallArgRector (#2217), Thanks @FlorinProfeanu!
    • [Parallel] Fix --debug not working in parallel (#2307), Thanks @samsonasik!
    • [DowngradePhp80] Handle match inside ArrowFunction on DowngradeMatchToSwitchRector (#2330), Thanks @samsonasik!
    • [DowngradePhp80] Add in arrow function in return support on DowngradeMatchToSwitchRector (#2331), Thanks @samsonasik!
    • [DowngradePhp80] Apply PHPStan 1.7.x-dev compatible for PhpParameterReflection (#2336), Thanks @samsonasik!
    • [DeadCode] Skip used in Closure use on RemoveUnusedConstructorParamRector (#2341), Thanks @samsonasik!
    • [Naming] Move collecting param names method to FunctionLikeManipulator (#2347), Thanks @samsonasik!
    • [Naming] Handle Grouped use import on UseImportsResolver (#2348), Thanks @samsonasik!
    Source code(tar.gz)
    Source code(zip)
  • 0.12.23(May 1, 2022)

    This release fixes major slowdown on find parents node rules in stmts: https://github.com/rectorphp/rector/issues/7144, thanks for report and provided detailed info @bobvandevijver and @jrmcpeek :bow:

    Update as soon as possible to enjoy the speed again :+1:

    • [Code] Improve BetterNodeFinder::findFirstPrevious() to only locate previous of parent if no previous of Node (#2209), Thanks @samsonasik!

    New Features :tada:

    • [CodeQuality] Add InlineArrayReturnAssignRector (#2183)
    • Add RectorConfigProvider to ask for configuration behave for 3rd party packages (#2187)
    • [Core] Add $seconds, $maxNumberOfProcess, and $jobSize parameters to RectorConfig::parallel() method (#2188), Thanks @samsonasik!
    • [DX] Move PhpVersionProvider from AbstractRector to particular services (#2189)
    • [DowngradePhp80] Support match as array item in DowngradeMatchToSwitchRector (#2178), Thanks @jrstanley!

    Bugfixes 🐛

    • [DeadCode] Improve RemoveUnreachableStatementRector performance by return after array_splice early (#2193), Thanks @samsonasik!
    • [DeadCode] Register array_splice into impure functions on PureFunctionDetector (#2194), Thanks @samsonasik!
    • [CodingStyle] Skip readonly type property on AddArrayDefaultToArrayPropertyRector (#2196), Thanks @samsonasik!
    • [DeadCode] Remove RemoveCodeAfterReturnRector, already handled at RemoveUnreachableStatementRector (#2199), Thanks @samsonasik!
    Source code(tar.gz)
    Source code(zip)
  • 0.12.22(Apr 28, 2022)

    This release slowly moves towards RectorConfig to improve Rector isolation from your project and ease to configuration. You can read more about it here: https://getrector.org/blog/new-in-rector-012-introducing-rector-config-with-autocomplete

    New Features :tada:

    • [DX] Update super old configure to RectorConfig (#2121)
    • [DX] Add RectorConfig upgrade rule to make upgrade easier :) (#2098)
    • Improve BetterNodeFinder::findFirstPrevious() to work without statements (#2136)
    • Invalidate errored files in cache, to avoid hiding errors (#2138)
    • [NodeCollector] Remove CurrentStmtResolver service (#2143), Thanks @samsonasik!
    • [DX] Add note warning about using old config (#2177), Thanks @dritter!
    • DowngradeMatchToSwitchRector adds Method and Function call support (#2173), Thanks @jrstanley!

    Bugfixes 🐛

    • [Fix][InlineSimplePropertyAnnotationRector] Add test case and minor fix (#2096), Thanks @dorrogeray!
    • [TypeDeclaration] Skip union param type on AddArrayParamDocTypeRector (#2119), Thanks @samsonasik!
    • [TypeDeclaration] Skip return property not exists by ClassReflection on ReturnTypeDeclarationRector (#2134), Thanks @samsonasik!
    • [Php80] Handle named type on JMS\AccessType on AnnotationToAttributeRector (#2141), Thanks @samsonasik!
    • [DeadCode] Skip remove variable on switch use return after break on RemoveUnusedVariableAssignRector (#2145), Thanks @samsonasik!
    • [Php80] Skip different type cases cond on ChangeSwitchToMatchRector (#2147), Thanks @samsonasik!
    • Remove PREVIOUS_STATEMENT from StatementNodeVisitor (#2146)
    • Remove CURRENT_STATEMENT where not needed (#2149)
    • [Php74] Allow change protected property of final class when property only in current class on TypedPropertyRector (#2153), Thanks @samsonasik!
    • Remove uses nodes attribute - part #1 (#2155)
    • Disable StatementNodeVisitor (#2154)
    • Remove NamespaceNodeVisitor (#2167)
    • Decouple aliased object type specifier + updgrade to PHPStan 1.6 (#2170)
    • [DowngradePhp80] Add Static Call Support on DowngradeMatchToSwitchRector (#2175), Thanks @samsonasik!
    • Adds test for DowngradeMatchToSwitchRector match having true subject expression (#2176), Thanks @jrstanley!
    • [TypeDeclaration] Skip return type defined Closure on ReturnTypeDeclarationRector (#2179), Thanks @samsonasik!
    • [Doc] Document deprecated USE_NODES and CURRENT_STATEMENT constant to use existing method call when needed (#2181), Thanks @samsonasik!
    • [Doctrine][Nette][TypeDeclaration] Handle add __construct with no Scope on InitializeDefaultEntityCollectionRector+RenderMethodParamToTypeDeclarationRector (#2180), Thanks @samsonasik!
    Source code(tar.gz)
    Source code(zip)
  • 0.12.21(Apr 18, 2022)

    New RectorConfig to configure your rector.php Without Effort!

    • Add RectorConfig for custom configuration methods (#2019) (#2063)

    Before

    use Rector\Core\Configuration\Option;
    use Rector\Php74\Rector\Property\TypedPropertyRector;
    use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
    
    return static function (ContainerConfigurator $containerConfigurator): void {
        $parameters = $containerConfigurator->parameters();
        $parameters->set(Option::PARALLEL, true);
        $parameters->set(Option::AUTO_IMPORT_NAMES, true);
       
        $services = $containerConfigurator->services();
        $services->set(TypedPropertyRector::class);
    };
    

    Now

    use Rector\Php74\Rector\Property\TypedPropertyRector;
    use Rector\Config\RectorConfig;
    
    return static function (RectorConfig $rectorConfig): void {
        $rectorConfig->parallel();
        $rectorConfig->importNames();
     
        $rectorConfig->rule(TypedPropertyRector::class);
    };
    

    New Features :tada:

    • Add new rule to add explicit public scope to unscoped class methods (#2022), Thanks @Firehed!
    • [Transform] Add FileGetContentsAndJsonDecodeToStaticCallRector (#2059)
    • Add VarAnnotationIncorrectNullableRector for fixing incorrect null type in @var (#2053), Thanks @dorrogeray!
    • Add ReturnAnnotationIncorrectNullableRector for fixing incorrect null type in @return (#2060), Thanks @dorrogeray!
    • [TypeDeclaration] Make TypedPropertyFromAssignsRector configurable with INLINE_PUBLIC (#2052), Thanks @samsonasik!
    • Add ParamAnnotationIncorrectNullableRector for fixing incorrect null type in @param (#2069), Thanks @dorrogeray!
    • Add configurable InlineSimplePropertyAnnotationRector for inlining of simple annotations (#2070), Thanks @dorrogeray!
    • [Php74] Handle standalone false on php >=8 feature enabled on TypedPropertyRector (#2084), Thanks @samsonasik!

    Bugfixes 🐛

    • [Strict] Skip ArrayDimFetch on DisallowedEmptyRuleFixerRector (#2023), Thanks @samsonasik!
    • [TypeDeclaration] Skip default type value different with type assigned (#2027), Thanks @samsonasik!
    • [Php74] Skip array var type filled default null in __construct on TypedPropertyRector (#2029), Thanks @samsonasik!
    • [Php74] Skip by ref used by inner Closure use on ClosureToArrowFunctionRector (#2031), Thanks @samsonasik!
    • [Naming] Add Closure and Function_ on RenameParamToMatchTypeRector (#2042), Thanks @samsonasik!
    • [Php56] Skip with coalesce assign on AddDefaultValueForUndefinedVariableRector (#2078), Thanks @samsonasik!
    • [Php81] Skip multiple assign on __construct on ReadOnlyPropertyRector (#2088), Thanks @samsonasik!

    Changes :bar_chart:

    • [DX] Replace global BetterStandardPrinter from AbstractRector with autowired NodePrinterInterface for easier and specific re-use (#2036)
    • Move RemovedAndAddedFilesCollector, ParameterProvider from AbstractRector to rules that actually use it (#2038)
    • [DX] Remove deprecated attributes (#2039)
    • Merge SimplifyDuplicatedTernaryRector to UnnecessaryTernaryExpressionRector, almost identical rule (#2046)
    • Merge InArrayAndArrayKeysToArrayKeyExistsRector to ArrayKeysAndInArrayToArrayKeyExistsRector with almost identical behavior (#2047)
    • Merge FollowRequireByDirRector to almost identical AbsolutizeRequireAndIncludePathRector (#2048)
    • [build] fix tagging on release (https://github.com/rectorphp/rector-src/commit/451964615066aabcced75e66e4af9f13be5b5f7b)
    Source code(tar.gz)
    Source code(zip)
  • 0.12.20(Apr 6, 2022)

    • Bump min to PHP 7.2 (#1955) - following PHPStan 1.5 bump, PHP 7.1 usage of Rector is only ~0.2 %

    New Features :tada:

    • [DX] Remove different php version rector reporting to make run more clean (#1959)
    • Re-use NeighbourClassLikePrinter (#1957)
    • [Php74] Add GetCalledClassToSelfClassRector (#1971), Thanks @samsonasik!
    • [Php55] Move GetCalledClassToSelfClassRector + GetCalledClassToStaticClassRector from php 7.4 to 5.5 SetList (#1972), Thanks @samsonasik!
    • [DowngradePhp81] Add DowngradeArrayIsListRector (#1996), Thanks @samsonasik!
    • [DowngradePhp54] Add DowngradeThisInClosureRector (#1995), Thanks @samsonasik!
    • [Removing] Add RemoveNamespaceRector (#2013), #7093, Thanks @samsonasik!

    Bugfixes 🐛

    • Fix bug with handling bad symlinks (#1938), Thanks @inderpreet99!
    • Fix stub PHPUnit\Framework\TestCase (#1960), Thanks @samsonasik!
    • [TypeDeclaration] Skip ArrayShapeFromConstantArrayReturnRector on key has colon (#1962), Thanks @samsonasik!
    • [TypeDeclaration] Skip key has bracket {}[] on ArrayShapeFromConstantArrayReturnRector (#1968), Thanks @samsonasik!
    • [CodeQuality] Handle not identical return false then true on SimplifyIfReturnBoolRector (#1969), Thanks @samsonasik!
    • [Php81] Skip anonymous class on FinalizePublicClassConstantRector (#1970), Thanks @samsonasik!
    • Handle annotation import with enable AUTO_IMPORT_NAMES not changed (for non-namespaced file) (#1973), Thanks @samsonasik!
    • [CodeQuality] Handle Param by reference in target method on CallableThisArrayToAnonymousFunctionRector (#1974), Thanks @samsonasik!
    • [TypeDeclaration] Skip return inside array_map on ArrayShapeFromConstantArrayReturnRector (#1977), #7079, Thanks @samsonasik!
    • [Privatization] Skip parent static property used by parent method on PrivatizeFinalClassPropertyRector (#1978), Thanks @samsonasik!
    • [Php80] Skip empty default on ChangeSwitchToMatchRector (#1980), Thanks @samsonasik!
    • [TypeDeclaration] Fix AddMethodCallBasedStrictParamTypeRector for offset type (#1982)
    • Fix AddClosureReturnTypeRector for union types of mutually related classes (#1984), Thanks @samsonasik!
    • [CodingStyle] Skip AddFalseDefaultToBoolPropertyRector on assigned in __construct (#1998), Thanks @samsonasik!
    • [TypeDeclaration] Handle default value on not inlined assignment in __construct on TypedPropertyFromStrictConstructorRector (#2008), Thanks @samsonasik!
    • [TypeDeclaration] Handle multiple methods define __construct later on TypedPropertyFromStrictConstructorRector (#2009), Thanks @samsonasik!
    • [TypeDeclaration] Skip __construct in inner class on TypedPropertyFromStrictConstructorRector (#2010), Thanks @samsonasik!
    • [PHPStan] Fix PHPStan notice on ParallelFileProcessor (#2011), Thanks @samsonasik!
    Source code(tar.gz)
    Source code(zip)
  • 0.12.19(Mar 23, 2022)

    New Features :tada:

    • [DX] simplify --debug output to the proccessed file path (#1933)
    • [Php80] Handle return match no default on ChangeSwitchToMatchRector (#1949), Thanks @samsonasik!
    • [Php80] Handle init in before else on ChangeSwitchToMatchRector (#1952), Thanks @samsonasik!

    Bugfixes 🐛

    • [Php81] Skip has unset property fetch on ReadOnlyPropertyRector (#1954), Thanks @samsonasik!
    • Fix stub PHPUnit\Framework\TestCase (#1954), Thanks @samsonasik!
    • [TypeDeclaration] Avoid adding param type in case of different default type (#1956)
    Source code(tar.gz)
    Source code(zip)
  • 0.12.18(Mar 20, 2022)

    New Features :tada:

    • [TypeDeclaration] Add ArrayShapeFromConstantArrayReturnRector (#1908)
    • [Transform] Add type matching to MethodCallToPropertyFetchRector (#1905)
    • [Arguments] Add RemoveMethodCallParamRector (#1906)
    • [CodeQuality] Add InlineConstructorDefaultToPropertyRector (#1935)
    • Add StaticCall support to RemoveMethodCallParamRector (#1916)
    • [DX] simplify --debug output to the proccessed file path (#1933)

    Bugfixes 🐛

    • [CodeQuality] Handle default value on CallableThisArrayToAnonymousFunctionRector (#1900), Thanks @samsonasik!
    • [TypeDeclaration] Skip ArrayShapeFromConstantArrayReturnRector on class name as key (#1911), Thanks @samsonasik!
    • [Php81] Skip override __construct from interface on NewInInitializerRector (#1913), Thanks @samsonasik!
    • [Arguments] Handle by pass 2nd argument default value on ArgumentAdderRector (#1946), Thanks @samsonasik!
    • [DeadCode] Handle used in anonymous class on RemoveUnusedConstructorParamRector (#1948), Thanks @samsonasik!
    • [Transform] Handle property exists via Property Promotion on NewToMethodCallRector (#1915), Thanks @samsonasik!
    • [Renaming] Apply rename fully qualified namespace docblock on RenameNamespaceRector (#1917), Thanks @samsonasik!
    • [CodingStyle] Handle Interface suffix on CatchExceptionNameMatchingTypeRector (#1918), Thanks @samsonasik!
    • [CodingStyle] Use alias name when exists on CatchExceptionNameMatchingTypeRector (#1920), Thanks @samsonasik!
    • Fix some minor misprints (#1922), Thanks @bocharsky-bw!
    • [Dep] Add PHPUnit\Framework\TestCase stub on target-repository bootstrap.php (#1924), Thanks @samsonasik!
    • [TypeDeclaration] Fix parent method param override (#1945)
    • [DeadCode][CodingStyle] Handle SplitDoubleAssignRector+RemoveUnusedPrivatePropertyRector (#1944), Thanks @samsonasik!
    • [Php81] Skip static property on ReadOnlyPropertyRector (#1939), Thanks @samsonasik!
    • [PHP 8.0] Fix skip of silent key in annotation to attribute (#1932)

    Deprecations ⌛️

    • [MockeryToProphecy] Deprecate micro set as not practical (#1899)
    • [PhpSpecToPHPUnit] Deprecate historical set, mostly for experimental in early days (#1901)
    • Remove old PHPSpec 3 and 4 sets (#1902)
    • [Order] Deprecate rather coding standard related set, use OrderedClassElementsFixer instead (#1910)
    • [Transform] Remove AddInterfaceByParentRector as never used (#1935)
    • [DeadCode] Skip called by current classname on RemoveUnusedPrivateClassConstantRector (#1931), Thanks @samsonasik!
    Source code(tar.gz)
    Source code(zip)
  • 0.12.17(Mar 3, 2022)

    New Features :tada:

    • [DX] Make progress bar less verbose on CI (#1797), #6996
    • Remove min php version from OptionalParametersAfterRequiredRector (#1814), Thanks @leighman!
    • [CodeQuality] Extend SimplifyForeachToArrayFilterRector with compare cond (#1820)
    • Add Projects using Rector section to README.md (#1881), Thanks @Wirone!

    Bugfixes 🐛

    • [Php74] Skip mixed type on TypedPropertyRector on auto import enabled (#1798), Thanks @connerbw!
    • [Php74] Handle Multiple types with NullType on TypedPropertyRector when PHP 8.0 Feature enabled (#1803), Thanks @samsonasik!
    • [Php74] Skip null|false type on TypedPropertyRector on php 8.0 feature enabled (#1804), Thanks @samsonasik!
    • [TypeDeclaration] Use @return type on Generator on ReturnTypeDeclarationRector (#1794), Thanks @samsonasik!
    • [Php74] Skip variable FuncCall $fn() on ReservedFnFunctionRector (#1815), Thanks @samsonasik!
    • [TypeDeclaration] Skip @inheritdoc on PropertyTypeDeclaration (#1752), Thanks @oprypkhantc!
    • [Php81] Skip used as ArrayDimFetch on Arg on side effect FuncCall on ReadOnlyPropertyRector (#1822), Thanks @samsonasik!
    • Skip removing Psalm PhpDocTagNode (#1829), Thanks @rajyan!
    • Fix annotation to attribute rector with doctrine table and nested uniqueConstraints option (#1850), Thanks @acrobat!
    • [Php81] Add ConstFetch and ClassConstFetch arg support on NewInInitializerRector (#1848), Thanks @samsonasik!
    • Do not prepend a \ to the type, if it is already Fully Qualified (#1863), Thanks @mkrauser!
    • [Core] Fixing applied rules not shown when refactor() only change docblock (#1861), Thanks @samsonasik!
    • [DowngradePhp72] Handle in assign on DowngradePregUnmatchedAsNullConstantRector (#1872), Thanks @samsonasik!

    Changes ⚙️

    • Remove deprecated show command (#1796)
    • [DX] Deprecate disabling of import options to keep configuration simpler (#1817)
    • [DX] Inline PARALLEL_SYSTEM_ERROR_COUNT_LIMIT option to keep user scope outside internal system (#1818)
    • Deprecate RemovingStatic rules as very narrow use case in generic rules (#1819)
    • [DX] Remove GenericClassMethodParamRector, rather PHPStorm one-time refactoring job (#1830)
    • [DX] Remove SingleToManyMethodRector, rather one time job useful for PHPStorm (#1831)
    • [DX] Remove MoveValueObjectsToValueObjectDirectoryRector, should be handled by PHPStorm refactoring and PHPStan rule checks (#1832)
    • [DX] Remove deprecated constants (#1833)
    • [DX] Remove MoveServicesBySuffixToDirectoryRector, better handle by PHPStan + PHPStorm refacor (#1834)
    • [DX] Remove MoveInterfacesToContractNamespaceDirectoryRector as breaky, use PHPStan rule instead (#1835)
    • [DX] Remove MoveEntitiesToEntityDirectoryRector, use PHPStan rule + PhpStorm refactoring instead (#1836)
    Source code(tar.gz)
    Source code(zip)
A command line refactoring tool for PHP

PHP Refactoring Browser Note: This software is under development and in alpha state. Refactorings do not contain all necessary pre-conditions and migh

QafooLabs 562 Dec 30, 2022
Rector upgrades rules for CakePHP

Rector Rules for CakePHP See available CakePHP rules Install composer require rector/rector-cakephp Use Sets To add a set to your config, use Rector\C

RectorPHP 19 Oct 27, 2022
Rector upgrades rules for Nette

Rector Rules for Nette See available Nette rules Install composer require rector/rector-nette Use Sets To add a set to your config, use Rector\Nette\S

RectorPHP 21 Nov 7, 2022
Rector upgrades rules for Symfony Framework

Rector Rules for Symfony See available Symfony rules Install This package is already part of rector/rector package, so it works out of the box. All yo

Rector 107 Dec 31, 2022
Rector upgrades rules for Laravel

Rector Rules for Laravel See available Laravel rules Install This package is already part of rector/rector package, so it works out of the box. All yo

Rector 185 Dec 30, 2022
A full-scale PHP sandbox class that utilizes PHP-Parser to prevent sandboxed code from running unsafe code

A full-scale PHP 7.4+ sandbox class that utilizes PHP-Parser to prevent sandboxed code from running unsafe code. It also utilizes FunctionParser to di

Corveda 192 Dec 10, 2022
A full-scale PHP 5.3.2+ sandbox class that utilizes PHPParser to prevent sandboxed code from running unsafe code.

##DEPRECATED: The PHPSandbox project has transfered to Corveda/PHPSandbox and will be actively maintained there. This branch is no longer being active

Elijah Horton 219 Sep 2, 2022
Library for counting the lines of code in PHP source code

sebastian/lines-of-code Library for counting the lines of code in PHP source code. Installation You can add this library as a local, per-project depen

Sebastian Bergmann 715 Jan 5, 2023
Search PHP source code for function & method calls, variables, and more from PHP.

Searching PHP source code made easy Search PHP source code for function & method calls, variable assignments, classes and more directly from PHP. Inst

Permafrost Software 22 Nov 24, 2022
Deptrac is a static code analysis tool for PHP that helps you communicate, visualize and enforce architectural decisions in your projects

Deptrac is a static code analysis tool for PHP that helps you communicate, visualize and enforce architectural decisions in your projects. You can freely define your architectural layers over classes and which rules should apply to them.

QOSSMIC GmbH 2.2k Dec 30, 2022
phpcs-security-audit is a set of PHP_CodeSniffer rules that finds vulnerabilities and weaknesses related to security in PHP code

phpcs-security-audit v3 About phpcs-security-audit is a set of PHP_CodeSniffer rules that finds vulnerabilities and weaknesses related to security in

Floe design + technologies 655 Jan 3, 2023
Provides functionality that helps writing PHP code that has runtime-specific (PHP / HHVM) execution paths

sebastian/environment This component provides functionality that helps writing PHP code that has runtime-specific (PHP / HHVM) execution paths. Instal

Sebastian Bergmann 6.5k Jan 3, 2023
PHP Static Analysis Tool - discover bugs in your code without running it!

PHPStan - PHP Static Analysis Tool PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even b

PHPStan 11.6k Dec 30, 2022
A PHP code-quality tool

GrumPHP Sick and tired of defending code quality over and over again? GrumPHP will do it for you! This composer plugin will register some git hooks in

PHPro 3.9k Jan 1, 2023
Copy/Paste Detector (CPD) for PHP code.

PHP Copy/Paste Detector (PHPCPD) phpcpd is a Copy/Paste Detector (CPD) for PHP code. Installation This tool is distributed as a PHP Archive (PHAR): $

Sebastian Bergmann 2.2k Jan 1, 2023
Analyze PHP code with one command

PHPQA Analyze PHP code with one command. Requirements PHP >= 5.4.0 xsl extension for HTML reports Why? Every analyzer has different arguments and opti

edgedesign/phpqa 542 Dec 24, 2022
Performs advanced static analysis on PHP code

PHP Analyzer Please report bugs or feature requests via our website support system ? in bottom right or by emailing [email protected]. Contri

Continuous Inspection 443 Sep 23, 2022
A static php code analysis tool using the Graph Theory

Mondrian Ok guyz, you have a master degree in Graph Theory, you follow Law of Demeter and you live on S.O.L.I.D principles ? Let's have some Fun ! (^ω

Florent Genette 391 Nov 30, 2022
A tool to automatically fix PHP Coding Standards issues by Dragon Code.

A tool to automatically fix PHP Coding Standards issues by Dragon Code.

The Dragon Code 24 Aug 27, 2022