Skip to content

Commit 5ca0608

Browse files
committed
Setup PHPStan
1 parent 1f1e29c commit 5ca0608

7 files changed

Lines changed: 564 additions & 4 deletions

File tree

.github/CONTRIBUTING.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ about what you're working on, you can contact us via the
7474
```
7575

7676
to automatically fix coding standard issues.
77+
- Run
78+
79+
```shell
80+
make static-analysis
81+
```
82+
83+
to run a static analysis or, if applicable, run
84+
85+
```shell
86+
make static-analysis-baseline
87+
```
88+
89+
to regenerate the baseline.
7790
- Review the change once more just before submitting it.
7891

7992
## What happens after submitting contribution?
@@ -134,6 +147,20 @@ Having said that, here are the organizational rules:
134147
make coding-standards
135148
```
136149

137-
6. Use reasonable commit messages.
150+
6. Run
151+
152+
```shell
153+
make static-analysis
154+
```
155+
156+
to run a static analysis or, if applicable, run
157+
158+
```shell
159+
make static-analysis-baseline
160+
```
161+
162+
to regenerate the baseline.
163+
164+
7. Use reasonable commit messages.
138165

139166
Thank you for contributing to https://www.php.net!

.github/workflows/integrate.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,49 @@ jobs:
107107
- name: "Validate XML files"
108108
run: "for a in $(find . -name '*.xml'); do xmllint --quiet --noout $a; done"
109109

110+
static-analysis:
111+
name: "Static Analysis"
112+
113+
runs-on: "ubuntu-latest"
114+
115+
strategy:
116+
matrix:
117+
php-version:
118+
- "8.2"
119+
120+
dependencies:
121+
- "locked"
122+
123+
steps:
124+
- name: "Checkout"
125+
uses: "actions/checkout@v3"
126+
127+
- name: "Set up PHP"
128+
uses: "shivammathur/setup-php@v2"
129+
with:
130+
coverage: "none"
131+
extensions: "none, curl, dom, json, mbstring, tokenizer, xml, xmlwriter, iconv"
132+
php-version: "${{ matrix.php-version }}"
133+
134+
- name: "Set up problem matchers for PHP"
135+
run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\""
136+
137+
- name: "Determine composer cache directory"
138+
run: "echo \"COMPOSER_CACHE_DIR=$(composer config cache-dir)\" >> $GITHUB_ENV"
139+
140+
- name: "Cache dependencies installed with composer"
141+
uses: "actions/cache@v3"
142+
with:
143+
path: "${{ env.COMPOSER_CACHE_DIR }}"
144+
key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.lock') }}"
145+
restore-keys: "php-${{ matrix.php-version }}-composer-"
146+
147+
- name: "Install dependencies with composer"
148+
run: "composer install --ansi --no-interaction --no-progress"
149+
150+
- name: "Run static analysis"
151+
run: "vendor/bin/phpstan"
152+
110153
tests:
111154
name: "Tests"
112155

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ HTTP_HOST:=localhost:8080
44
CORES?=$(shell (nproc || sysctl -n hw.ncpu) 2> /dev/null)
55

66
.PHONY: it
7-
it: coding-standards tests ## Runs all the targets
7+
it: coding-standards static-analysis tests ## Runs all the targets
88

99
.PHONY: code-coverage
1010
code-coverage: vendor ## Collects code coverage from running unit tests with phpunit/phpunit
@@ -18,6 +18,14 @@ coding-standards: vendor ## Fixes code style issues with friendsofphp/php-cs-fix
1818
help: ## Displays this list of targets with descriptions
1919
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'
2020

21+
.PHONY: static-analysis
22+
static-analysis: vendor ## Runs a static code analysis
23+
vendor/bin/phpstan
24+
25+
.PHONY: static-analysis-baseline
26+
static-analysis-baseline: vendor ## Generates a baseline for static analysis
27+
vendor/bin/phpstan --generate-baseline
28+
2129
.PHONY: tests
2230
tests: vendor ## Runs unit and end-to-end tests with phpunit/phpunit
2331
vendor/bin/phpunit --configuration=tests/phpunit.xml --testsuite=unit

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"require-dev": {
1414
"ext-curl": "*",
1515
"friendsofphp/php-cs-fixer": "^3.95.4",
16+
"phpstan/extension-installer": "^1.4",
17+
"phpstan/phpstan": "^2.2",
18+
"phpstan/phpstan-phpunit": "^2.0",
1619
"phpunit/phpunit": "^11.5.50"
1720
},
1821
"autoload": {
@@ -29,6 +32,9 @@
2932
"platform": {
3033
"php": "8.2.0"
3134
},
32-
"sort-packages": true
35+
"sort-packages": true,
36+
"allow-plugins": {
37+
"phpstan/extension-installer": true
38+
}
3339
}
3440
}

composer.lock

Lines changed: 169 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)