Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ PHP Copy-Paste Detector analyzes your code and reports when there are blocks of
more than a certain number of lines long (default: 5). In most cases this is a sign of poor
code structure and an opportunity to consolidate classes or functions.

#### PHP CS Fixer

PHP CS Fixer is used to enforce coding standards. Once the rules are defined in the config file
the workflow will check your code against the definitions and fail for any deviance.

#### PHPStan

*Requires **phpstan.neon.dist***
Expand Down
61 changes: 61 additions & 0 deletions src/.github/workflows/phpcsfixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: PHPCSFixer

on:
pull_request:
branches:
- develop
paths:
- '**.php'
- '.github/workflows/phpcsfixer.yml'
push:
branches:
- develop
paths:
- '**.php'
- '.github/workflows/phpcsfixer.yml'

jobs:
build:
name: PHP ${{ matrix.php-versions }} Coding Standards
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
strategy:
fail-fast: false
matrix:
php-versions: ['7.3', '7.4', '8.0']

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: json, tokenizer
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: |
composer -q config -g github-oauth.github.com "${{ secrets.GITHUB_TOKEN }}"
if [ -f composer.lock ]; then
composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
else
composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
fi

- name: Check code for standards compliance
run: vendor/bin/php-cs-fixer fix --verbose --ansi --dry-run --using-cache=no --diff
23 changes: 23 additions & 0 deletions src/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use CodeIgniter\CodingStandard\CodeIgniter4;
use Nexus\CsConfig\Factory;
use PhpCsFixer\Finder;

$finder = Finder::create()
->files()
->in([
__DIR__ . '/app',
__DIR__ . '/tests',
])
->exclude('build')
->append([__FILE__]);

$overrides = [];

$options = [
'finder' => $finder,
'cacheFile' => 'build/.php-cs-fixer.cache',
];

return Factory::create(new CodeIgniter4(), $overrides, $options)->forProjects();