Skip to content

Commit

Permalink
Fix and assert basic CS using CI (#9246)
Browse files Browse the repository at this point in the history
* Assert CS using CI

* fix "single_blank_line_at_eof"

* fix "statement_indentation"

* fix "switch_case_semicolon_to_colon"

* fix "control_structure_braces"

* fix "statement_indentation"

* fix "no_whitespace_in_blank_line"

* fix "no_trailing_whitespace_in_comment"

* fix "no_trailing_whitespace"

* fix "single_space_around_construct"

* fix "spaces_inside_parentheses"

* fix "ternary_operator_spaces"

* fix "trim_array_spaces"

* fix "whitespace_after_comma_in_array"

* fix "cast_spaces"

* fix "unary_operator_spaces"

* fix "no_trailing_comma_in_singleline"

* fix "ordered_imports"

* fix "no_unused_imports"

* Check composer.json format

* fix CI job name

* file header comments are not phpdoc

* fix "phpdoc_indent"

* fix "braces_position"

* fix "phpdoc_types"

* fix "no_blank_lines_after_class_opening"

* fix "no_multiple_statements_per_line"

* fix "multiline_comment_opening_closing"

* fix "single_line_empty_body"

* fix "non_printable_character"

* fix "phpdoc_trim_consecutive_blank_line_separation"

* fix "include"

* fix "no_mixed_echo_print"

---------

Co-authored-by: Aleksander Machniak <alec@alec.pl>
  • Loading branch information
mvorisek and alecpl committed Dec 16, 2023
1 parent 479ad3b commit a8707ae
Show file tree
Hide file tree
Showing 415 changed files with 4,582 additions and 4,361 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on:
push:
pull_request:

permissions:
contents: read

jobs:
cs:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]')"

name: Coding Style

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.3"
extensions: mbstring
tools: composer:v2
coverage: none
ini-values: error_reporting=E_ALL

- name: Setup composer
run: |
cp composer.json-dist composer.json
- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress

- name: Check Coding Style
run: vendor/bin/php-cs-fixer fix --dry-run --using-cache=no --diff --verbose

- name: Check composer.json format
run: composer validate --strict --no-check-lock && composer normalize --dry-run --no-check-lock
143 changes: 143 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in([__DIR__])
->exclude(['vendor']);

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PhpCsFixer' => true,
'@PHP74Migration' => true,

// required by PSR-12
'concat_space' => [
'spacing' => 'one',
],

// disable some too strict rules
'phpdoc_types_order' => [
'null_adjustment' => 'always_last',
'sort_algorithm' => 'none',
],
'single_line_throw' => false,
'yoda_style' => [
'equal' => false,
'identical' => false,
],
'native_constant_invocation' => true,
'native_function_invocation' => false,
'void_return' => false,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'exit'],
],
'combine_consecutive_issets' => false,
'combine_consecutive_unsets' => false,
'multiline_whitespace_before_semicolons' => false,
'no_superfluous_elseif' => false,
'ordered_class_elements' => false,
'php_unit_internal_class' => false,
'php_unit_test_class_requires_covers' => false,
'phpdoc_add_missing_param_annotation' => false,
'return_assignment' => false,
'comment_to_phpdoc' => false,
'general_phpdoc_annotation_remove' => [
'annotations' => ['author', 'copyright', 'throws'],
],
'nullable_type_declaration_for_default_null_value' => [
'use_nullable_type_declaration' => false,
],

// fn => without curly brackets is less readable,
// also prevent bounding of unwanted variables for GC
'use_arrow_functions' => false,

// disable too destructive formating for now
'escape_implicit_backslashes' => false,
'heredoc_to_nowdoc' => false,
'no_useless_else' => false,
'no_useless_return' => false,
'phpdoc_no_empty_return' => false,
'phpdoc_order' => false,
'phpdoc_var_annotation_correct_order' => false,
'protected_to_private' => false,
'simple_to_complex_string_variable' => false,
'single_line_comment_style' => false,

// enable some safe rules from @PHP71Migration:risky
'pow_to_exponentiation' => true,
'is_null' => true,
'modernize_types_casting' => true,
'dir_constant' => true,
'combine_nested_dirname' => true,
'non_printable_character' => [
'use_escape_sequences_in_strings' => true,
],

// TODO
'align_multiline_comment' => false,
'array_indentation' => false,
'array_syntax' => false,
'backtick_to_shell_exec' => false,
'binary_operator_spaces' => false,
'blank_line_before_statement' => false,
'class_attributes_separation' => false,
'class_definition' => false,
'class_reference_name_casing' => false,
'class_reference_name_casing' => false,
'concat_space' => false,
'constant_case' => false,
'control_structure_continuation_position' => false,
'dir_constant' => false,
'elseif' => false,
'empty_loop_condition' => false,
'explicit_indirect_variable' => false,
'explicit_string_variable' => false,
'function_declaration' => false,
'general_phpdoc_annotation_remove' => false,
'global_namespace_import' => false,
'heredoc_indentation' => false,
'increment_style' => false,
'integer_literal_case' => false,
'is_null' => false,
'list_syntax' => false,
'method_argument_space' => false,
'method_chaining_indentation' => false,
'modernize_types_casting' => false,
'native_constant_invocation' => false,
'native_type_declaration_casing' => false,
'new_with_parentheses' => false,
'no_alias_language_construct_call' => false,
'no_blank_lines_after_phpdoc' => false,
'no_break_comment' => false,
'no_empty_statement' => false,
'no_extra_blank_lines' => false,
'no_null_property_initialization' => false,
'no_superfluous_phpdoc_tags' => false,
'no_unneeded_control_parentheses' => false,
'no_useless_concat_operator' => false,
'operator_linebreak' => false,
'php_unit_method_casing' => false,
'phpdoc_align' => false,
'phpdoc_annotation_without_dot' => false,
'phpdoc_no_alias_tag' => false,
'phpdoc_no_package' => false,
'phpdoc_scalar' => false,
'phpdoc_separation' => false,
'phpdoc_single_line_var_spacing' => false,
'phpdoc_summary' => false,
'phpdoc_to_comment' => false,
'phpdoc_trim' => false,
'phpdoc_types_order' => false,
'phpdoc_var_without_name' => false,
'single_line_comment_spacing' => false,
'single_quote' => false,
'single_trait_insert_per_statement' => false,
'standardize_increment' => false,
'ternary_to_null_coalescing' => false,
'trailing_comma_in_multiline' => false,
'visibility_required' => false,
'yoda_style' => false,
])
->setFinder($finder)
->setCacheFile(sys_get_temp_dir() . '/php-cs-fixer.' . md5(__DIR__) . '.cache');
33 changes: 18 additions & 15 deletions composer.json-dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,38 @@
"name": "roundcube/roundcubemail",
"description": "The Roundcube Webmail suite",
"license": "GPL-3.0-or-later",
"repositories": [
{
"type": "composer",
"url": "https://plugins.roundcube.net"
}
],
"require": {
"php": ">=7.3.0",
"pear/pear-core-minimal": "~1.10.1",
"bacon/bacon-qr-code": "^2.0.0",
"guzzlehttp/guzzle": "^7.3.0",
"masterminds/html5": "~2.8.0",
"pear/auth_sasl": "~1.1.0",
"pear/mail_mime": "~1.10.0",
"pear/net_smtp": "~1.10.0",
"pear/crypt_gpg": "~1.6.3",
"pear/mail_mime": "~1.10.0",
"pear/net_sieve": "~1.4.5",
"pear/net_smtp": "~1.10.0",
"pear/pear-core-minimal": "~1.10.1",
"roundcube/plugin-installer": "~0.3.1",
"roundcube/rtf-html-php": "~2.1",
"masterminds/html5": "~2.8.0",
"bacon/bacon-qr-code": "^2.0.0",
"guzzlehttp/guzzle": "^7.3.0"
"roundcube/rtf-html-php": "^2.1"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.13",
"friendsofphp/php-cs-fixer": "^3.0",
"phpunit/phpunit": "^9"
},
"suggest": {
"kolab/net_ldap3": "~1.1.4 required for connecting to LDAP",
"bjeavons/zxcvbn-php": "^1.0 required for Zxcvbn password strength driver"
"bjeavons/zxcvbn-php": "^1.0 required for Zxcvbn password strength driver",
"kolab/net_ldap3": "~1.1.4 required for connecting to LDAP"
},
"repositories": [
{
"type": "composer",
"url": "https://plugins.roundcube.net"
}
],
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true,
"roundcube/plugin-installer": true
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/mimetypes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/**
/*
* Local mapping file to specify mime-types based on common file-name extensions
*
* Please note that this mapping takes precedence over the content-based mime-type detection
Expand Down
3 changes: 2 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/**

/*
+-------------------------------------------------------------------------+
| Roundcube Webmail IMAP Client |
| Version 1.7-git |
Expand Down
8 changes: 4 additions & 4 deletions installer/check.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/**
/*
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
Expand Down Expand Up @@ -173,7 +173,7 @@
echo '<br />';
}
if (empty($found_db_driver)) {
$RCI->failures++;
$RCI->failures++;
}

?>
Expand Down Expand Up @@ -224,7 +224,7 @@
$RCI->pass($var);
}
else {
$RCI->fail($var, "is '$status', should be '$val'");
$RCI->fail($var, "is '$status', should be '$val'");
}
echo '<br />';
}
Expand Down Expand Up @@ -264,7 +264,7 @@
$RCI->pass($var);
}
else {
$RCI->optfail($var, "is '$status', could be '$val'");
$RCI->optfail($var, "is '$status', could be '$val'");
}
echo '<br />';
}
Expand Down
Loading

0 comments on commit a8707ae

Please sign in to comment.