Skip to content

Instantly share code, notes, and snippets.

@PedroRajao
Last active July 13, 2021 04:37
Show Gist options
  • Save PedroRajao/e2c34d27b7e86fa5bf78ab2253a856d9 to your computer and use it in GitHub Desktop.
Save PedroRajao/e2c34d27b7e86fa5bf78ab2253a856d9 to your computer and use it in GitHub Desktop.
Rector - php 7.4 to 8 config file
<?php
// Details => https://getrector.org/blog/2020/11/30/smooth-upgrade-to-php-8-in-diffs
declare(strict_types=1);
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 {
// get parameters
$parameters = $containerConfigurator->parameters();
$containerConfigurator->import(SetList::PHP_80);
// is there a file you need to skip?
$parameters->set(Option::SKIP, [
// single file
//__DIR__ . '/src/ComplicatedFile.php',
// or directory
__DIR__ . '/vendor',
__DIR__ . '/lib',
// or fnmatch
//__DIR__ . '/src/*/Tests/*',
// is there single rule you don't like from a set you use?
SimplifyIfReturnBoolRector::class,
// or just skip rule in specific directory
SimplifyIfReturnBoolRector::class => [
// single file
__DIR__ . '/src/ComplicatedFile.php',
// or directory
__DIR__ . '/src',
// or fnmatch
__DIR__ . '/src/*/Tests/*',
],
]);
// Define what rule sets will be applied
$containerConfigurator->import(SetList::DEAD_CODE);
// get services (needed for register a single rule)
// $services = $containerConfigurator->services();
// register a single rule
// $services->set(TypedPropertyRector::class);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment