Skip to content

Commit 0ed4563

Browse files
authored
[DowngradePhp73] Handle comma in array on DowngradeFlexibleHeredocSyntaxRector (#256)
* [DowngradePhp73] Handle comma in array on DowngradeFlexibleHeredocSyntaxRector * update fixture * fix
1 parent be0720b commit 0ed4563

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp73\Rector\String_\DowngradeFlexibleHeredocSyntaxRector\Fixture;
4+
5+
class CommaInArray
6+
{
7+
public function run()
8+
{
9+
$variable = [
10+
<<<EOT
11+
<?php
12+
/** @readonly */
13+
class C {
14+
}\n
15+
EOT,
16+
new \stdClass()
17+
];
18+
}
19+
}
20+
21+
?>
22+
-----
23+
<?php
24+
25+
namespace Rector\Tests\DowngradePhp73\Rector\String_\DowngradeFlexibleHeredocSyntaxRector\Fixture;
26+
27+
class CommaInArray
28+
{
29+
public function run()
30+
{
31+
$variable = [
32+
<<<EOT
33+
<?php
34+
/** @readonly */
35+
class C {
36+
}
37+
38+
EOT
39+
,
40+
new \stdClass()
41+
];
42+
}
43+
}
44+
45+
?>

rules-tests/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector/Fixture/fixture.php.inc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,19 @@ class Fixture
3737
SELECT *
3838
FROM `table`
3939
WHERE `column` = true;
40-
SQL;
40+
SQL
41+
;
4142
$this->setOnClick(<<<SQL
4243
SELECT *
4344
FROM `table`
4445
WHERE `column` = true;
45-
SQL);
46+
SQL
47+
);
4648
$this->setOnClick(<<<JAVASCRIPT
4749
document.getElementById('{$this->getHtmlId()}').value = '';
4850
document.getElementById('{$this->getHtmlId()}').onchange();
49-
JAVASCRIPT);
51+
JAVASCRIPT
52+
);
5053
}
5154
}
5255

rules-tests/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector/Fixture/line_ends_with_newline_or_semicolon.php.inc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ EOS
4646

4747
$needsDowngrade1 = sprintf(<<<EOS
4848
test %s
49-
EOS, 'more');
49+
EOS
50+
, 'more');
5051

5152
$needsDowngrade2 = <<<EOS
5253
test
53-
EOS; $z = '';
54+
EOS
55+
; $z = '';
5456
}
5557
}
5658

rules/DowngradePhp73/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ public function refactor(Node $node): ?Node
8383
$node->setAttribute(AttributeKey::DOC_INDENTATION, '__REMOVED__');
8484
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
8585

86+
$tokens = $this->file->getOldTokens();
87+
if (isset($tokens[$node->getEndTokenPos()], $tokens[$node->getEndTokenPos() + 1])) {
88+
$tokens[$node->getEndTokenPos() + 1]->text = "\n" . $tokens[$node->getEndTokenPos() + 1]->text;
89+
}
90+
8691
return $node;
8792
}
8893
}

0 commit comments

Comments
 (0)