Skip to content

Commit

Permalink
Add CS fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Sep 6, 2024
1 parent 3768515 commit 359f984
Show file tree
Hide file tree
Showing 4 changed files with 2,052 additions and 569 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---

on: # yamllint disable-line rule:truthy
pull_request:
branches:
- master
push:
branches:
- master

name: 🧹 Fix PHP coding standards

jobs:
coding-standards:
timeout-minutes: 4
runs-on: ${{ matrix.os }}
concurrency:
cancel-in-progress: true
group: coding-standards-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
strategy:
matrix:
os:
- ubuntu-latest
php-version:
- '8.2'
dependencies:
- locked
permissions:
contents: write
steps:
- name: ⚙️ Set git to use LF line endings
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: 🛠️ Setup PHP
uses: shivammathur/setup-php@2.30.4
with:
php-version: ${{ matrix.php-version }}
extensions: none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, sockets
ini-values: error_reporting=E_ALL
coverage: none

- name: 📦 Check out the codebase
uses: actions/checkout@v4.1.6

- name: 🛠️ Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: 🤖 Validate composer.json and composer.lock
run: composer validate --ansi --strict

- name: 🔍 Get composer cache directory
uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0

- name: ♻️ Restore cached dependencies installed with composer
uses: actions/cache@v4.0.2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-

- name: 📥 Install "${{ matrix.dependencies }}" dependencies with composer
uses: wayofdev/gh-actions/actions/composer/install@v3.1.0
with:
dependencies: ${{ matrix.dependencies }}

- name: 🛠️ Prepare environment
run: make prepare

- name: 🚨 Run coding standards task
run: composer cs:fix
env:
PHP_CS_FIXER_IGNORE_ENV: true

- name: 📤 Commit and push changed files back to GitHub
uses: stefanzweifel/git-auto-commit-action@v5.0.1
with:
commit_message: 'style(php-cs-fixer): lint php files and fix coding standards'
branch: ${{ github.head_ref }}
commit_author: 'github-actions <github-actions@users.noreply.github.com>'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19 changes: 19 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

use WayOfDev\PhpCsFixer\Config\ConfigBuilder;
use WayOfDev\PhpCsFixer\Config\RuleSets\ExtendedPERSet;

require_once 'vendor/autoload.php';

$config = ConfigBuilder::createFromRuleSet(new ExtendedPERSet())
->inDir(__DIR__ . '/bin')
->inDir(__DIR__ . '/src')
->inDir(__DIR__ . '/tests')
->addFiles([__FILE__])
->getConfig();

$config->setCacheFile(__DIR__ . '/runtime/php-cs-fixer/php-cs-fixer.cache');

return $config;
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
},
"require-dev": {
"buggregator/trap": "^1.10",
"friendsofphp/php-cs-fixer": "^3.64",
"phpunit/phpunit": "^10.5",
"ta-tikoma/phpunit-architecture-test": "^0.8.4",
"vimeo/psalm": "^5.25"
"vimeo/psalm": "^5.25",
"wayofdev/cs-fixer-config": "^1.4"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand All @@ -49,6 +51,8 @@
"sort-packages": true
},
"scripts": {
"cs:diff": "php-cs-fixer fix --dry-run -v --diff",
"cs:fix": "php-cs-fixer fix -v",
"psalm": "psalm",
"psalm:baseline": "psalm --set-baseline=psalm-baseline.xml",
"psalm:ci": "psalm --output-format=github --shepherd --show-info=false --stats --threads=4",
Expand Down
Loading

0 comments on commit 359f984

Please sign in to comment.