rector/README.md

1.9 KiB

Rector - Reconstruct your Legacy Code to Modern Codebase

Build Status Coverage Status

This tool will upgrade your application for you.

All Reconstructors

At the moment these packages are supported:

Install

composer require rector/rector --dev

How To Reconstruct your Code?

  1. Create rector.yml with desired Rectors
rectors:
    - Rector\Rector\Contrib\Nette\Application\InjectPropertyRector
  1. Run rector on your /src directory
vendor/bin/rector process src
  1. Check the Git
git diff

6 Steps to Add New Rector

Just extend Rector\Rector\AbstractRector. It will prepare 2 methods processing the node.

public function isCandidate(Node $node): bool
{
}

public function refactor(Node $node): ?Node
{
}
  1. Put it under namespace Rector\Contrib\<set>; namespace
<?php declare(strict_types=1);

namespace Rector\Contrib\Symfony;
    
use Rector\Rector\AbstractRector;

final class MyRector extends AbstractRector
{
    // ...
}
  1. Add a Test Case

  2. Add to specific level, e.g. /src/config/level/nette/nette24.yml

  3. Submit PR

  4. 👍

How to Contribute

Just follow 3 rules:

  • 1 feature per pull-request

  • New feature needs tests

  • Tests, coding standard and PHPStan checks must pass

    composer all
    

    Don you need to fix coding standards? Run:

    composer fix-cs
    

We would be happy to merge your feature then.