From 6d572ae421cb6f7d215ed83637f06de444b9b29a Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Fri, 24 Mar 2023 01:13:24 +0100 Subject: [PATCH] Add fixer to place promoted properties on a new line when there is more than 1 parameter --- CHANGELOG.md | 3 +++ composer.json | 3 ++- composer.lock | 48 +++++++++++++++++++++++++++++++++++++++++++++++- src/Config.php | 8 ++++++-- src/Rules.php | 5 +++++ 5 files changed, 63 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d492a9e..d58c20e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Enh #12: Implemented `Ely\align_multiline_parameters` fixer. - Enabled `Ely\align_multiline_parameters` for Ely.by codestyle in `['types' => false, 'defaults' => false]` mode. +- Enabled + [`PhpCsFixerCustomFixers/multiline_promoted_properties`](https://github.com/kubawerlos/php-cs-fixer-custom-fixers#multilinepromotedpropertiesfixer) + fixer for Ely.by codestyle in 2+ parameters mode. ### Fixed - Bug #10: `Ely/blank_line_before_return` don't treat interpolation curly bracket as beginning of the scope. diff --git a/composer.json b/composer.json index 598482f..839395d 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ "homepage": "https://github.com/elyby/php-code-style", "require": { "php": "^7.4 || ^8.0", - "friendsofphp/php-cs-fixer": "^3.13" + "friendsofphp/php-cs-fixer": "^3.13", + "kubawerlos/php-cs-fixer-custom-fixers": "^3.13" }, "require-dev": { "ergebnis/composer-normalize": "^2.28", diff --git a/composer.lock b/composer.lock index f72755a..48f74cd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "984ffa466fb6bc9281a36b8701147fee", + "content-hash": "9fc362b1a074bf1a33695018a2b1b198", "packages": [ { "name": "composer/pcre", @@ -462,6 +462,52 @@ ], "time": "2022-10-31T19:28:50+00:00" }, + { + "name": "kubawerlos/php-cs-fixer-custom-fixers", + "version": "v3.13.0", + "source": { + "type": "git", + "url": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers.git", + "reference": "fb53d8bbe2224383a84c71f451d76eb7bc6c8e33" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/kubawerlos/php-cs-fixer-custom-fixers/zipball/fb53d8bbe2224383a84c71f451d76eb7bc6c8e33", + "reference": "fb53d8bbe2224383a84c71f451d76eb7bc6c8e33", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "ext-tokenizer": "*", + "friendsofphp/php-cs-fixer": "^3.6.0", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.5.20" + }, + "type": "library", + "autoload": { + "psr-4": { + "PhpCsFixerCustomFixers\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kuba Werłos", + "email": "werlos@gmail.com" + } + ], + "description": "A set of custom fixers for PHP CS Fixer", + "support": { + "issues": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers/issues", + "source": "https://github.com/kubawerlos/php-cs-fixer-custom-fixers/tree/v3.13.0" + }, + "time": "2023-02-15T18:51:16+00:00" + }, { "name": "psr/cache", "version": "1.0.1", diff --git a/src/Config.php b/src/Config.php index 9d26d9d..5d3277a 100644 --- a/src/Config.php +++ b/src/Config.php @@ -3,14 +3,18 @@ declare(strict_types=1); namespace Ely\CS; +use Ely\CS\Fixers as ElyFixers; use PhpCsFixer\Config as PhpCsFixerConfig; +use PhpCsFixer\ConfigInterface as PhpCsFixerConfigInterface; +use PhpCsFixerCustomFixers\Fixers as KubawerlosFixers; class Config { - public static function create(array $overwrittenRules = []): PhpCsFixerConfig { + public static function create(array $overwrittenRules = []): PhpCsFixerConfigInterface { return (new PhpCsFixerConfig()) ->setRiskyAllowed(true) - ->registerCustomFixers(new Fixers()) + ->registerCustomFixers(new ElyFixers()) + ->registerCustomFixers(new KubawerlosFixers()) ->setRules(Rules::create($overwrittenRules)); } diff --git a/src/Rules.php b/src/Rules.php index b964a44..42b8630 100644 --- a/src/Rules.php +++ b/src/Rules.php @@ -213,6 +213,11 @@ class Rules { 'space_multiple_catch' => 'none', ], + // kubawerlos fixers + 'PhpCsFixerCustomFixers/multiline_promoted_properties' => [ + 'minimum_number_of_parameters' => 2, + ], + // Our custom or extended fixers 'Ely/align_multiline_parameters' => [ 'variables' => false,