diff --git a/.github/workflows/automated_testing.yml b/.github/workflows/automated_testing.yml index 18715e1..4746a90 100644 --- a/.github/workflows/automated_testing.yml +++ b/.github/workflows/automated_testing.yml @@ -21,6 +21,32 @@ jobs: - name: Validate composer.json and composer.lock run: composer validate --strict + cs-fixer: + name: Check code style with CS Fixer + runs-on: ubuntu-latest + + steps: + - uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + + - uses: actions/checkout@v4 + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v4 + with: + path: vendor + key: "${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}" + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + uses: ramsey/composer-install@v3 + + - name: Check code style + run: composer run cs-fixer-check -- --show-progress=none + phpstan: name: Static analyze with PHPStan runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 1292c27..6ec1b85 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea /.phpunit.cache/ /vendor/ +/.php-cs-fixer.cache diff --git a/.php-cs-fixer-finder.php b/.php-cs-fixer-finder.php new file mode 100644 index 0000000..def3278 --- /dev/null +++ b/.php-cs-fixer-finder.php @@ -0,0 +1,14 @@ +files() + ->in(__DIR__) + ->exclude(['var', 'vendor']) + ->append([ + 'bin/dev/php-cs-fixer-update-baseline', + ]); + + + diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..8916fff --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,19 @@ + true, + '@Symfony:risky' => true, + 'concat_space' => [ + 'spacing' => 'one', + ], + 'phpdoc_align' => ['align' => 'left'], +]; + +$config = (new PhpCsFixer\Config()) + ->setRiskyAllowed(true) + ->setRules($rules); + +/** @var PhpCsFixer\Finder $finder */ +$finder = require __DIR__ . '/.php-cs-fixer-finder.php'; + +return $config->setFinder($finder); diff --git a/composer.json b/composer.json index a05dc25..b18a10c 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,10 @@ "sort-packages": true }, "scripts": { + "cs-check": "@cs-fixer-check", + "cs-fix": "@cs-fixer-fix", + "cs-fixer-check": "vendor/bin/php-cs-fixer fix --dry-run", + "cs-fixer-fix": "vendor/bin/php-cs-fixer fix -vv", "phpstan": [ "@phpstan-clear", "@phpstan-analyse"