From 707bd56cf47cdd80dd929d85b38894e5882f320a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 22 Oct 2025 09:18:53 +0700 Subject: [PATCH 1/5] Bump nikic/php-parser to ^5.6.2 and Fix AttributeGroupNewLiner for already has new line --- composer.json | 2 +- .../Fixture/do_not_remove_parameter_attribute.php.inc | 2 +- rules/Php81/NodeManipulator/AttributeGroupNewLiner.php | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 135e20db25f..33e4d87ee0a 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "doctrine/inflector": "^2.1", "illuminate/container": "^11.46", "nette/utils": "^4.0", - "nikic/php-parser": "^5.6.1", + "nikic/php-parser": "^5.6.2", "ondram/ci-detector": "^4.2", "phpstan/phpdoc-parser": "^2.3", "phpstan/phpstan": "^2.1.26", diff --git a/rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/do_not_remove_parameter_attribute.php.inc b/rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/do_not_remove_parameter_attribute.php.inc index dfb36b5303a..ddf318dcaaf 100644 --- a/rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/do_not_remove_parameter_attribute.php.inc +++ b/rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/do_not_remove_parameter_attribute.php.inc @@ -25,7 +25,7 @@ namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromo final class DoNotRemoveParameterAttribute { public function __construct( - #[\SensitiveParameter]private string $password + #[\SensitiveParameter] private string $password ) { } diff --git a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php index 7de40a8f287..0815bf7066a 100644 --- a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php +++ b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php @@ -48,8 +48,14 @@ public function newLine(File $file, Node $node): void break; } - if (trim($oldTokens[$startTokenPos + $iteration + 1]->text ?? '') === '') { - $space = ltrim($oldTokens[$startTokenPos + $iteration + 1]->text ?? '', "\r\n"); + $nextTokenText = $oldTokens[$startTokenPos + $iteration + 1]->text ?? ''; + if (str_starts_with($nextTokenText, "\n") || str_starts_with($nextTokenText, "\r")) { + // already has newline + break; + } + + if (trim($nextTokenText) === '') { + $space = ltrim($nextTokenText, "\r\n"); } elseif (trim($oldTokens[$startTokenPos - 1]->text ?? '') === '') { $space = ltrim($oldTokens[$startTokenPos - 1]->text ?? '', "\r\n"); } else { From cb3f65e5a5b1b212f6f192755115643251b71a04 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 22 Oct 2025 09:24:00 +0700 Subject: [PATCH 2/5] clean up --- rules/Php81/NodeManipulator/AttributeGroupNewLiner.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php index 0815bf7066a..d16b315f830 100644 --- a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php +++ b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php @@ -49,8 +49,8 @@ public function newLine(File $file, Node $node): void } $nextTokenText = $oldTokens[$startTokenPos + $iteration + 1]->text ?? ''; - if (str_starts_with($nextTokenText, "\n") || str_starts_with($nextTokenText, "\r")) { - // already has newline + // when trimmed is empty string, but it contains new line + if (trim($nextTokenText) === '' && str_contains($nextTokenText, "\n")) { break; } From a13d7a6d74dfd019930374b6d967cebb1dfa8d47 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 22 Oct 2025 09:27:53 +0700 Subject: [PATCH 3/5] clean up --- rules/Php81/NodeManipulator/AttributeGroupNewLiner.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php index d16b315f830..d97fa225fff 100644 --- a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php +++ b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php @@ -49,12 +49,12 @@ public function newLine(File $file, Node $node): void } $nextTokenText = $oldTokens[$startTokenPos + $iteration + 1]->text ?? ''; - // when trimmed is empty string, but it contains new line - if (trim($nextTokenText) === '' && str_contains($nextTokenText, "\n")) { - break; - } - if (trim($nextTokenText) === '') { + // when trimmed is empty string, but it contains new line + if (str_contains($nextTokenText, "\n") || str_contains($nextTokenText, "\r")) { + break; + } + $space = ltrim($nextTokenText, "\r\n"); } elseif (trim($oldTokens[$startTokenPos - 1]->text ?? '') === '') { $space = ltrim($oldTokens[$startTokenPos - 1]->text ?? '', "\r\n"); From 9660ad6758b3cf8cd525a0722dba9c9bcdd3fae6 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 22 Oct 2025 09:28:15 +0700 Subject: [PATCH 4/5] clean up --- rules/Php81/NodeManipulator/AttributeGroupNewLiner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php index d97fa225fff..40421e27dce 100644 --- a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php +++ b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php @@ -50,7 +50,7 @@ public function newLine(File $file, Node $node): void $nextTokenText = $oldTokens[$startTokenPos + $iteration + 1]->text ?? ''; if (trim($nextTokenText) === '') { - // when trimmed is empty string, but it contains new line + // when trimmed is empty string, but original text contains new line if (str_contains($nextTokenText, "\n") || str_contains($nextTokenText, "\r")) { break; } From 6af5c8a05e2c7d50209abf7d6ffe7d2a673b11df Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 22 Oct 2025 09:29:13 +0700 Subject: [PATCH 5/5] comment --- rules/Php81/NodeManipulator/AttributeGroupNewLiner.php | 1 + 1 file changed, 1 insertion(+) diff --git a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php index 40421e27dce..93a0eccaf41 100644 --- a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php +++ b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php @@ -51,6 +51,7 @@ public function newLine(File $file, Node $node): void $nextTokenText = $oldTokens[$startTokenPos + $iteration + 1]->text ?? ''; if (trim($nextTokenText) === '') { // when trimmed is empty string, but original text contains new line + // no need to add another new line if (str_contains($nextTokenText, "\n") || str_contains($nextTokenText, "\r")) { break; }