Skip to content

Commit b8a871d

Browse files
authored
InlineHTML is an impure point
1 parent 4e4120a commit b8a871d

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

src/Analyser/ImpurePoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use PHPStan\Node\VirtualNode;
77

88
/**
9-
* @phpstan-type ImpurePointIdentifier = 'echo'|'die'|'exit'|'propertyAssign'|'methodCall'|'new'|'functionCall'|'include'|'require'|'print'|'eval'|'superglobal'|'yield'|'yieldFrom'|'static'|'global'
9+
* @phpstan-type ImpurePointIdentifier = 'echo'|'die'|'exit'|'propertyAssign'|'methodCall'|'new'|'functionCall'|'include'|'require'|'print'|'eval'|'superglobal'|'yield'|'yieldFrom'|'static'|'global'|'betweenPhpTags'
1010
* @api
1111
*/
1212
class ImpurePoint

src/Analyser/NodeScopeResolver.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
use PhpParser\Node\Stmt\For_;
4444
use PhpParser\Node\Stmt\Foreach_;
4545
use PhpParser\Node\Stmt\If_;
46+
use PhpParser\Node\Stmt\InlineHTML;
4647
use PhpParser\Node\Stmt\Return_;
4748
use PhpParser\Node\Stmt\Static_;
4849
use PhpParser\Node\Stmt\Switch_;
@@ -1804,6 +1805,12 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
18041805
$exprResult = $this->processExprNode($stmt, $stmt->expr, $scope, $nodeCallback, ExpressionContext::createDeep());
18051806
$impurePoints = $exprResult->getImpurePoints();
18061807
}
1808+
} elseif ($stmt instanceof InlineHTML) {
1809+
$hasYield = false;
1810+
$throwPoints = [];
1811+
$impurePoints = [
1812+
new ImpurePoint($scope, $stmt, 'betweenPhpTags', 'output between PHP opening and closing tags', true),
1813+
];
18071814
} elseif ($stmt instanceof Node\Stmt\Nop) {
18081815
$hasYield = false;
18091816
$throwPoints = $overridingThrowPoints ?? [];

tests/PHPStan/Rules/Pure/PureFunctionRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ public function testRule(): void
100100
'Possibly impure call to a Closure in pure function PureFunction\callsClosures().',
101101
140,
102102
],
103+
[
104+
'Impure output between PHP opening and closing tags in pure function PureFunction\justContainsInlineHtml().',
105+
160,
106+
],
103107
]);
104108
}
105109

tests/PHPStan/Rules/Pure/data/pure-function.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,16 @@ function callsPureCallableIdentifierTypeNode(callable $cb, \Closure $closure): i
151151
$cb();
152152
$closure();
153153
}
154+
155+
156+
/** @phpstan-pure */
157+
function justContainsInlineHtml()
158+
{
159+
?>
160+
</td>
161+
</tr>
162+
</table></td>
163+
</tr>
164+
</table>
165+
<?php
166+
}

0 commit comments

Comments
 (0)