Skip to content

Commit ba6f4cb

Browse files
committed
feat: implement php-cs
Signed-off-by: Vitor Mattos <[email protected]>
1 parent 9df2555 commit ba6f4cb

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

.github/workflows/lint-php-cs.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Lint php-cs
2+
3+
on: pull_request
4+
5+
permissions:
6+
contents: read
7+
8+
concurrency:
9+
group: lint-php-cs-${{ github.head_ref || github.run_id }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
php:
18+
- "8.1"
19+
- "8.2"
20+
- "8.3"
21+
- "8.4"
22+
23+
name: php-cs
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
28+
with:
29+
persist-credentials: false
30+
31+
- name: Set up php${{ matrix.php }}
32+
uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4
33+
with:
34+
php-version: ${{ matrix.php }}
35+
coverage: none
36+
ini-file: development
37+
38+
- name: Get composer cache directory
39+
id: composer-cache
40+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
41+
42+
- name: Cache composer cache
43+
uses: actions/cache@v4
44+
with:
45+
path: ${{ steps.composer-cache.outputs.dir }}
46+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
47+
restore-keys: ${{ runner.os }}-composer-
48+
49+
- name: Install dependencies
50+
run: composer install
51+
52+
- name: Lint
53+
run: composer cs:check || ( echo 'Please run `composer run cs:fix` to format your code' && exit 1 )

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ composer.lock
33
/vendor/
44
/vendor-bin/**/vendor/
55
*.swp
6+
.php-cs-fixer.cache
67
.phpunit.result.cache
78
/tests/logs

.php-cs-fixer.dist.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
require_once './vendor-bin/coding-standard/vendor/autoload.php';
6+
7+
use PhpCsFixer\Config;
8+
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
9+
10+
$config = new Config();
11+
$config
12+
->setParallelConfig(ParallelConfigFactory::detect())
13+
->getFinder()
14+
->ignoreVCSIgnored(true)
15+
->notPath('vendor')
16+
->notPath('vendor-bin')
17+
->in(__DIR__);
18+
return $config;

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"scripts": {
3232
"bin": "echo 'bin not installed'",
3333
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './vendor-bin/*' -print0 | xargs -0 -n1 php -l",
34+
"cs:check": "php-cs-fixer fix --dry-run --diff",
35+
"cs:fix": "php-cs-fixer fix",
3436
"post-install-cmd": [
3537
"@composer bin all install --ansi",
3638
"composer dump-autoload"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"require-dev": {
3+
"friendsofphp/php-cs-fixer": "^3.86"
4+
},
5+
"config": {
6+
"platform": {
7+
"php": "8.1"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)