Skip to content

Commit

Permalink
Merge pull request #2173 from tarlepp/chore(env)/rector-configuration
Browse files Browse the repository at this point in the history
Chore(env) - Updated rector basic configuration
  • Loading branch information
tarlepp committed Jan 28, 2023
2 parents 6c47377 + bd67121 commit 7e05d1e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
5 changes: 1 addition & 4 deletions composer.json
Expand Up @@ -127,10 +127,7 @@
"PHPStan\\Symfony\\": "tools/02_phpstan/vendor/phpstan/phpstan-symfony/src/Symfony",
"PHPStan\\Type\\PHPUnit\\": "tools/02_phpstan/vendor/phpstan/phpstan-phpunit/src/Type/PHPUnit",
"PHPStan\\Type\\Symfony\\": "tools/02_phpstan/vendor/phpstan/phpstan-symfony/src/Type/Symfony",
"Rector\\Core\\": "tools/09_rector/vendor/rector/rector/src",
"Rector\\Php74\\": "tools/09_rector/vendor/rector/rector/rules/Php74",
"Rector\\Php80\\": "tools/09_rector/vendor/rector/rector/rules/Php80",
"Rector\\Set\\": "tools/09_rector/vendor/rector/rector/packages/Set"
"Rector\\": "tools/09_rector/vendor/rector"
}
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions phpinsights.php
Expand Up @@ -42,6 +42,7 @@
'var',
'vendor',
'tools',
'rector.php',
],
'add' => [
// ExampleMetric::class => [
Expand Down
60 changes: 33 additions & 27 deletions rector.php
Expand Up @@ -2,36 +2,42 @@
declare(strict_types = 1);
/**
* rector.php
*
*
* @see following for actual rules
* ./tools/09_rector/vendor/rector/rector/packages/Set/ValueObject/LevelSetList.php
* ./tools/09_rector/vendor/rector/rector/vendor/rector/rector-symfony/src/Set/SymfonyLevelSetList.php
*/

use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Symfony\Set\SymfonyLevelSetList;

return static function (ContainerConfigurator $containerConfigurator): void {
// get parameters
$parameters = $containerConfigurator->parameters();
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/config',
__DIR__ . '/migrations',
__DIR__ . '/public',
__DIR__ . '/src',
/**
* First run some rule(s) or sets to whole codebase and
* run all the tests (phpunit, ecs, psalm and phpstan),
* after that fix possible issues of those and run those
* again until you don't have any issues left.
*
* After that enable this directory and run rector again
* and do that whole process again.
*/
//__DIR__ . '/tests',
]);

// paths to refactor; solid alternative to CLI arguments
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/tests']);
// Enable single or multiple rules with rector
//$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

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

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

// Define what rule sets will be applied
$containerConfigurator->import(SetList::CODE_QUALITY);
$containerConfigurator->import(SetList::CODE_QUALITY_STRICT);
$containerConfigurator->import(SetList::DEAD_CODE);
//$containerConfigurator->import(SetList::TYPE_DECLARATION);
$containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT);
$containerConfigurator->import(SetList::PHP_80);

// get services (needed for register a single rule)
$services = $containerConfigurator->services();
$services->set(TypedPropertyRector::class);
// Enable the set(s) that you want to run with rector
$rectorConfig->sets([
//LevelSetList::UP_TO_PHP_82, // This is for PHP version upgrade
//SymfonyLevelSetList::UP_TO_SYMFONY_62, // This is for Symfony version upgrade
]);
};

0 comments on commit 7e05d1e

Please sign in to comment.