Skip to content

Commit d20e569

Browse files
authored
Merge pull request #4 from OnrampLab/3-add-static-analysis-with-phpstan-and-phpcs
feat: Add static analysis tools (PHPStan and PHPCS)
2 parents 02a2749 + a1d1928 commit d20e569

File tree

5 files changed

+236
-4
lines changed

5 files changed

+236
-4
lines changed

.github/workflows/phpcs.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: PHPCS
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
phpcs:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
19+
- name: Set up PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: '8.1'
23+
24+
- name: Install dependencies
25+
run: composer install
26+
27+
- name: Get list of changed files
28+
id: changed-files
29+
uses: tj-actions/changed-files@v34
30+
31+
- name: Run PHPCS
32+
run: |
33+
CHANGED_FILES=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep '\.php$' || true)
34+
if [ -n "$CHANGED_FILES" ]; then
35+
vendor/bin/phpcs --standard=PSR12 $CHANGED_FILES
36+
else
37+
echo "No PHP files changed, skipping PHPCS."
38+
fi

.github/workflows/phpstan.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: PHPStan
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
phpstan:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
19+
- name: Set up PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: '8.1'
23+
24+
- name: Install dependencies
25+
run: composer install
26+
27+
- name: Get list of changed files
28+
id: changed-files
29+
uses: tj-actions/changed-files@v34
30+
31+
- name: Run PHPStan
32+
run: |
33+
CHANGED_FILES=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep '\.php$' || true)
34+
if [ -n "$CHANGED_FILES" ]; then
35+
vendor/bin/phpstan analyse $CHANGED_FILES
36+
else
37+
echo "No PHP files changed, skipping PHPStan."
38+
fi

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "A content generator for PHP",
44
"type": "library",
55
"require": {
6-
"php": ">=7.4",
6+
"php": ">=8.1",
77
"mustache/mustache": "^2.13"
88
},
99
"autoload": {
@@ -12,7 +12,9 @@
1212
}
1313
},
1414
"require-dev": {
15-
"phpunit/phpunit": "^9.5"
15+
"phpunit/phpunit": "^9.5",
16+
"phpstan/phpstan": "^1.0",
17+
"squizlabs/php_codesniffer": "^3.0"
1618
},
1719
"scripts": {
1820
"test": "phpunit"

composer.lock

Lines changed: 146 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
parameters:
2+
level: max
3+
paths:
4+
- src
5+
6+
# Optional: Include bootstrap file if necessary and ensure the path is correct
7+
bootstrapFiles:
8+
- vendor/autoload.php
9+
10+
# Optional: Add any other configuration options as needed

0 commit comments

Comments
 (0)