-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Printer] Handle return array of nodes with InlineHTML (#3304)
* [Printer] Handle return array on InlineHTML * add node before with inlinehtml has open close php tag * udpate fixtue * fix reprint add node before node * Fixed * comment * [ci-review] Rector Rectify * [ci-review] Rector Rectify * tweak cache * phpstan * Fix * rename fixture * add failing fixture return array * reuse already called * previousNode param * ensure token check * decorate * Fix * service comment * rectify * loop next nodes inlinehtml * clean up * [ci-review] Rector Rectify * clean up * Final touch: move down check to ensure all next nodes InlineHTML will be re-printed when inserted in between * final touch: pass File object * comment * Final touch: remove unused count() usage * inline count() is cheap * phpstan cache * Fixture source cache Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
2c35322
commit 828ec4e
Showing
20 changed files
with
331 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...ypeDeclaration/Rector/ClassMethod/ReturnNeverTypeRector/Fixture/skip_nested_value.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...claration/Rector/ClassMethod/ReturnNeverTypeRector/FixturePHP72/skip_nested_value.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/Issues/AddNodeBeforeNodeStmt/FixtureBeforeInlineHTML/fixture2.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div><?php echo $this->filter ;?></div> | ||
----- | ||
<?php | ||
|
||
$test = 'test'; | ||
$test2 = 'test2'; | ||
?> | ||
<div><?php | ||
echo $this->filter ; | ||
?></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
tests/Issues/InsertFirstBeforeInlineHTML/Fixture/fixture.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div><?php echo $this->filter ;?></div> | ||
----- | ||
<?php | ||
|
||
echo 'this is new stmt before InlineHTML'; | ||
?> | ||
<div><?php | ||
echo $this->filter ; | ||
?></div> |
32 changes: 32 additions & 0 deletions
32
tests/Issues/InsertFirstBeforeInlineHTML/InsertFirstBeforeInlineHTMLTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\InsertFirstBeforeInlineHTML; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class InsertFirstBeforeInlineHTMLTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
/** | ||
* @return Iterator<array<string>> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
tests/Issues/InsertFirstBeforeInlineHTML/Source/InsertBeforeInlineHTMLRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\InsertFirstBeforeInlineHTML\Source; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Scalar\String_; | ||
use PhpParser\Node\Stmt\Echo_; | ||
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
class InsertBeforeInlineHTMLRector extends AbstractRector | ||
{ | ||
private array $justAdded = []; | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return new RuleDefinition('uff', []); | ||
} | ||
|
||
public function getNodeTypes(): array | ||
{ | ||
return [ | ||
FileWithoutNamespace::class, | ||
]; | ||
} | ||
|
||
public function refactor(Node $node) | ||
{ | ||
if (isset($this->justAdded[$this->file->getFilePath()])) { | ||
return null; | ||
} | ||
|
||
$echo = new Echo_([new String_('this is new stmt before InlineHTML')]); | ||
|
||
$node->stmts = array_merge( | ||
[$echo], | ||
$node->stmts | ||
); | ||
|
||
$this->justAdded[$this->file->getFilePath()] = true; | ||
|
||
return $node; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/Issues/InsertFirstBeforeInlineHTML/config/configured_rule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Core\Tests\Issues\InsertFirstBeforeInlineHTML\Source\InsertBeforeInlineHTMLRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(InsertBeforeInlineHTMLRector::class); | ||
}; |
Oops, something went wrong.