diff --git a/.github/workflows/rector.yaml b/.github/workflows/rector.yaml new file mode 100644 index 00000000..bf4f407e --- /dev/null +++ b/.github/workflows/rector.yaml @@ -0,0 +1,35 @@ +# github action that checks code with Rector +name: Rector + +on: + pull_request: null + +jobs: + rector: + runs-on: ubuntu-latest + if: github.event.pull_request.head.repo.full_name == 'TomasVotruba/lines' + steps: + - + if: github.event.pull_request.head.repo.full_name == github.repository + uses: actions/checkout@v3 + with: + # Must be used to trigger workflow after push + token: ${{ secrets.ACCESS_TOKEN }} + + - + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + coverage: none + + - uses: "ramsey/composer-install@v2" + + - run: vendor/bin/rector --ansi + + - + # commit only to core contributors who have repository access + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: '[rector] Rector fixes' + commit_author: 'GitHub Action ' + commit_user_email: 'action@github.com' diff --git a/rector.php b/rector.php index adbf9d7b..0d520a08 100644 --- a/rector.php +++ b/rector.php @@ -5,7 +5,9 @@ use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector; +use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Set\ValueObject\LevelSetList; +use Rector\Set\ValueObject\SetList; return static function (RectorConfig $rectorConfig): void { $rectorConfig->importNames(); @@ -16,15 +18,21 @@ $rectorConfig->paths([ __DIR__ . '/src', - __DIR__ . '/tests/unit', + __DIR__ . '/tests', + ]); + + $rectorConfig->skip([ + '*/Fixture/*', ]); $rectorConfig->sets([ LevelSetList::UP_TO_PHP_81, - \Rector\Set\ValueObject\SetList::CODE_QUALITY, - \Rector\Set\ValueObject\SetList::CODING_STYLE, - \Rector\Set\ValueObject\SetList::TYPE_DECLARATION, - \Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_100, - \Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_CODE_QUALITY, + SetList::CODE_QUALITY, + SetList::CODING_STYLE, + SetList::TYPE_DECLARATION, + SetList::PRIVATIZATION, + SetList::DEAD_CODE, + PHPUnitSetList::PHPUNIT_100, + PHPUnitSetList::PHPUNIT_CODE_QUALITY, ]); }; diff --git a/src/Analyser.php b/src/Analyser.php index 506f5b02..4c322bb4 100644 --- a/src/Analyser.php +++ b/src/Analyser.php @@ -11,7 +11,7 @@ */ final class Analyser { - private Collector $collector; + private readonly Collector $collector; public function __construct() { diff --git a/src/CLI/Application.php b/src/CLI/Application.php index 3d0e7243..b5a550eb 100644 --- a/src/CLI/Application.php +++ b/src/CLI/Application.php @@ -4,6 +4,7 @@ namespace TomasVotruba\Lines\CLI; +use Throwable; use SebastianBergmann\FileIterator\Facade; use TomasVotruba\Lines\Analyser; use TomasVotruba\Lines\Enum\StatusCode; @@ -22,7 +23,7 @@ public function run(array $argv): int try { $arguments = $argumentsBuilder->build($argv); - } catch (\Throwable $throwable) { + } catch (Throwable $throwable) { print PHP_EOL . $throwable->getMessage() . PHP_EOL; return StatusCode::ERROR; @@ -40,7 +41,7 @@ public function run(array $argv): int foreach ($arguments->directories() as $directory) { $currentFiles = (new Facade())->getFilesAsArray($directory, $arguments->suffixes(), '', $arguments->exclude()); - $files = array_merge($files, $currentFiles); + $files = [...$files, ...$currentFiles]; } if ($files === []) { diff --git a/src/CLI/ArgumentsBuilder.php b/src/CLI/ArgumentsBuilder.php index cbc58109..f9fdfc35 100644 --- a/src/CLI/ArgumentsBuilder.php +++ b/src/CLI/ArgumentsBuilder.php @@ -29,7 +29,7 @@ public function build(array $argv): Arguments } catch (CliParserException $cliParserException) { throw new ShouldNotHappenException( $cliParserException->getMessage(), - (int) $cliParserException->getCode(), + $cliParserException->getCode(), $cliParserException ); } diff --git a/src/Collector.php b/src/Collector.php index d849ee91..cfc66630 100644 --- a/src/Collector.php +++ b/src/Collector.php @@ -25,7 +25,7 @@ public function getPublisher(): Publisher public function addFile(string $filename): void { $this->increment('files'); - $this->addUnique('directories', dirname((string) $filename)); + $this->addUnique('directories', dirname($filename)); } public function incrementLines(int $number): void