Skip to content

Commit

Permalink
[TypeDeclaration] Handle mix InlineHTML on FileWithoutNamespace (#3648)
Browse files Browse the repository at this point in the history
* Added failling declare-strict test

currently declare-strict is added twice

* rename fixture

* fix

* Fix phsptan

* add more fixture: only inline html

---------

Co-authored-by: Markus Staab <markus.staab@redaxo.de>
  • Loading branch information
samsonasik and staabm committed Apr 22, 2023
1 parent 0a086a8 commit 61f2c42
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use rexstan\RexStan;

?>
<div style="width: 80%; background-color: rgb(32, 43, 53)">
Hello
</div>
-----
<?php

declare(strict_types=1);

use rexstan\RexStan;
?>
<div style="width: 80%; background-color: rgb(32, 43, 53)">
Hello
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div style="width: 80%; background-color: rgb(32, 43, 53)">
Hello
</div>
-----
<?php

declare(strict_types=1);

?>
<div style="width: 80%; background-color: rgb(32, 43, 53)">
Hello
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\Node\Stmt\DeclareDeclare;
use PhpParser\Node\Stmt\Nop;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -59,6 +61,14 @@ public function beforeTraverse(array $nodes): ?array

$stmt = current($newStmts);

if ($stmt instanceof FileWithoutNamespace) {
$stmt = current($stmt->stmts);

if (! $stmt instanceof Stmt) {
return null;
}
}

// when first stmt is Declare_, verify if there is strict_types definition already,
// as multiple declare is allowed, with declare(strict_types=1) only allowed on very first stmt
if ($stmt instanceof Declare_) {
Expand Down

0 comments on commit 61f2c42

Please sign in to comment.