From fc33aa98c54748e56fdca4cac37ec26a0e49012e Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 2 Oct 2025 10:57:48 +0200 Subject: [PATCH 1/4] feat: add `logical_operators` as a required rule Signed-off-by: Ferdinand Thiessen --- CHANGELOG.md | 15 +++++++++++++++ composer.json | 2 +- src/Config.php | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e111186..e636d09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,21 @@ # Changelog All notable changes to this project will be documented in this file. +## 1.5.0 - UNRELEASED +### Notes +The `logical_operators` rule is considered risky as operators `and` and `&&` +have different precedence and in rare cases the logic of existing code could change. +So to run this new version of the configuration, you need to adjust your composer scripts like this: + +```diff +- "cs:check": "php-cs-fixer fix --dry-run --diff", ++ "cs:check": "php-cs-fixer fix --dry-run --allow-risky yes --diff", + "cs:fix": "php-cs-fixer fix", +``` + +### Added +- `logical_operators`: Disallow `and` and `or` operator in favor of `&&` and `||`. + ## 1.4.0 — 2025-07-19 ### Added * `no_whitespace_in_blank_line`: Remove trailing whitespace at the end of blank lines diff --git a/composer.json b/composer.json index 631f445..65f98da 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ } }, "scripts": { - "cs:check": "php-cs-fixer fix --dry-run --diff", + "cs:check": "php-cs-fixer fix --dry-run --allow-risky yes --diff", "cs:fix": "php-cs-fixer fix", "lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l" } diff --git a/src/Config.php b/src/Config.php index beb5854..29d7532 100644 --- a/src/Config.php +++ b/src/Config.php @@ -41,6 +41,7 @@ public function getRules() : array { 'indentation_type' => true, 'line_ending' => true, 'list_syntax' => true, + 'logical_operators' => true, 'lowercase_cast' => true, 'lowercase_keywords' => true, 'method_argument_space' => [ From 79692856a7690896c8c7f0d6115b42aa4f5a742a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 6 Oct 2025 12:41:23 +0200 Subject: [PATCH 2/4] fix: Define risky by default and only use the rule then Signed-off-by: Joas Schilling --- src/Config.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Config.php b/src/Config.php index 29d7532..a37568c 100644 --- a/src/Config.php +++ b/src/Config.php @@ -8,14 +8,15 @@ use PhpCsFixerCustomFixers; class Config extends Base { - public function __construct($name = 'default') { + public function __construct($name = 'default', bool $allowRisky = true) { parent::__construct($name); $this->setIndent("\t"); $this->registerCustomFixers(new PhpCsFixerCustomFixers\Fixers()); + $this->setRiskyAllowed($allowRisky); } public function getRules() : array { - return [ + $rules = [ '@PSR1' => true, '@PSR2' => true, 'align_multiline_comment' => true, @@ -41,7 +42,6 @@ public function getRules() : array { 'indentation_type' => true, 'line_ending' => true, 'list_syntax' => true, - 'logical_operators' => true, 'lowercase_cast' => true, 'lowercase_keywords' => true, 'method_argument_space' => [ @@ -85,5 +85,11 @@ public function getRules() : array { 'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false], PhpCsFixerCustomFixers\Fixer\MultilinePromotedPropertiesFixer::name() => true, ]; + + if ($this->getRiskyAllowed()) { + $rules['logical_operators'] = true; + } + + return $rules; } } From f96c9adce01c4e9374d4f8c19a93c8480d1c1952 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 6 Oct 2025 13:39:55 +0200 Subject: [PATCH 3/4] docs: Adjust note to match again Signed-off-by: Joas Schilling --- CHANGELOG.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e636d09..698a605 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,15 +3,10 @@ All notable changes to this project will be documented in this file. ## 1.5.0 - UNRELEASED ### Notes -The `logical_operators` rule is considered risky as operators `and` and `&&` -have different precedence and in rare cases the logic of existing code could change. -So to run this new version of the configuration, you need to adjust your composer scripts like this: - -```diff -- "cs:check": "php-cs-fixer fix --dry-run --diff", -+ "cs:check": "php-cs-fixer fix --dry-run --allow-risky yes --diff", - "cs:fix": "php-cs-fixer fix", -``` +- Risky mode is enabled by default + The `logical_operators` rule is considered risky as operators `and` and `&&` + have different precedence and in rare cases the logic of existing code could change. + In order to run those correctly by default, the risky flag is default enabled for our config. ### Added - `logical_operators`: Disallow `and` and `or` operator in favor of `&&` and `||`. From b1cee961eba3dee17a091f23ee31ee33c705cd76 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 6 Oct 2025 13:41:02 +0200 Subject: [PATCH 4/4] fix: Don't specify risky manually Signed-off-by: Joas Schilling --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 65f98da..631f445 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ } }, "scripts": { - "cs:check": "php-cs-fixer fix --dry-run --allow-risky yes --diff", + "cs:check": "php-cs-fixer fix --dry-run --diff", "cs:fix": "php-cs-fixer fix", "lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l" }