Skip to content

Commit

Permalink
feat: add rector in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
noelma committed Dec 9, 2021
1 parent c1d1952 commit d1dac19
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ phpdoc.dist.xml export-ignore
phpunit.xml export-ignore
phpunit.xml.dist export-ignore
phpstan.neon.dist export-ignore
rector.php export-ignore
USAGE.md export-ignore
README_fr.md export-ignore
6 changes: 5 additions & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
php: [7.2, 7.3, 7.4, 8.0, 8.1]
experimental: [false]
include:
- php: 7.4
- php: 7.2
analysis: true

steps:
Expand All @@ -40,6 +40,10 @@ jobs:
- name: Unit tests
run: bin/phpunit --coverage-clover clover.xml

- name: Refactoring
if: matrix.analysis
run: bin/rector --dry-run

- name: Upload coverage results to Coveralls
if: matrix.analysis
env:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"friendsofphp/php-cs-fixer": "^3.2",
"phpstan/phpstan": "^1.1",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^8.5"
"phpunit/phpunit": "^8.5",
"rector/rector": "0.12.5"
},
"suggest": {
"phpdocumentor/phpdocumentor": "To generate documentation.",
Expand Down
28 changes: 28 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// get parameters
$parameters = $containerConfigurator->parameters();

// paths to refactor; solid alternative to CLI arguments
$parameters->set(Option::PATHS, [
__DIR__ . '/src',
__DIR__ . '/tests'
]);

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

// Define what rule sets will be applied
$containerConfigurator->import(SetList::CODE_QUALITY);

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

0 comments on commit d1dac19

Please sign in to comment.