Skip to content

Commit e7a0ab1

Browse files
committed
ci: add psalm static analysis
test: separate phpunit and pest tests test: add arch pest tests deps: add support for rector
1 parent 78b8f41 commit e7a0ab1

17 files changed

+480
-135
lines changed

.github/workflows/static-analysis.yml

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,32 @@ on: # yamllint disable-line rule:truthy
55
branches:
66
- master
77
paths:
8+
- 'phpstan*'
9+
- 'psalm*'
10+
- 'composer.*'
811
- 'src/**'
912
- 'tests/**'
10-
- 'bin/trap'
1113
- '.php-cs-fixer.dist.php'
1214
pull_request:
1315
branches:
1416
- master
1517
paths:
18+
- 'phpstan*'
19+
- 'psalm*'
20+
- 'composer.*'
1621
- 'src/**'
1722
- 'tests/**'
18-
- 'bin/trap'
1923
- '.php-cs-fixer.dist.php'
2024

2125
name: 🔍 Static analysis
2226

2327
jobs:
24-
static-analysis:
28+
phpstan:
2529
timeout-minutes: 4
2630
runs-on: ${{ matrix.os }}
2731
concurrency:
2832
cancel-in-progress: true
29-
group: static-analysis-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
33+
group: phpstan-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
3034
strategy:
3135
fail-fast: true
3236
matrix:
@@ -71,3 +75,54 @@ jobs:
7175

7276
- name: 🔍 Run static analysis using phpstan/phpstan
7377
run: composer stan:ci
78+
79+
psalm:
80+
timeout-minutes: 4
81+
runs-on: ${{ matrix.os }}
82+
concurrency:
83+
cancel-in-progress: true
84+
group: psalm-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
85+
strategy:
86+
fail-fast: true
87+
matrix:
88+
os:
89+
- ubuntu-latest
90+
php-version:
91+
- '8.1'
92+
dependencies:
93+
- locked
94+
steps:
95+
- name: 📦 Check out the codebase
96+
uses: actions/checkout@v4.1.6
97+
98+
- name: 🛠️ Setup PHP
99+
uses: shivammathur/setup-php@2.30.4
100+
with:
101+
php-version: ${{ matrix.php-version }}
102+
extensions: none, ctype, curl, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, opcache, pcntl, posix
103+
ini-values: error_reporting=E_ALL
104+
coverage: xdebug
105+
106+
- name: 🛠️ Setup problem matchers
107+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
108+
109+
- name: 🤖 Validate composer.json and composer.lock
110+
run: composer validate --ansi --strict
111+
112+
- name: 🔍 Get composer cache directory
113+
uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0
114+
115+
- name: ♻️ Restore cached dependencies installed with composer
116+
uses: actions/cache@v4.0.2
117+
with:
118+
path: ${{ env.COMPOSER_CACHE_DIR }}
119+
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
120+
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
121+
122+
- name: 📥 Install "${{ matrix.dependencies }}" dependencies
123+
uses: wayofdev/gh-actions/actions/composer/install@v3.1.0
124+
with:
125+
dependencies: ${{ matrix.dependencies }}
126+
127+
- name: 🔍 Run static analysis using vimeo/psalm
128+
run: composer psalm:ci

.phive/phars.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
33
<phar name="composer-normalize" version="^2.42.0" installed="2.42.0" location="./.phive/composer-normalize" copy="false"/>
4-
<phar name="composer-require-checker" version="^4.10.0" installed="4.10.0" location="./.phive/composer-require-checker" copy="false"/>
4+
<phar name="composer-require-checker" version="^4.11.0" installed="4.11.0" location="./.phive/composer-require-checker" copy="false"/>
55
</phive>

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ repos:
2929
description: Run markdownlint-cli2 on your Markdown files using the docker image
3030
language: docker_image
3131
types: [markdown]
32-
entry: davidanson/markdownlint-cli2-rules:latest
32+
entry: 'davidanson/markdownlint-cli2-rules:latest'
33+
args: ['--config', '.github/.markdownlint.json']
3334

3435
...

Makefile

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ENVSUBST ?= $(BUILDER) envsubst
3636
YAML_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
3737
-v $(PWD):/data \
3838
cytopia/yamllint:latest \
39+
-c ./.github/.yamllint.yaml \
3940
-f colored .
4041

4142
ACTION_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
@@ -47,7 +48,8 @@ ACTION_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
4748
MARKDOWN_LINT_RUNNER ?= $(DOCKER) run --rm $$(tty -s && echo "-it" || echo) \
4849
-v $(shell pwd):/app \
4950
--workdir /app \
50-
davidanson/markdownlint-cli2-rules:latest
51+
davidanson/markdownlint-cli2-rules:latest \
52+
--config ".github/.markdownlint.json"
5153

5254
PHIVE_RUNNER ?= $(DOCKER_COMPOSE) run --rm --no-deps app
5355

@@ -94,9 +96,9 @@ help: ## Show this menu
9496
@echo
9597
@echo ' 📑 Logs are stored in $(MAKE_LOGFILE)'
9698
@echo
97-
@echo ' 📦 Package php-cs-fixer-config (github.com/wayofdev/php-cs-fixer-config)'
98-
@echo ' 🤠 Makefile Author Andrij Orlenko (github.com/lotyp)'
99-
@echo ' 🏢 ${YELLOW}Org wayofdev (github.com/wayofdev)${RST}'
99+
@echo ' 📦 Package php-cs-fixer-config (https://github.com/wayofdev/php-cs-fixer-config)'
100+
@echo ' 🤠 Makefile Author Andrij Orlenko (https://github.com/lotyp)'
101+
@echo ' 🏢 ${YELLOW}Org wayofdev (https://github.com/wayofdev)${RST}'
100102
@echo
101103
.PHONY: help
102104

@@ -140,6 +142,10 @@ down: # Stops and removes containers of this project
140142
$(DOCKER_COMPOSE) down --remove-orphans --volumes
141143
.PHONY: down
142144

145+
stop: ## Stops all containers, without removing them
146+
$(DOCKER_COMPOSE) stop
147+
.PHONY: stop
148+
143149
restart: down up ## Runs down and up commands
144150
.PHONY: restart
145151

@@ -267,10 +273,17 @@ infect-ci: ## Runs infection – mutation testing framework with github output (
267273
$(APP_COMPOSER) infect:ci
268274
.PHONY: lint-infect-ci
269275

270-
test: ## Run project php-unit and pest tests
276+
test: test-unit test-arch ## Run project php-unit and pest tests
277+
.PHONY: test
278+
279+
test-unit: ## Run project php-unit tests
271280
$(APP_COMPOSER) test
272281
.PHONY: test
273282

283+
test-arch: ## Run project pest tests with architecture checks
284+
$(APP_COMPOSER) test:arch
285+
.PHONY: test-arch
286+
274287
test-cc: ## Run project php-unit and pest tests in coverage mode and build report
275288
$(APP_COMPOSER) test:cc
276289
.PHONY: test-cc

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,30 @@ composer req --dev wayofdev/cs-fixer-config
7373

7474
```php
7575
<?php
76-
76+
7777
declare(strict_types=1);
78-
78+
7979
use WayOfDev\PhpCsFixer\Config\ConfigBuilder;
8080
use WayOfDev\PhpCsFixer\Config\RuleSets\DefaultSet;
81-
81+
8282
require_once 'vendor/autoload.php';
83-
83+
8484
$config = ConfigBuilder::createFromRuleSet(new DefaultSet())
8585
->inDir(__DIR__ . '/src')
8686
->inDir(__DIR__ . '/tests')
8787
->addFiles([__FILE__])
8888
->getConfig()
8989
;
90-
90+
9191
$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php-cs-fixer.cache');
92-
92+
9393
return $config;
9494
```
9595

9696
### → Composer Script
9797

9898
* Add `scripts` section to `composer.json`:
99-
99+
100100
```diff
101101
{
102102
"scripts": {
@@ -126,11 +126,11 @@ composer req --dev wayofdev/cs-fixer-config
126126
+prepare:
127127
+ mkdir -p .build/php-cs-fixer
128128
+.PHONY: prepare
129-
129+
130130
+lint-php: prepare ## Fixes code to follow coding standards using php-cs-fixer
131131
+ $(APP_COMPOSER) cs:fix
132132
+.PHONY: lint-php
133-
133+
134134
+lint-diff: prepare ## Runs php-cs-fixer in dry-run mode and shows diff which will by applied
135135
+ $(APP_COMPOSER) cs:diff
136136
+.PHONY: lint-diff
@@ -148,17 +148,17 @@ composer req --dev wayofdev/cs-fixer-config
148148

149149
```yaml
150150
---
151-
151+
152152
on: # yamllint disable-line rule:truthy
153153
pull_request:
154154
branches:
155155
- master
156156
push:
157157
branches:
158158
- master
159-
159+
160160
name: 🧹 Fix PHP coding standards
161-
161+
162162
jobs:
163163
coding-standards:
164164
timeout-minutes: 4
@@ -181,48 +181,48 @@ composer req --dev wayofdev/cs-fixer-config
181181
run: |
182182
git config --global core.autocrlf false
183183
git config --global core.eol lf
184-
184+
185185
- name: 🛠️ Setup PHP
186186
uses: shivammathur/setup-php@2.30.4
187187
with:
188188
php-version: ${{ matrix.php-version }}
189189
extensions: none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter
190190
ini-values: error_reporting=E_ALL
191191
coverage: none
192-
192+
193193
- name: 📦 Check out the codebase
194194
uses: actions/checkout@v4.1.5
195-
195+
196196
- name: 🛠️ Setup problem matchers
197197
run: |
198198
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
199-
199+
200200
- name: 🤖 Validate composer.json and composer.lock
201201
run: composer validate --ansi --strict
202-
202+
203203
- name: 🔍 Get composer cache directory
204204
uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0
205-
205+
206206
- name: ♻️ Restore cached dependencies installed with composer
207207
uses: actions/cache@v4.0.2
208208
with:
209209
path: ${{ env.COMPOSER_CACHE_DIR }}
210210
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
211211
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
212-
212+
213213
- name: 📥 Install "${{ matrix.dependencies }}" dependencies with composer
214214
uses: wayofdev/gh-actions/actions/composer/install@v3.1.0
215215
with:
216216
dependencies: ${{ matrix.dependencies }}
217-
217+
218218
- name: 🛠️ Prepare environment
219219
run: make prepare
220-
220+
221221
- name: 🚨 Run coding standards task
222222
run: composer cs:fix
223223
env:
224224
PHP_CS_FIXER_IGNORE_ENV: true
225-
225+
226226
- name: 📤 Commit and push changed files back to GitHub
227227
uses: stefanzweifel/git-auto-commit-action@v5.0.1
228228
with:
@@ -278,7 +278,7 @@ To use via composer script commands:
278278
* Runs php-cs-fixer in dry-run mode and shows diff which will by applied:
279279

280280
```bash
281-
make lint-diff
281+
make lint-diff
282282
```
283283

284284
<br>
@@ -320,7 +320,7 @@ You are more than welcome. Before contributing, kindly check our [contribution g
320320
* **Discord:** Join our community on [Discord](https://discord.gg/CE3TcCC5vr).
321321

322322
<p align="left">
323-
<a href="https://discord.gg/CE3TcCC5vr" target="_blank"><img alt="Codecov" src="https://img.shields.io/discord/1228506758562058391?style=for-the-badge&logo=discord&labelColor=7289d9&logoColor=white&color=39456d"></a>
323+
<a href="https://discord.gg/CE3TcCC5vr" target="_blank"><img alt="Discord Link" src="https://img.shields.io/discord/1228506758562058391?style=for-the-badge&logo=discord&labelColor=7289d9&logoColor=white&color=39456d"></a>
324324
<a href="https://x.com/intent/follow?screen_name=wayofdev" target="_blank"><img alt="Follow on Twitter (X)" src="https://img.shields.io/badge/-Follow-black?style=for-the-badge&logo=X"></a>
325325
</p>
326326

composer.json

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"phpstan/phpstan-strict-rules": "^1.6",
4040
"phpunit/phpunit": "^10.5",
4141
"psalm/plugin-phpunit": "~0.19.0",
42+
"rector/rector": "^1.1",
4243
"roave/infection-static-analysis-plugin": "^1.35",
4344
"vimeo/psalm": "^5.23.1"
4445
},
@@ -49,7 +50,7 @@
4950
},
5051
"autoload-dev": {
5152
"psr-4": {
52-
"WayOfDev\\PhpCsFixer\\Config\\Tests\\": "tests/"
53+
"WayOfDev\\Tests\\": "tests/"
5354
}
5455
},
5556
"config": {
@@ -74,19 +75,35 @@
7475
}
7576
},
7677
"scripts": {
77-
"cs:diff": "php vendor/bin/php-cs-fixer fix --dry-run -v --diff",
78-
"cs:fix": "php vendor/bin/php-cs-fixer fix -v",
79-
"infect": "XDEBUG_MODE=coverage php vendor/bin/roave-infection-static-analysis-plugin --configuration=infection.json.dist",
80-
"infect:ci": "XDEBUG_MODE=coverage php vendor/bin/roave-infection-static-analysis-plugin --ansi --configuration=infection.json.dist --logger-github --ignore-msi-with-no-mutations --only-covered",
81-
"psalm": "php vendor/bin/psalm --show-info=true",
82-
"psalm:baseline": "php vendor/bin/psalm --set-baseline=psalm-baseline.xml",
83-
"psalm:ci": "php vendor/bin/psalm --output-format=github --shepherd --show-info=false --stats --threads=4",
84-
"refactor": "php vendor/bin/rector process --config=rector.php",
85-
"refactor:ci": "php vendor/bin/rector process --config=rector.php --dry-run --ansi",
86-
"stan": "php vendor/bin/phpstan analyse --memory-limit=2G",
87-
"stan:baseline": "php vendor/bin/phpstan analyse --generate-baseline --memory-limit=2G --allow-empty-baseline",
88-
"stan:ci": "php vendor/bin/phpstan analyse --memory-limit=2G --error-format=github",
89-
"test": "XDEBUG_MODE=coverage php vendor/bin/pest",
90-
"test:cc": "XDEBUG_MODE=coverage php vendor/bin/pest --coverage --coverage-clover=.build/phpunit/logs/clover.xml"
78+
"cs:diff": "php-cs-fixer fix --dry-run -v --diff",
79+
"cs:fix": "php-cs-fixer fix -v",
80+
"infect": [
81+
"@putenv XDEBUG_MODE=coverage",
82+
"roave-infection-static-analysis-plugin"
83+
],
84+
"infect:ci": [
85+
"@putenv XDEBUG_MODE=coverage",
86+
"roave-infection-static-analysis-plugin --ansi --logger-github --ignore-msi-with-no-mutations --only-covered"
87+
],
88+
"psalm": "psalm --show-info=true",
89+
"psalm:baseline": "psalm --set-baseline=psalm-baseline.xml",
90+
"psalm:ci": "psalm --output-format=github --shepherd --show-info=false --stats --threads=4",
91+
"refactor": "rector process --config=rector.php",
92+
"refactor:ci": "rector process --config=rector.php --dry-run --ansi",
93+
"stan": "phpstan analyse --memory-limit=2G",
94+
"stan:baseline": "phpstan analyse --generate-baseline --memory-limit=2G --allow-empty-baseline",
95+
"stan:ci": "phpstan analyse --memory-limit=2G --error-format=github",
96+
"test": [
97+
"@putenv XDEBUG_MODE=coverage",
98+
"pest --color=always"
99+
],
100+
"test:arch": [
101+
"@putenv XDEBUG_MODE=coverage",
102+
"pest --color=always --configuration pest.xml.dist"
103+
],
104+
"test:cc": [
105+
"@putenv XDEBUG_MODE=coverage",
106+
"pest --coverage --coverage-clover=.build/phpunit/logs/clover.xml"
107+
]
91108
}
92109
}

0 commit comments

Comments
 (0)