Skip to content

Commit

Permalink
update php-cs-fixer configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmajor committed Jul 31, 2024
1 parent 2bd9164 commit fc71602
Show file tree
Hide file tree
Showing 772 changed files with 54,860 additions and 18,061 deletions.
37 changes: 7 additions & 30 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Get changed files
uses: dorny/paths-filter@v2
id: filter
with:
list-files: shell
base: ${{ github.ref }}
filters: |
addedOrModified:
- added|modified: '**.php'
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
if: ${{ steps.filter.outputs.addedOrModified == 'true' }}
with:
php-version: '7.4'

- name: Get Composer cache directory path
id: composer-cache-dir
if: ${{ steps.filter.outputs.addedOrModified == 'true' }}
run: |
echo "::set-output name=path::$(composer config cache-files-dir)"
- name: Cache Composer dependencies
uses: actions/cache@v2
if: ${{ steps.filter.outputs.addedOrModified == 'true' }}
- name: PHP-CS-Fixer cache
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache-dir.outputs.path }}
key: composer-${{ hashFiles('composer.lock') }}
restore-keys: composer-

- name: Install PHP-CS-Fixer
if: ${{ steps.filter.outputs.addedOrModified == 'true' }}
run: composer global require friendsofphp/php-cs-fixer:^3.4
path: .php-cs-fixer.cache
key: php-cs-fixer-${{ github.sha }}
restore-keys: php-cs-fixer-

- name: Run PHP-CS-Fixer
if: ${{ steps.filter.outputs.addedOrModified == 'true' }}
run: composer global exec -- php-cs-fixer fix --config=.php-cs-fixer.dist.php --dry-run --diff --path-mode=intersection ${{ steps.filter.outputs.addedOrModified_files }}
run: vendor/bin/php-cs-fixer fix --dry-run --diff
222 changes: 46 additions & 176 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,186 +1,56 @@
<?php

use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

$finder = PhpCsFixer\Finder::create()
->notPath('mobile/lib/smarty')
->notPath('okapi')
->notPath('src/Libs')
->notPath('vendor')
->in(__DIR__)
->name('*.php')
->path('src')
->notPath('src/Libs')
->notPath('src/Utils/Database/Updates/template.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new PhpCsFixer\Config())
->setParallelConfig(ParallelConfigFactory::detect())
->setFinder($finder)
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,

// Alias
'backtick_to_shell_exec' => true,
'no_alias_language_construct_call' => true,
'no_mixed_echo_print' => true,

// Array Notation
'array_syntax' => ['syntax' => 'short'],
'no_multiline_whitespace_around_double_arrow' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_whitespace_before_comma_in_array' => true,
'normalize_index_brace' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'trim_array_spaces' => true,
'whitespace_after_comma_in_array' => true,

// Basic
'braces' => [
'allow_single_line_anonymous_class_with_empty_body' => true,
'allow_single_line_closure' => true,
],

// Casing
'magic_constant_casing' => true,
'magic_method_casing' => true,
'native_function_casing' => true,
'native_function_type_declaration_casing' => true,

// Cast Notation
'cast_spaces' => true,
'no_short_bool_cast' => true,
'no_unset_cast' => true,

// Class Notation
'class_attributes_separation' => true,
'ordered_class_elements' => ['order' => [
'use_trait', 'constant', 'property', 'construct', 'method', 'magic',
]],
'self_static_accessor' => true,

// Comment
'multiline_comment_opening_closing' => true,
'single_line_comment_style' => true,

// Control Structure
'include' => true,
'no_alternative_syntax' => true,
'no_superfluous_elseif' => true,
'no_trailing_comma_in_list_call' => true,
'no_unneeded_control_parentheses' => true,
'no_unneeded_curly_braces' => true,
'no_useless_else' => true,
'simplified_if_return' => true,
'switch_continue_to_break' => true,

// Function Notation
'function_typehint_space' => true,
'lambda_not_used_import' => true,
'nullable_type_declaration_for_default_null_value' => [
'use_nullable_type_declaration' => false,
],

// Import
'fully_qualified_strict_types' => true,
'global_namespace_import' => true,
'no_unused_imports' => true,
'ordered_imports' => [
'imports_order' => ['class', 'function', 'const'],
'sort_algorithm' => 'alpha',
],

// Language Construct
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'explicit_indirect_variable' => true,
'single_space_after_construct' => true,

// List Notation
'list_syntax' => ['syntax' => 'short'],

// Namespace Notation
'clean_namespace' => true,
'no_leading_namespace_whitespace' => true,

// Operator
'binary_operator_spaces' => ['operators' => ['|' => null]],
'concat_space' => ['spacing' => 'one'],
'increment_style' => ['style' => 'post'],
'not_operator_with_successor_space' => true,
'object_operator_without_whitespace' => true,
'operator_linebreak' => true,
'standardize_increment' => true,
'standardize_not_equals' => true,
'ternary_to_null_coalescing' => true,
'unary_operator_spaces' => true,

// PHP Tag
// 'echo_tag_syntax' => true,
'linebreak_after_opening_tag' => true,

// PHPDoc
'align_multiline_comment' => true,
'general_phpdoc_tag_rename' => [
'replacements' => ['inheritDocs' => 'inheritDoc'],
],
// 'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
'no_superfluous_phpdoc_tags' => [
'allow_mixed' => true,
'allow_unused_params' => true,
],
'phpdoc_align' => [
'tags' => ['param', 'property', 'property-read', 'property-write', 'return', 'throws', 'type', 'var', 'method'],
'align' => 'left',
],
'phpdoc_annotation_without_dot' => true,
'phpdoc_indent' => true,
'phpdoc_inline_tag_normalizer' => true,
'phpdoc_line_span' => ['const' => 'single', 'property' => 'single'],
'phpdoc_no_access' => true,
'phpdoc_no_alias_tag' => ['replacements' => ['type' => 'var', 'link' => 'see']],
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_return_self_reference' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
// 'phpdoc_summary' => true,
'phpdoc_tag_casing' => true,
// 'phpdoc_to_comment' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => [
'sort_algorithm' => 'none',
'null_adjustment' => 'always_last',
],
'phpdoc_var_annotation_correct_order' => true,
'phpdoc_var_without_name' => true,

// Return Notation
'no_useless_return' => true,
'simplified_null_return' => true,

// Semicolon
'multiline_whitespace_before_semicolons' => true,
'no_empty_statement' => true,
'no_singleline_whitespace_before_semicolons' => true,
'semicolon_after_instruction' => true,
'space_after_semicolon' => ['remove_in_empty_for_expressions' => true],

// String Notation
'explicit_string_variable' => true,
'heredoc_to_nowdoc' => true,
'no_binary_string' => true,
'simple_to_complex_string_variable' => true,
'single_quote' => true,
'escape_implicit_backslashes' => ['single_quoted' => false],

// Whitespace
'array_indentation' => true,
'blank_line_before_statement' => ['statements' => [
'continue', 'declare', 'do', 'exit', 'for', 'foreach', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', 'yield_from',
]],
'heredoc_indentation' => true,
'no_extra_blank_lines' => ['tokens' => [
'break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'switch', 'throw', 'use',
]],
'no_spaces_around_offset' => true,
])
->setFinder($finder);
'@PSR12:risky' => true,

// To be enabled later
'binary_operator_spaces' => false,
'blank_line_after_namespace' => false,
'blank_line_after_opening_tag' => false,
'blank_lines_before_namespace' => false,
'braces_position' => false,
'class_definition' => false,
'constant_case' => false,
'control_structure_braces' => false,
'control_structure_continuation_position' => false,
'elseif' => false,
'function_declaration' => false,
'line_ending' => false,
'lowercase_keywords' => false,
'method_argument_space' => false,
'new_with_parentheses' => false,
'no_blank_lines_after_class_opening' => false,
'no_break_comment' => false,
'no_closing_tag' => false,
'no_leading_import_slash' => false,
'no_multiple_statements_per_line' => false,
'no_spaces_after_function_name' => false,
'no_trailing_whitespace_in_comment' => false,
'no_whitespace_in_blank_line' => false,
'return_type_declaration' => false,
'short_scalar_cast' => false,
'single_blank_line_at_eof' => false,
'single_class_element_per_statement' => false,
'single_line_after_imports' => false,
'spaces_inside_parentheses' => false,
'statement_indentation' => false,
'switch_case_space' => false,
'ternary_operator_spaces' => false,
'unary_operator_spaces' => false,
'visibility_required' => false,
]);
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"ezyang/htmlpurifier": "^4.13",
"kint-php/kint": "^3.3",
"npm-asset/js-cookie": "^2.1.3",
"friendsofphp/php-cs-fixer": "^3.4"
"friendsofphp/php-cs-fixer": "^3.61"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit fc71602

Please sign in to comment.