Skip to content

Commit d3b6b3e

Browse files
authored
Enhancement: Run friendsofphp/php-cs-fixer on GitHub Actions
Co-authored-by: Markus Staab <[email protected]> Closes phpGH-559.
1 parent e45bf2b commit d3b6b3e

File tree

7 files changed

+2181
-2
lines changed

7 files changed

+2181
-2
lines changed

.github/CONTRIBUTING.md

+13
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ about what you're working on, you can contact us via the
6767
```
6868

6969
to check your change doesn't break other features.
70+
- Run
71+
72+
```
73+
make coding-standards
74+
```
75+
76+
to automatically fix coding standard issues.
7077
- Review the change once more just before submitting it.
7178

7279
## What happens after submitting contribution?
@@ -121,6 +128,12 @@ Having said that, here are the organizational rules:
121128
make tests
122129
```
123130

131+
5. Fix coding standard issues before committing code. To do so use
132+
133+
```
134+
make coding-standards
135+
```
136+
124137
6. Use reasonable commit messages.
125138

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

.github/workflows/integrate.yaml

+43
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,49 @@ on:
99
- "master"
1010

1111
jobs:
12+
coding-standards:
13+
name: "Coding Standards"
14+
15+
runs-on: "ubuntu-latest"
16+
17+
strategy:
18+
matrix:
19+
php-version:
20+
- "7.3"
21+
22+
steps:
23+
- name: "Checkout"
24+
uses: "actions/checkout@v3"
25+
26+
- name: "Set up PHP"
27+
uses: "shivammathur/setup-php@v2"
28+
with:
29+
coverage: "none"
30+
extensions: "none, json, mbstring, tokenizer"
31+
php-version: "${{ matrix.php-version }}"
32+
33+
- name: "Set up problem matchers for PHP"
34+
run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\""
35+
36+
- name: "Validate composer.json and composer.lock"
37+
run: "composer validate --ansi --strict"
38+
39+
- name: "Determine composer cache directory"
40+
run: "echo \"COMPOSER_CACHE_DIR=$(composer config cache-dir)\" >> $GITHUB_ENV"
41+
42+
- name: "Cache dependencies installed with composer"
43+
uses: "actions/cache@v3"
44+
with:
45+
path: "${{ env.COMPOSER_CACHE_DIR }}"
46+
key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.lock') }}"
47+
restore-keys: "php-${{ matrix.php-version }}-composer-"
48+
49+
- name: "Install dependencies with composer"
50+
run: "composer install --ansi --no-interaction --no-progress"
51+
52+
- name: "Run friendsofphp/php-cs-fixer"
53+
run: "vendor/bin/php-cs-fixer fix --ansi --config=.php-cs-fixer.php --diff --dry-run --verbose"
54+
1255
tests:
1356
name: "Tests"
1457

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ backend/mirror.gif
44
backend/mirror.png
55
backend/mirror.jpg
66
backend/GeoIP.dat
7+
vendor/
78
.idea
89
.DS_Store
910
.DS_Store?
11+
.php-cs-fixer.cache

.php-cs-fixer.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()->in(__DIR__);
4+
5+
$config = new PhpCsFixer\Config();
6+
7+
$finder = $config->getFinder()
8+
->ignoreDotFiles(false)
9+
->in(__DIR__)
10+
->name(__FILE__);
11+
12+
$config->setRules([]);
13+
14+
return $config;

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
help: ## Displays this list of targets with descriptions
33
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'
44

5+
.PHONY: coding-standards
6+
coding-standards: vendor ## Fixes code style issues with friendsofphp/php-cs-fixer
7+
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --verbose
8+
59
.PHONY: tests
610
tests: ## Runs tests
711
php tests/run-tests.php -j3 -q
12+
13+
vendor: composer.json composer.lock
14+
composer validate --strict
15+
composer install --no-interaction --no-progress

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"require": {
1111
"php": "^7.3"
1212
},
13+
"require-dev": {
14+
"friendsofphp/php-cs-fixer": "^3.4.0"
15+
},
1316
"autoload": {
1417
"psr-4": {
1518
"phpweb\\": "src/"

0 commit comments

Comments
 (0)