Skip to content

Commit deb6fd6

Browse files
authored
Bump nikic/php-parser to ^5.6.2 and Fix AttributeGroupNewLiner for already has new line (#7531)
* Bump nikic/php-parser to ^5.6.2 and Fix AttributeGroupNewLiner for already has new line * clean up * clean up * clean up * comment
1 parent 6602925 commit deb6fd6

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"doctrine/inflector": "^2.1",
2121
"illuminate/container": "^11.46",
2222
"nette/utils": "^4.0",
23-
"nikic/php-parser": "^5.6.1",
23+
"nikic/php-parser": "^5.6.2",
2424
"ondram/ci-detector": "^4.2",
2525
"phpstan/phpdoc-parser": "^2.3",
2626
"phpstan/phpstan": "^2.1.26",

rules-tests/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector/Fixture/do_not_remove_parameter_attribute.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromo
2525
final class DoNotRemoveParameterAttribute
2626
{
2727
public function __construct(
28-
#[\SensitiveParameter]private string $password
28+
#[\SensitiveParameter] private string $password
2929
)
3030
{
3131
}

rules/Php81/NodeManipulator/AttributeGroupNewLiner.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,15 @@ public function newLine(File $file, Node $node): void
4848
break;
4949
}
5050

51-
if (trim($oldTokens[$startTokenPos + $iteration + 1]->text ?? '') === '') {
52-
$space = ltrim($oldTokens[$startTokenPos + $iteration + 1]->text ?? '', "\r\n");
51+
$nextTokenText = $oldTokens[$startTokenPos + $iteration + 1]->text ?? '';
52+
if (trim($nextTokenText) === '') {
53+
// when trimmed is empty string, but original text contains new line
54+
// no need to add another new line
55+
if (str_contains($nextTokenText, "\n") || str_contains($nextTokenText, "\r")) {
56+
break;
57+
}
58+
59+
$space = ltrim($nextTokenText, "\r\n");
5360
} elseif (trim($oldTokens[$startTokenPos - 1]->text ?? '') === '') {
5461
$space = ltrim($oldTokens[$startTokenPos - 1]->text ?? '', "\r\n");
5562
} else {

0 commit comments

Comments
 (0)