From df670d5dfd1b53e5850962d78e32bc63d89b5d71 Mon Sep 17 00:00:00 2001 From: Dave van der Brugge Date: Mon, 4 Nov 2019 11:51:45 +0100 Subject: [PATCH 1/5] Git should ignore more --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 3d0b430..b34b1e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ +.idea/ .php_cs.cache + +# Libraries should ignore the lock file +composer.lock + +vendor/ From 1c6667e026e8a65b5b34a22dd32f1834f453fd1d Mon Sep 17 00:00:00 2001 From: Dave van der Brugge Date: Mon, 4 Nov 2019 12:04:03 +0100 Subject: [PATCH 2/5] Update PHP-CS-Fixer to v2.16 --- .php_cs.dist | 10 ++++++++-- composer.json | 2 +- src/PhpCsFixer/Rules.php | 32 +++++++++++++++++++------------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index 72983ea..cdfcf71 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -1,14 +1,20 @@ name('.php_cs.dist') // Fix this file as well + ->name('.php_cs.dist') // Fix this file as well ->in(__DIR__); +$overrides = [ + 'declare_strict_types' => true, +]; + return Config::create() ->setFinder($finder) ->setRiskyAllowed(true) - ->setRules(Rules::getForPhp71()); + ->setRules(Rules::getForPhp71($overrides)); diff --git a/composer.json b/composer.json index e9b077e..fea6394 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,6 @@ "minimum-stability": "stable", "require": { "php": "^7.1.3", - "friendsofphp/php-cs-fixer": "^2.15" + "friendsofphp/php-cs-fixer": "^2.16" } } diff --git a/src/PhpCsFixer/Rules.php b/src/PhpCsFixer/Rules.php index f8daeb3..f975d4a 100644 --- a/src/PhpCsFixer/Rules.php +++ b/src/PhpCsFixer/Rules.php @@ -5,7 +5,7 @@ namespace Mollie\PhpCodingStandards\PhpCsFixer; /* - * Last updated for php-cs-fixer version: 2.15 + * Last updated for php-cs-fixer version: 2.16 */ class Rules { @@ -46,10 +46,7 @@ private static function getBaseRules(): array 'align_multiline_comment' => [ 'comment_type' => 'all_multiline', ], - 'array_indentation' => true, - 'array_syntax' => [ - 'syntax' => 'short', - ], + 'array_indentation' => true, 'binary_operator_spaces' => [ 'default' => 'align_single_space_minimal', ], @@ -75,6 +72,7 @@ private static function getBaseRules(): array 'explicit_string_variable' => true, 'fully_qualified_strict_types' => true, 'function_to_constant' => true, + 'global_namespace_import' => true, // 'header_comment' => [ // Has too many issues atm // 'header' => '', // ], @@ -105,14 +103,15 @@ private static function getBaseRules(): array // TODO: Add 'use' when php-cs-fixer #3582 is fixed ], ], - 'no_null_property_initialization' => true, - 'no_superfluous_elseif' => true, - 'no_superfluous_phpdoc_tags' => true, - 'no_unset_cast' => true, - 'no_unset_on_property' => false, // It's purposely used for the side effect :( - 'no_useless_else' => true, - 'no_useless_return' => true, - 'ordered_class_elements' => [ + 'no_null_property_initialization' => true, + 'no_superfluous_elseif' => true, + 'no_superfluous_phpdoc_tags' => true, + 'no_unset_cast' => true, + 'no_unset_on_property' => false, // It's purposely used for the side effect :( + 'no_useless_else' => true, + 'no_useless_return' => true, + 'nullable_type_declaration_for_default_null_value' => true, + 'ordered_class_elements' => [ 'order' => [ 'use_trait', 'constant_public', 'constant_protected', 'constant_private', @@ -123,6 +122,12 @@ private static function getBaseRules(): array 'ordered_imports' => [ 'imports_order' => ['class', 'function', 'const'], ], + 'phpdoc_line_span' => [ + 'const' => 'single', + 'method' => 'multi', + 'property' => 'single', + ], + 'phpdoc_no_empty_return' => true, 'php_unit_construct' => true, 'php_unit_dedicate_assert_internal_type' => true, 'php_unit_method_casing' => true, @@ -149,6 +154,7 @@ private static function getBaseRules(): array 'simple_to_complex_string_variable' => true, 'simplified_null_return' => false, // Too many old code places that become implicit, also ignores doc blocks. 'single_class_element_per_statement' => true, + 'single_line_throw' => false, 'single_quote' => false, 'single_trait_insert_per_statement' => true, 'space_after_semicolon' => [ From 9b88669c4245c1eb8a86b058642f34d3ac666f26 Mon Sep 17 00:00:00 2001 From: Dave van der Brugge Date: Mon, 4 Nov 2019 12:06:58 +0100 Subject: [PATCH 3/5] License should also be in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fea6394..7f0d1f2 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "mollie/php-coding-standards", "description": "Contains PHP coding standards like rules for PHP-CS-Fixer that serves for purpose of standardization.", - "license": "proprietary", + "license": "BSD-2-Clause", "type": "library", "authors": [ { From 61c169a6848ea70f1953012ce93b93c8610efbab Mon Sep 17 00:00:00 2001 From: Dave van der Brugge Date: Mon, 4 Nov 2019 13:50:42 +0100 Subject: [PATCH 4/5] Add Travis config --- .travis.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..654fe74 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,30 @@ +language: php + +dist: xenial + +matrix: + fast_finish: true + allow_failures: + - php: nightly + include: + - php: 7.1 + - php: 7.2 + - php: 7.3 + - php: nightly + +sudo: false + +cache: + directories: + - "$HOME/.composer/cache" + +env: + - COMPOSER_NO_INTERACTION=1 + +install: + - travis_retry composer install --no-suggest + +script: + - composer validate --strict + - find src -name *.php | xargs -n 1 php -l + - vendor/bin/php-cs-fixer fix --dry-run From 4c84bdf55a9684411f069f044580f979f7db5f9c Mon Sep 17 00:00:00 2001 From: Dave van der Brugge Date: Mon, 4 Nov 2019 14:19:25 +0100 Subject: [PATCH 5/5] Also enable php: 7.4snapshot on Travis as 'nightly' is already 8.0 --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 654fe74..3b059a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,13 @@ dist: xenial matrix: fast_finish: true allow_failures: + - php: 7.4snapshot - php: nightly include: - php: 7.1 - php: 7.2 - php: 7.3 + - php: 7.4snapshot - php: nightly sudo: false @@ -27,4 +29,4 @@ install: script: - composer validate --strict - find src -name *.php | xargs -n 1 php -l - - vendor/bin/php-cs-fixer fix --dry-run + - vendor/bin/php-cs-fixer fix -v --dry-run