Skip to content

Commit

Permalink
add rector CI
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jul 26, 2023
1 parent c5fe85f commit 7948729
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/rector.yaml
Original file line number Diff line number Diff line change
@@ -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 <actions@github.com>'
commit_user_email: 'action@github.com'
20 changes: 14 additions & 6 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
]);
};
2 changes: 1 addition & 1 deletion src/Analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
final class Analyser
{
private Collector $collector;
private readonly Collector $collector;

public function __construct()
{
Expand Down
5 changes: 3 additions & 2 deletions src/CLI/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace TomasVotruba\Lines\CLI;

use Throwable;
use SebastianBergmann\FileIterator\Facade;
use TomasVotruba\Lines\Analyser;
use TomasVotruba\Lines\Enum\StatusCode;
Expand All @@ -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;
Expand All @@ -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 === []) {
Expand Down
2 changes: 1 addition & 1 deletion src/CLI/ArgumentsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function build(array $argv): Arguments
} catch (CliParserException $cliParserException) {
throw new ShouldNotHappenException(
$cliParserException->getMessage(),
(int) $cliParserException->getCode(),
$cliParserException->getCode(),
$cliParserException
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7948729

Please sign in to comment.