Upgrade

PHP Upgrade #

Supported Versions #

Rector #

Overview #

Install #

$ composer require rector/rector --dev
$ composer install
$ vendor/bin/rector init
$ vi rector.php
<?php

declare(strict_types=1);

// use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
    // register paths to upgrade and refactor PHP code
    $rectorConfig->paths([
        __DIR__ . '/src',
    ]);

    // register paths to skip
    $rectorConfig->skip([
        __DIR__ . '/foo/bar',
    ]);

    // register following values
    // arguments and default values: max seconds = 120, max number of process = 16, job size = 20
    $rectorConfig->parallel(300);

    // register a single rule
    // $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

    // define sets of rules
    $rectorConfig->sets([
        // LevelSetList::UP_TO_PHP_54,
        // LevelSetList::UP_TO_PHP_55, 
        // LevelSetList::UP_TO_PHP_56, 
        // LevelSetList::UP_TO_PHP_70, 
        // LevelSetList::UP_TO_PHP_71, 
        // LevelSetList::UP_TO_PHP_72,
        // LevelSetList::UP_TO_PHP_73,
        LevelSetList::UP_TO_PHP_74,
        LevelSetList::UP_TO_PHP_80,
        LevelSetList::UP_TO_PHP_81,
        LevelSetList::UP_TO_PHP_82,
    ]);
};

Run #

$ vendor/bin/rector --help
$ vendor/bin/rector process src --config=rector.php --dry-run 
$ vendor/bin/rector process src --config=rector.php

Directory Structure #

.
├── src # Target dir to upgrade and refactor PHP code
├── vendor
│   ├── bin
│   ├── composer
│   ├── phpstan
│   ├── rector
│   └── autoload.php
├── composer.json
├── composer.lock
└── rector.php

Rector for Laravel #

Overview #

Install #

$ composer require driftingly/rector-laravel --dev
$ composer install
$ vendor/bin/rector init
$ vi rector.php
<?php

declare(strict_types=1);

// use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use RectorLaravel\Set\LaravelSetList;

return static function (RectorConfig $rectorConfig): void {
    // register paths to upgrade and refactor PHP code
    $rectorConfig->paths([
        __DIR__ . '/src',
    ]);

    // register paths to skip
    $rectorConfig->skip([
        __DIR__ . '/foo/bar',
    ]);

    // register following values
    // arguments and default values: max seconds = 120, max number of process = 16, job size = 20
    $rectorConfig->parallel(300);

    // register a single rule
    // $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

    // define sets of rules 
    $rectorConfig->sets([
        // LevelSetList::UP_TO_PHP_54,
        // LevelSetList::UP_TO_PHP_55, 
        // LevelSetList::UP_TO_PHP_56, 
        // LevelSetList::UP_TO_PHP_70, 
        // LevelSetList::UP_TO_PHP_71, 
        // LevelSetList::UP_TO_PHP_72,
        // LevelSetList::UP_TO_PHP_73,
        LevelSetList::UP_TO_PHP_74,
        LevelSetList::UP_TO_PHP_80,
        LevelSetList::UP_TO_PHP_81,
        LevelSetList::UP_TO_PHP_82,

        // LaravelSetList::LARAVEL_51,
        // LaravelSetList::LARAVEL_52,
        // LaravelSetList::LARAVEL_53,
        // LaravelSetList::LARAVEL_54,
        // LaravelSetList::LARAVEL_55,
        // LaravelSetList::LARAVEL_56,
        // LaravelSetList::LARAVEL_57,
        // LaravelSetList::LARAVEL_58,
        LaravelSetList::LARAVEL_60,
        LaravelSetList::LARAVEL_70,
        LaravelSetList::LARAVEL_80,
        LaravelSetList::LARAVEL_90,
    ]); 
};

Run #

$ vendor/bin/rector process src --config=rector.php --dry-run
$ vendor/bin/rector process src --config=rector.php

References #