Skip to content

Commit

Permalink
[DowngradePhp73] Handle comma in array on DowngradeFlexibleHeredocSyn…
Browse files Browse the repository at this point in the history
…taxRector (#256)

* [DowngradePhp73] Handle comma in array on DowngradeFlexibleHeredocSyntaxRector

* update fixture

* fix
  • Loading branch information
samsonasik authored Dec 12, 2024
1 parent be0720b commit 0ed4563
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Rector\Tests\DowngradePhp73\Rector\String_\DowngradeFlexibleHeredocSyntaxRector\Fixture;

class CommaInArray
{
public function run()
{
$variable = [
<<<EOT
<?php
/** @readonly */
class C {
}\n
EOT,
new \stdClass()
];
}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp73\Rector\String_\DowngradeFlexibleHeredocSyntaxRector\Fixture;

class CommaInArray
{
public function run()
{
$variable = [
<<<EOT
<?php
/** @readonly */
class C {
}
EOT
,
new \stdClass()
];
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ class Fixture
SELECT *
FROM `table`
WHERE `column` = true;
SQL;
SQL
;
$this->setOnClick(<<<SQL
SELECT *
FROM `table`
WHERE `column` = true;
SQL);
SQL
);
$this->setOnClick(<<<JAVASCRIPT
document.getElementById('{$this->getHtmlId()}').value = '';
document.getElementById('{$this->getHtmlId()}').onchange();
JAVASCRIPT);
JAVASCRIPT
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ EOS

$needsDowngrade1 = sprintf(<<<EOS
test %s
EOS, 'more');
EOS
, 'more');

$needsDowngrade2 = <<<EOS
test
EOS; $z = '';
EOS
; $z = '';
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public function refactor(Node $node): ?Node
$node->setAttribute(AttributeKey::DOC_INDENTATION, '__REMOVED__');
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);

$tokens = $this->file->getOldTokens();
if (isset($tokens[$node->getEndTokenPos()], $tokens[$node->getEndTokenPos() + 1])) {
$tokens[$node->getEndTokenPos() + 1]->text = "\n" . $tokens[$node->getEndTokenPos() + 1]->text;
}

return $node;
}
}

0 comments on commit 0ed4563

Please sign in to comment.