-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Php56] Skip AddDefaultValueForUndefinedVariableRector on has InlineH…
…TML (#757) * AddDefaultValueForUndefinedVariableRector adds variable to embedded HTML * Closes #754 * fixture * move to InlineHTMLAnalyzer * cs fix * fix Co-authored-by: Brandon Olivares <programmer2188@gmail.com>
- Loading branch information
1 parent
991ea06
commit 4520aaa
Showing
4 changed files
with
60 additions
and
9 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...ionLike/AddDefaultValueForUndefinedVariableRector/Fixture/skip_with_embedded_html.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,22 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector\Fixture; | ||
|
||
final class SkipWithEmbeddedHTML | ||
{ | ||
public function run(): void | ||
{ | ||
?> | ||
<p>Let's insert stuff here.</p> | ||
<?php | ||
if (random_int(1, 10) === 5) { | ||
$a = true; | ||
} | ||
|
||
if (isset($a)) { | ||
doStuff(); | ||
} | ||
} | ||
} | ||
|
||
?> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\NodeAnalyzer; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\FunctionLike; | ||
use PhpParser\Node\Stmt\InlineHTML; | ||
use Rector\Core\PhpParser\Node\BetterNodeFinder; | ||
|
||
final class InlineHTMLAnalyzer | ||
{ | ||
public function __construct( | ||
private BetterNodeFinder $betterNodeFinder | ||
) { | ||
} | ||
|
||
public function hasInlineHTML(Node $node): bool | ||
{ | ||
if ($node instanceof FunctionLike) { | ||
return (bool) $this->betterNodeFinder->findInstanceOf((array) $node->getStmts(), InlineHTML::class); | ||
} | ||
|
||
return (bool) $this->betterNodeFinder->findInstanceOf($node, InlineHTML::class); | ||
} | ||
} |