Skip to content

Commit b09b69b

Browse files
Add linting to pipeline
1 parent 39dea7c commit b09b69b

File tree

3 files changed

+115
-10
lines changed

3 files changed

+115
-10
lines changed

.github/workflows/main.yml

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
jobs:
1111
unit:
12-
name: "Unit and mutation tests for PHP ${{ matrix.php-version }}"
12+
name: "Unit and mutation testing"
1313
runs-on: ${{ matrix.os }}
1414
continue-on-error: true
1515

@@ -35,24 +35,19 @@ jobs:
3535
ini-values: memory_limit=512M, xdebug.mode=off
3636
tools: composer:${{ env.COMPOSER_VERSION }}
3737

38-
- name: Get composer cache directory
38+
- name: Get Composer cache directory
3939
id: composer-cache
4040
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
4141

42-
- name: Cache dependencies
42+
- name: Restore Composer cache
4343
uses: actions/cache@v2
4444
with:
4545
path: ${{ steps.composer-cache.outputs.dir }}
4646
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('composer.*') }}
47-
restore-keys: |
48-
composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('composer.*') }}-
49-
composer-${{ runner.os }}-${{ matrix.php-version }}-
50-
composer-${{ runner.os }}-
51-
composer-
47+
restore-keys: composer-${{ runner.os }}-${{ matrix.php-version }}-
5248

5349
- name: Install dependencies
54-
run: |
55-
composer install --no-interaction --prefer-dist --no-progress
50+
run: composer install --no-interaction --prefer-dist --no-progress
5651

5752
- name: Run unit tests
5853
run: |
@@ -61,3 +56,44 @@ jobs:
6156
6257
- name: Run mutation tests
6358
run: XDEBUG_MODE=coverage php vendor/bin/infection --show-mutations --min-msi=${{ env.MINIMUM_MSI_PERCENTAGE }} --threads=4
59+
60+
lint:
61+
name: "Linting"
62+
runs-on: ${{ matrix.os }}
63+
continue-on-error: true
64+
65+
strategy:
66+
matrix:
67+
os: [ "ubuntu-latest" ]
68+
php-version: [ "8.1" ]
69+
70+
env:
71+
COMPOSER_VERSION: 2
72+
PHP_CS_FIXER_CACHE_FILE: .php-cs-fixer.cache
73+
74+
steps:
75+
- name: Checkout repository
76+
uses: actions/checkout@v3
77+
78+
- name: Setup PHP
79+
uses: shivammathur/setup-php@v2
80+
with:
81+
php-version: ${{ matrix.php-version }}
82+
83+
- name: Get Composer cache directory
84+
id: composer-cache
85+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
86+
87+
- name: Restore Composer cache
88+
uses: actions/cache@v2
89+
with:
90+
path: ${{ steps.composer-cache.outputs.dir }}
91+
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('composer.*') }}
92+
restore-keys: composer-${{ runner.os }}-${{ matrix.php-version }}-
93+
94+
- name: Install dependencies
95+
run: |
96+
composer install --no-interaction --prefer-dist --no-progress
97+
98+
- name: Run PHP-CS-Fixer
99+
run: php vendor/bin/php-cs-fixer fix --config .php-cs-fixer.dist.php --verbose --dry-run

.php-cs-fixer.dist.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
use PhpCsFixer\Config;
4+
use PhpCsFixer\Finder;
5+
6+
$finder = Finder::create()
7+
->in([__DIR__ . '/src', __DIR__ . '/tests'])
8+
->name('*php');
9+
10+
return (new Config())
11+
->setRules([
12+
'@PSR12' => true,
13+
'align_multiline_comment' => true,
14+
'array_indentation' => true,
15+
'blank_line_before_statement' => [
16+
'statements' => [
17+
'break',
18+
'continue',
19+
'declare',
20+
'do',
21+
'for',
22+
'foreach',
23+
'if',
24+
'include',
25+
'include_once',
26+
'require',
27+
'require_once',
28+
'return',
29+
'switch',
30+
'throw',
31+
'try',
32+
'while',
33+
'yield',
34+
],
35+
],
36+
'concat_space' => ['spacing' => 'one'],
37+
'fully_qualified_strict_types' => true,
38+
'list_syntax' => [
39+
'syntax' => 'short',
40+
],
41+
'no_unused_imports' => true,
42+
'no_useless_else' => true,
43+
'no_useless_return' => true,
44+
'nullable_type_declaration_for_default_null_value' => true,
45+
'ordered_class_elements' => true,
46+
'ordered_imports' => true,
47+
'phpdoc_align' => [
48+
'align' => 'left',
49+
],
50+
'phpdoc_scalar' => true,
51+
'php_unit_method_casing' => [
52+
'case' => 'snake_case',
53+
],
54+
'phpdoc_order_by_value' => [
55+
'annotations' => ['covers'],
56+
],
57+
'phpdoc_no_empty_return' => true,
58+
'phpdoc_order' => true,
59+
'return_assignment' => true,
60+
'self_static_accessor' => true,
61+
'simplified_if_return' => true,
62+
'trailing_comma_in_multiline' => true
63+
])
64+
->setFinder($finder)
65+
->setCacheFile(__DIR__ . '/.php-cs-fixer.cache')
66+
->setUsingCache(true);

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
"infection/extension-installer": true
7272
}
7373
},
74+
"scripts": {
75+
"php-cs-fixer": "php-cs-fixer fix --config .php-cs-fixer.dist.php --verbose"
76+
},
7477
"minimum-stability": "stable",
7578
"prefer-stable": true
7679
}

0 commit comments

Comments
 (0)