Setup php-cs-fixer

This commit is contained in:
Philipp 2021-04-06 20:00:21 +02:00
parent ae7178c042
commit 3f2d5c4111
No known key found for this signature in database
GPG key ID: 9A28B7D4FF5667BD
7 changed files with 2071 additions and 2 deletions

View file

@ -3,11 +3,11 @@ on: pull_request
jobs:
php-linters:
name: php${{ matrix.php-versions }} lint
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.3', '7.4', '8.0']
name: php${{ matrix.php-versions }} lint
steps:
- name: Checkout
uses: actions/checkout@master
@ -18,3 +18,23 @@ jobs:
coverage: none
- name: Lint
run: bin/composer.phar run lint
php-cs-fixer:
name: php-cs check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Set up php
uses: shivammathur/setup-php@master
with:
php-version: 7.2
coverage: none
tools: cs2pr
- name: Install dependencies
run: bin/composer.phar run cs:install
- name: Run coding standards check
run: |
bin/composer.phar run cs:check -- --format=checkstyle | cs2pr
bin/composer.phar run cs:check || ( echo 'Please run `bin/composer.phar run cs:fix` to format your code' && exit 1 )
shell: bash

3
.gitignore vendored
View file

@ -82,3 +82,6 @@ venv/
#Ignore temporary installed phpunit
/bin/phpunit
#Ignore cache file
.php_cs.cache

74
.php_cs.dist Normal file
View file

@ -0,0 +1,74 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/bin/dev/php-cs-fixer/vendor/autoload.php';
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->notPath('bin/dev')
->notPath('config')
->notPath('doc')
->notPath('images')
->notPath('mods')
->notPath('spec')
->notPath('vendor')
->notPath('view/asset')
->notPath('lang')
->notPath('view/smarty3/compiled');
$config = new PhpCsFixer\Config();
return $config
->setRules([
'@PSR1' => true,
'@PSR2' => true,
'@PSR12' => true,
'align_multiline_comment' => true,
'array_indentation' => true,
'array_syntax' => [
'syntax' => 'short',
],
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => [
'=>' => 'align_single_space_minimal',
'=' => 'align_single_space_minimal',
],
],
'blank_line_after_namespace' => true,
'braces' => [
'position_after_anonymous_constructs' => 'same',
'position_after_control_structures' => 'same',
'position_after_functions_and_oop_constructs' => 'next',
],
'elseif' => true,
'encoding' => true,
'full_opening_tag' => true,
'function_declaration' => [
'closure_function_spacing' => 'one',
],
'indentation_type' => true,
'line_ending' => true,
'list_syntax' => [
'syntax' => 'long',
],
'lowercase_keywords' => true,
'method_argument_space' => [],
'no_closing_tag' => true,
'no_spaces_after_function_name' => true,
'no_spaces_inside_parenthesis' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_unused_imports' => true,
'single_blank_line_at_eof' => true,
'single_class_element_per_statement' => true,
'single_import_per_statement' => true,
'single_line_after_imports' => true,
'switch_case_space' => true,
'visibility_required' => [
'elements' => ['property', 'method']
],
'new_with_braces' => true,
])
->setFinder($finder)
->setIndent("\t");

1
bin/dev/php-cs-fixer/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
vendor

View file

@ -0,0 +1,5 @@
{
"require": {
"friendsofphp/php-cs-fixer": "^2.18"
}
}

1963
bin/dev/php-cs-fixer/composer.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -129,6 +129,9 @@
},
"scripts": {
"test": "phpunit",
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './view/asset/*' -print0 | xargs -0 -n1 php -l"
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './view/asset/*' -print0 | xargs -0 -n1 php -l",
"cs:install": "@composer install --working-dir=bin/dev/php-cs-fixer",
"cs:check": ["@cs:install", "bin/dev/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff"],
"cs:fix": ["@cs:install", "bin/dev/php-cs-fixer/vendor/bin/php-cs-fixer fix"]
}
}