Skip to content

Commit

Permalink
[AutoImport] Skip first stmt is InlineHTML (#3288)
Browse files Browse the repository at this point in the history
* [AutoImport] Skip first stmt is InlineHTML

* Fixed 🎉

* final touch: verify new stmts too

* final touch: test first stmt is not inlineHTMl
  • Loading branch information
samsonasik committed Jan 15, 2023
1 parent 836fa59 commit 8f4642c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/PostRector/Rector/NameImportingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\InlineHTML;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Use_;
use PHPStan\Reflection\ReflectionProvider;
Expand Down Expand Up @@ -53,6 +54,16 @@ public function enterNode(Node $node): ?Node
return null;
}

$currentStmt = current($file->getOldStmts());
if ($currentStmt instanceof InlineHTML) {
return null;
}

$currentStmt = current($file->getNewStmts());
if ($currentStmt instanceof InlineHTML) {
return null;
}

if ($node instanceof Name) {
return $this->processNodeName($node, $file);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
$a = '';
?>
<div></div>
<?php

require(__DIR__ . '/../../vendor/autoload.php');

$dotenv = \Dotenv\Dotenv::createUnsafeMutable(__DIR__ . '/../../');
$dotenv->load();
-----
<?php
use Dotenv\Dotenv;
$a = '';
?>
<div></div>
<?php

require(__DIR__ . '/../../vendor/autoload.php');

$dotenv = Dotenv::createUnsafeMutable(__DIR__ . '/../../');
$dotenv->load();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/local/bin/php -q

<?php

require(__DIR__ . '/../../vendor/autoload.php');

$dotenv = \Dotenv\Dotenv::createUnsafeMutable(__DIR__ . '/../../');
$dotenv->load();
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div>
some text
</div>

<?php

require(__DIR__ . '/../../vendor/autoload.php');

$dotenv = \Dotenv\Dotenv::createUnsafeMutable(__DIR__ . '/../../');
$dotenv->load();

0 comments on commit 8f4642c

Please sign in to comment.