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..93a0eccaf41 100644 --- a/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php +++ b/rules/Php81/NodeManipulator/AttributeGroupNewLiner.php @@ -48,8 +48,15 @@ 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 (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; + } + + $space = ltrim($nextTokenText, "\r\n"); } elseif (trim($oldTokens[$startTokenPos - 1]->text ?? '') === '') { $space = ltrim($oldTokens[$startTokenPos - 1]->text ?? '', "\r\n"); } else {