Skip to content

Commit bfd8312

Browse files
authored
[fix] skip HTML + PHP mix in DeclareStrictTypesTestsRector to avoid mallformed code (#600)
* [fix] skip HTML + PHP mix in DeclareStrictTypesTestsRector to avoid mallformed code * cleanup RemoveOverrideFinalConstructTestCaseRector
1 parent 50cec58 commit bfd8312

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<img src="asdf">
2+
3+
<?php
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class SkipHtmlPHPMix extends TestCase
8+
{
9+
public function test()
10+
{
11+
}
12+
}

rules/CodeQuality/Rector/StmtsAwareInterface/DeclareStrictTypesTestsRector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public function beforeTraverse(array $nodes): ?array
7474
{
7575
parent::beforeTraverse($nodes);
7676

77+
if ($this->file->containsHTML()) {
78+
return null;
79+
}
80+
7781
if ($this->shouldSkipNodes($nodes, $this->file)) {
7882
return null;
7983
}

rules/PHPUnit120/Rector/Class_/RemoveOverrideFinalConstructTestCaseRector.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ public function refactor(Node $node): Node|null
7171
return null;
7272
}
7373

74-
$constructClassMethod = $node->getMethod(MethodName::CONSTRUCT);
75-
76-
if ($constructClassMethod instanceof ClassMethod) {
77-
foreach ($node->stmts as $key => $stmt) {
78-
if ($stmt instanceof ClassMethod && $this->isName($stmt, MethodName::CONSTRUCT)) {
79-
unset($node->stmts[$key]);
74+
foreach ($node->stmts as $key => $stmt) {
75+
if (! $stmt instanceof ClassMethod) {
76+
continue;
77+
}
8078

81-
$node->setAttribute('hasRemovedFinalConstruct', true);
82-
return $node;
83-
}
79+
if (! $this->isName($stmt, MethodName::CONSTRUCT)) {
80+
continue;
8481
}
82+
83+
unset($node->stmts[$key]);
84+
return $node;
8585
}
8686

8787
return null;

0 commit comments

Comments
 (0)