Rector - Instant Upgrades and Automated Refactoring

Overview

Rector - Instant Upgrades and Automated Refactoring

Downloads


This repository (rectorphp/rector-src) is for development Rector only. Head to rectorphp/rector for documentation, install or creating an issue.


Building rectorphp/rector

Code of this repository requires PHP 8. For rector/rector package user the build downgrades code to PHP 7.1 and higher.

How to Contribute

Please read contributing guideline for how to contribute to rector.

Code of Conduct

This project adheres to a Contributor Code of Conduct By participating in this project and its community, you are expected to uphold this code.

Comments
  • [Core] Handle parent return/assign from FuncCall with No Scope

    [Core] Handle parent return/assign from FuncCall with No Scope

    Continue of https://github.com/rectorphp/rector-src/pull/2523, given the following code:

    trait ServiceLocatorTrait
    {
        private array $factories;
        private array $loading = [];
        private array $providedTypes;
    
        public function get(string $id): mixed
        {
            if (!isset($this->factories[$id])) {
                throw $this->createNotFoundException($id);
            }
    
            $this->loading[$id] = $id;
            try {
                return $this->factories[$id]($this);
            } finally {
                unset($this->loading[$id]);
            }
        }
    }
    

    cause error:

    php ../e2eTestRunner.php
     1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%[ERROR] Could not process "src/ServiceLocatorTrait.php" file, due to:
             "System error: "Scope not available on "PhpParser\Node\Expr\FuncCall" node with parent node of
             "PhpParser\Node\Stmt\Return_", but is required by a refactorWithScope() method of
             "Rector\DowngradePhp81\Rector\FuncCall\DowngradeArrayIsListRector" rule. Fix scope refresh on changed nodes
             first"
             Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new". On
             line: 43%    
    
    opened by samsonasik 28
  • introduce PlatformAgnosticAssertions trait which handles cross platform issues - adds windows CI coverage

    introduce PlatformAgnosticAssertions trait which handles cross platform issues - adds windows CI coverage

    As discussed in https://github.com/rectorphp/rector-src/pull/115#discussion_r640952613 this PR introduced a way which allows to turn assertSame assertions to ignore PHP_EOL differences.

    Since I don't like overriding the very fundatmental behaviour across the entire code-base I figured using a simple Trait could be used in Testclasses as an opt-in to a newline normalized assertSame (later maybe more assertion methods).

    Adding a trait is very easy and does not require changes in the inheritance hierarchy of the classes which already exist. existing tests currently extend from PHPUnit\Framework\TestCase, some from Rector\Testing\PHPUnit\AbstractTestCase, and some from Rector\Testing\PHPUnit\AbstractRectorTestCase

    closes https://github.com/rectorphp/rector-src/pull/115 https://github.com/rectorphp/rector-src/pull/117 https://github.com/rectorphp/rector-src/pull/99

    opened by staabm 23
  • Added test for Rectors making additional changes

    Added test for Rectors making additional changes

    Based on PR https://github.com/rectorphp/rector-nette/pull/26 and https://github.com/rectorphp/rector-nette/pull/23 I've created this generic way how to test Rectors which create / update also another files.

    Usage:

    Rector:

    Add file with content:

    $addedFileWithContent = new AddedFileWithContent($templateFilePath, $content);
    $this->removedAndAddedFilesCollector->addAddedFile($addedFileWithContent);
    

    Test fixtures

    Fixtures contains more parts separated by ----- like in previous tests:

    1) original content
    -----
    2) expected content (keep empty if no change should happen)
    -----
    3) path to another changed file (relative to file processed)
    -----
    4) original content of another file (keep empty if file doesn't exist yet)
    -----
    5) expected content of another file
    

    3-5 can be multiplied in case there are more files created / updated

    Fixture example

    <?php
    
    namespace Rector\Nette\Tests\Rector\Class_\LatteVarTypesBasedOnPresenterTemplateParametersRector\Fixture;
    
    use Nette\Application\UI\Presenter;
    
    class SomePresenter extends Presenter
    {
        public function renderDefault(): void
        {
            $this->template->title = 'My title';
            $this->template->count = 123;
        }
    }
    
    ?>
    -----
    -----
    templates/Some/default.latte
    -----
    <h1>{$title}</h1>
    <span class="count">{$count}</span>
    -----
    {varType string $title}
    {varType int $count}
    
    <h1>{$title}</h1>
    <span class="count">{$count}</span>
    

    RectorTest

    In RectorTest just use

    $this->doTestFileInfoWithAdditionalChanges($fileInfo);
    

    instead of

    $this->doTestFileInfo($fileInfo);
    
    opened by lulco 20
  • [PHP 8.2] Add rule for AllowDynamicProperties attribute

    [PHP 8.2] Add rule for AllowDynamicProperties attribute

    This rector rule accounts for the proposed RFC to deprecate implicit dynamic properties in PHP 8.2. Per discussion on twitter this rule would add the new #[AllowDynamicProperties] attribute to every class - unless it already has this attribute applied.

    opened by mallardduck 19
  • Fix performance issue

    Fix performance issue

    I faced with performance issue on my project. When I run rector process on big number of files it takes a lot of time. I profiled this command and found that NodeScopeResolver is decorated on each node processing. As result there is a huge staketrace: Screenshot_1

    I moved decoration to constructor to do it once and it boost performance a lot.

    opened by ossinkine 18
  • AddReturnTypeDeclarationBasedOnParentClassMethodRector

    AddReturnTypeDeclarationBasedOnParentClassMethodRector

    First draft that adds return type only by first parent/interface found with that method. In future I will try to change it to detect correct intersection type that will satisfy all parents/interfaces.

    It is heavily based on AddReturnTypeDeclaration and AddParamBasedOnParentClassMethodRector.

    There were some duplicated code with existing rule so I moved it to service but not sure if it is correct place. Structure of services used in rules is quite confusing to me - is there any design guide for that?

    I think this roule could also be added to some existing sets but not sure to which. It is quite universal rule that detects issues that would cause Fatal error.

    Tests included and after PR #2660 by @samsonasik it works perfectly with interfaces too.

    @TomasVotruba Let me know if you want something solved differently.

    opened by MartinMystikJonas 18
  • [DeadCode] Skip using coealesce assign operator on return on RemoveUnusedPrivatePropertyRector

    [DeadCode] Skip using coealesce assign operator on return on RemoveUnusedPrivatePropertyRector

    The following code should be skipped:

    final class SkipUsingCoalesceAssignOperator
    {
        private SomeService $someService;
    
        private array $types = [];
    
        public function __construct(SomeService $someService)
        {
            $this->someService = $someService;
        }
    
        public function get(string $key)
        {
            return $this->types[$key] ??= $this->someService->resolve();
        }
    }
    
    opened by samsonasik 17
  • Rollback stubs-rector tweak and remove e2e/define-constant

    Rollback stubs-rector tweak and remove e2e/define-constant

    @TomasVotruba it seems the error is only happen on Github action on php 7.2. This rollback the tweak and remove the e2e/define-constant, The e2e/define-constant was exists to verify RichParser which it working ok now, so I think it is safe to be removed.

    opened by samsonasik 17
  • Sync FileCacheStorage with changes from phpstan-src

    Sync FileCacheStorage with changes from phpstan-src

    as can be seen in https://github.com/rectorphp/rector-src/pull/461#issuecomment-885617373 the FileCacheStorage is a major bottleneck while running tests on windows - I guess the same is true on other OSes.

    This PR removes unnecessary temp-file handling, because smartFileSystem->dumpFile is already a atomic operation which does magic temp-path file handling behind the scenes. therefore we don't need to do the same things on the rector side.

    opened by staabm 16
  • [Core] Remove RectifiedNode value object for RectifiedAnalyzer

    [Core] Remove RectifiedNode value object for RectifiedAnalyzer

    With consecutive last passed Rector rule correctly handled at PR:

    • https://github.com/rectorphp/rector-src/pull/3078

    The RectifiedNode value object that previously used to save last previously run Rector rule no longer needed, so it can be removed https://github.com/rectorphp/rector-src/pull/3079/files#diff-5c5469b5b3ba8256b58b9d9bf66fe5873b03597965174036968f5b0d1513a565

    ~~It require verify phpstan_cache_printer attribute exists to decorate attribute CREATED_BY_RULE when refactor() call returns null.~~ It require connect refactored Node with existing Nodes for previous and next node.

    By this, we finally get rid of unnecessary save Node and Rector rule into object as it already in CREATED_BY_RULE :tada: 🎉 🎉

    opened by samsonasik 15
  • [PHPStan] Set compatible with upcoming PHPStan 1.6.x with set NodeConnectingVisitor tags

    [PHPStan] Set compatible with upcoming PHPStan 1.6.x with set NodeConnectingVisitor tags

    @ondrejmirtes @TomasVotruba I try to set compatible for upcoming PHPStan 1.6.x with bleeding edge feature. I tried to register NodeConnectingVisitor to config/phpstan/static-reflection.neon and it cause error Multiple services definition:

    Caused by
    _PHPStan_ccec86fc8\Nette\DI\ServiceCreationException: Multiple services of type PhpParser\NodeVisitor\NodeConnectingVisitor found: 04, 0258
    

    so I add to existing Service->set() definition in the config/services.php with define its tag there:

        $services->set(NodeConnectingVisitor::class)
            ->tag('phpstan.parser.richParserNodeVisitor');
    

    ref https://github.com/rectorphp/rector/issues/7088

    opened by samsonasik 15
  • [Renaming][PostRector] Handle skip path after defined at RenameClassRector

    [Renaming][PostRector] Handle skip path after defined at RenameClassRector

    Given the following config in tests:

    use Rector\Config\RectorConfig;
    use Rector\Renaming\Rector\Name\RenameClassRector;
    use Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\NewClass;
    use Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\OldClass;
    
    return static function (RectorConfig $rectorConfig): void {
        $rectorConfig
            ->ruleWithConfiguration(RenameClassRector::class, [
                OldClass::class => NewClass::class,
            ]);
    
        // skip the path after defined
        $rectorConfig->skip([
            RenameClassRector::class => [sys_get_temp_dir() . '/rector/tests_fixture_'],
        ]);
    };
    

    It not properly skipped, as there are 2 services:

    • RenameClassRector
    • ClassRenamingPostRector

    The ClassRenamingPostRector apply the change already before it actually skipped because that read the configs:

    https://github.com/rectorphp/rector-src/blob/3c168f03d38bb967a5e65e453f82adf120ef4eba/packages/PostRector/Rector/ClassRenamingPostRector.php#L27-L35

    This PR try to fix it with add new interface: PostRectorDependencyInterface to define the dependencies of the PostRector when needed.

    Fixes https://github.com/rectorphp/rector/issues/7417

    opened by samsonasik 4
  • Add constant FilesystemIterator::SKIP_DOTS when flags parameter is used

    Add constant FilesystemIterator::SKIP_DOTS when flags parameter is used

    I created a new rector rule to update \FilesystemIterator , this rule is supposed to be used when migrating code from php 8.1 to 8.2.

    Before PHP 8.2, \FilesystemIterator::SKIP_DOTS was always set and couldn't be removed, this has been fixed in PHP 8.2 and now you have to add this constant manually if you want to maintain the same behavior. This is also explained in documentation https://www.php.net/manual/en/filesystemiterator.construct.php.

    You can see an example here https://3v4l.org/HrmZ2.

    Note that this rule is important only if you use the second parameter ($params) from FilesystemIterator, the reason is that \FilesystemIterator::SKIP_DOTS is part of $paramsdefault value.

    // Nothing to do since \FilesystemIterator::SKIP_DOTS is part of default value.  
    new \FilesystemIterator(__DIR__);
    
    // Must add \FilesystemIterator::SKIP_DOTS to maintain same behavior before PHP 8.2
    new \FilesystemIterator(__DIR__, \FilesystemIterator::KEY_AS_FILENAME);
    

    I don't have experience creating Rector rules, so I'm open to any comment/suggestion :)

    opened by jawira 0
  • Add remove parent call rector

    Add remove parent call rector

    This rector allows users to remove calls to the parent class, for example when a parent method is removed.

    class SomeClass extends Other
    {
       public function __construct() {
    -     parent::__construct();
          /* ... */
       }
    
       public function other() {
    -     parent::some();
          /* ... */
       }
    }
    
    • [ ] add tests
    opened by jaapio 8
  • Add failing test fixture for SimplifyForeachToCoalescingRector

    Add failing test fixture for SimplifyForeachToCoalescingRector

    Failing Test for SimplifyForeachToCoalescingRector

    Based on https://getrector.org/demo/f9798778-4ed8-46c7-8d25-c4aa36358e82

    See https://github.com/rectorphp/rector/issues/7593

    opened by Wohlie 1
  • NormalizeNamespaceByPSR4ComposerAutoloadRector: Replace references correctly

    NormalizeNamespaceByPSR4ComposerAutoloadRector: Replace references correctly

    Previously, NormalizeNamespaceByPSR4ComposerAutoloadRector did not update references to other normalized classes properly. This change fixes that by recording the renames using RenamedClassesDataCollector.

    Supersedes https://github.com/rectorphp/rector-src/pull/2482

    opened by jtojnar 4
project with laravel 9 and php 8 and vuejs 3(modular) in both multi page and single page application

About Project Since Laravel 9 was recently released, it supports PHP 8 and above. So I decided to implement a prototype project using Laravel 9 + PHP

ali ahmadi 10 Sep 7, 2022
TweetNow is a Twitter clone created with Vue.js and Laravel. It is a social media platform that allows users to post short messages, follow other users, and engage in conversations through comments and likes.

TweetNow TweetNow is a opensource social media created with Vue.js+Inertia SSR and Laravel. It is a social media platform that allows users to post sh

I.E.U. Juboraj Naofel 12 Jun 16, 2023
PHP Laravel, MySQL and AIML chatbot engine and admin portal

Lemur Engine The Lemur Engine is a PHP/MySQL/AIML Chatbot. Written using the Laravel Framework. Demo You can demo the bot at the website: https://lemu

The Ramen Robot Disco Code 18 Nov 8, 2022
A Laravel 8 and Vue 3 SPA boilerplate using tailwind styling and sanctum for authentication :ghost:

Laravel Vue Sanctum SPA Laravel and vue spa using tailwind (laravel/ui looks) for styling and sanctum for authentification Features Laravel 8 Vue + Vu

Hijen EL Khalifi 62 Dec 5, 2022
Admin Columns allows you to manage and organize columns in the posts, users, comments, and media lists tables in the WordPress admin panel.

Admin Columns allows you to manage and organize columns in the posts, users, comments, and media lists tables in the WordPress admin panel. Transform the WordPress admin screens into beautiful, clear overviews.

Codepress 67 Dec 14, 2022
lara setups is a new star kit for installing latest and greetest version of vue js and bootstrap

Lara setups Introduction lara setups helps you to install latest bootstrap and vue.js version on your laravel project laravel team no longer supports

Mohammad khazaee 11 Jul 12, 2022
a simple and secured RESTful API made with codeIgniter and JSON Web Tokens

CodeIgniter 4 Application Starter What is CodeIgniter? CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure. More in

null 2 Oct 8, 2021
Symfony React Blank is a blank symfony and react project, use this template to start your app using Symfony as an backend api and React as a frontend library.

Symfony React Blank Symfony React Blank is a blank symfony and react project, use this template to start your app using Symfony as an backend api and

Antoine Kingue 2 Nov 5, 2021
Laravel and AngularJS Starter Application Boilerplate featuring Laravel 5.3 and AngularJS 1.5.8

?? Zemke/starter-laravel-angular has been upgraded to AngularJS 1.5.8. ?? Zemke/starter-laravel-angular has been upgraded to Laravel 5.3. You can pull

Florian Zemke 372 Nov 21, 2022
Demo and practice application with Laravel 8 and InertiaJS. (From laracasts course)

InertiaJS playground ⚽️ Started with the Laracasts: Build Modern Laravel Apps Using Inertia.js course and decided to share all my code here, I'll be a

Kasper Ligthart 1 Dec 2, 2021
Laravel 8 boilerplate in docker-compose with Treafik and SSL setup and github workflow ready for CI/CD pipeline

Laravel8 boilerplate Laravel 8 boilerplate in docker-compose with Treafik and SSL setup with .github workflow ready To start the containers in prod en

Tej Dahal 5 Jul 9, 2022
PHP template engine that uses data-attributes and keeps HTML templates valid and clean

Dataplater PHP template engine that uses data-attributes and keeps HTML templates valid and clean. Scroll down to see a usage example. Install compose

Leon 7 Oct 23, 2022
A simple and clean boilerplate to start a new SPA project with authentication and more features from fortify

A simple and clean boilerplate to start a new SPA project with authentication and more features from fortify. Its like the little sister of Jetstream, but as SPA.

Tobias Schulz 11 Dec 30, 2022
Generate Admin Panels CRUDs and APIs in Minutes with tons of other features and customizations with 3 different themes

InfyOm Laravel Generator Generate Admin Panels CRUDs and APIs in Minutes with tons of other features and customizations with 3 different themes. Docum

InfyOmLabs (InfyOm Technologies) 3.5k Jan 1, 2023
LaraAdmin is a Open source Laravel Admin Panel / CMS which can be used as Admin Backend, Data Management Tool or CRM boilerplate for Laravel with features like Advanced CRUD Generation, Module Manager, Backups and many more.

LaraAdmin 1.0 LaraAdmin is a Open source CRM for quick-start Admin based applications with features like Advanced CRUD Generation, Schema Manager and

Dwij IT Solutions 1.5k Dec 29, 2022
Prepare your Laravel apps incredibly fast, with various commands, services, facades and boilerplates.

Grafite Builder Grafite has archived this project and no longer supports or develops the code. We recommend using only as a source of ideas for your o

Grafite Inc 997 Dec 22, 2022
Get started with Laravel 5.3 and AngularJS (material)

Laravel 5.3 Angular Material Starter Demo An online demo is available. Angular (2+) update While this starter used to be an excellent starting point f

Jad Joubran 1.7k Dec 14, 2022
A Laravel 5 package that switchs default Laravel scaffolding/boilerplate to AdminLTE template and Pratt Landing Page with Bootstrap 3.0

AdminLTE template Laravel package A Laravel package that switch default Laravel scaffolding / boilerplate to AdminLTE template with Bootstrap 3.0 and

Sergi Tur Badenas 1.8k Jan 3, 2023