Skip to content

Commit b52efa7

Browse files
committed
adding phpcs
1 parent 9d23159 commit b52efa7

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

.github/workflows/php-quality.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: PHP Auto-Fix & Quality Check
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
10+
jobs:
11+
# 🔧 Auto-fix coding standards (only once, PHP 8.1)
12+
phpcbf-fix:
13+
runs-on: ubuntu-latest
14+
steps:
15+
# 1️⃣ Checkout code
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
ref: ${{ github.head_ref || github.ref_name }}
20+
persist-credentials: false # allows bot to push fixes
21+
22+
# 2️⃣ Setup PHP (single version for auto-fix)
23+
- name: Setup PHP 8.3
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: 8.3
27+
coverage: none
28+
29+
# 3️⃣ Install PHPCS
30+
- name: Install PHPCS
31+
run: |
32+
composer global require squizlabs/php_codesniffer
33+
echo "$HOME/.config/composer/vendor/bin" >> $GITHUB_PATH
34+
35+
# 4️⃣ Run PHPCBF (auto-fix issues)
36+
- name: Run PHPCBF
37+
run: phpcbf --standard=PSR12 src/ || true
38+
39+
# 5️⃣ Commit & push fixes back to branch
40+
- name: Commit and push PHPCBF fixes
41+
if: github.ref != 'refs/heads/main' # optional: skip main
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
run: |
45+
git config user.name "github-actions[bot]"
46+
git config user.email "github-actions[bot]@users.noreply.github.com"
47+
git add .
48+
git diff-index --quiet HEAD || git commit -m "PHPCBF: auto-fix coding standards (PHP ${{ matrix.php-version }})"
49+
git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD
50+
51+
# 🧪 Run PHPCS + PHPStan on multiple PHP versions
52+
php-quality:
53+
runs-on: ubuntu-latest
54+
needs: phpcbf-fix
55+
strategy:
56+
fail-fast: false
57+
matrix:
58+
php-version: [7.3, 7.4, 8.0, 8.1, 8.2, 8.3]
59+
60+
steps:
61+
# 1️⃣ Checkout code
62+
- name: Checkout code
63+
uses: actions/checkout@v4
64+
65+
# 2️⃣ Setup PHP for matrix
66+
- name: Setup PHP ${{ matrix.php-version }}
67+
uses: shivammathur/setup-php@v2
68+
with:
69+
php-version: ${{ matrix.php-version }}
70+
coverage: none
71+
72+
# 3️⃣ Install PHPStan + PHPCS
73+
- name: Install PHPStan and PHPCS
74+
run: |
75+
composer global require phpstan/phpstan squizlabs/php_codesniffer
76+
echo "$HOME/.config/composer/vendor/bin" >> $GITHUB_PATH
77+
78+
# 4️⃣ Run PHPStan
79+
- name: Run PHPStan
80+
run: phpstan analyse src --memory-limit=1G
81+
82+
# 5️⃣ Run PHPCS
83+
- name: Run PHPCS (lint only)
84+
run: phpcs --standard=PSR12 --warning-severity=0 src/

0 commit comments

Comments
 (0)