Skip to content

Commit c552781

Browse files
authored
Merge pull request #3 from codeigniter4/fixer-workflow
2 parents 739ba4b + e149695 commit c552781

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ PHP Copy-Paste Detector analyzes your code and reports when there are blocks of
104104
more than a certain number of lines long (default: 5). In most cases this is a sign of poor
105105
code structure and an opportunity to consolidate classes or functions.
106106

107+
#### PHP CS Fixer
108+
109+
PHP CS Fixer is used to enforce coding standards. Once the rules are defined in the config file
110+
the workflow will check your code against the definitions and fail for any deviance.
111+
107112
#### PHPStan
108113

109114
*Requires **phpstan.neon.dist***
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: PHPCSFixer
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
paths:
8+
- '**.php'
9+
- '.github/workflows/phpcsfixer.yml'
10+
push:
11+
branches:
12+
- develop
13+
paths:
14+
- '**.php'
15+
- '.github/workflows/phpcsfixer.yml'
16+
17+
jobs:
18+
build:
19+
name: PHP ${{ matrix.php-versions }} Coding Standards
20+
runs-on: ubuntu-latest
21+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
php-versions: ['7.3', '7.4', '8.0']
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
31+
- name: Set up PHP
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: ${{ matrix.php-versions }}
35+
extensions: json, tokenizer
36+
coverage: none
37+
env:
38+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Get composer cache directory
41+
id: composer-cache
42+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
43+
44+
- name: Cache composer dependencies
45+
uses: actions/cache@v2
46+
with:
47+
path: ${{ steps.composer-cache.outputs.dir }}
48+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
49+
restore-keys: ${{ runner.os }}-composer-
50+
51+
- name: Install dependencies
52+
run: |
53+
composer -q config -g github-oauth.github.com "${{ secrets.GITHUB_TOKEN }}"
54+
if [ -f composer.lock ]; then
55+
composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
56+
else
57+
composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
58+
fi
59+
60+
- name: Check code for standards compliance
61+
run: vendor/bin/php-cs-fixer fix --verbose --ansi --dry-run --using-cache=no --diff

src/.php-cs-fixer.dist.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use CodeIgniter\CodingStandard\CodeIgniter4;
4+
use Nexus\CsConfig\Factory;
5+
use PhpCsFixer\Finder;
6+
7+
$finder = Finder::create()
8+
->files()
9+
->in([
10+
__DIR__ . '/app',
11+
__DIR__ . '/tests',
12+
])
13+
->exclude('build')
14+
->append([__FILE__]);
15+
16+
$overrides = [];
17+
18+
$options = [
19+
'finder' => $finder,
20+
'cacheFile' => 'build/.php-cs-fixer.cache',
21+
];
22+
23+
return Factory::create(new CodeIgniter4(), $overrides, $options)->forProjects();

0 commit comments

Comments
 (0)