Skip to content

Commit e00f52f

Browse files
authored
fix: remove empty construct when parent has no construct (#7239)
* fix: remove empty construct when parent has no construct * chore: updates
1 parent 78fd064 commit e00f52f

File tree

5 files changed

+62
-5
lines changed

5 files changed

+62
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Fixture;
4+
5+
use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Source\ParentWithoutConstructor;
6+
7+
class RemovedEmptyConstructWhenNoParentConstruct extends ParentWithoutConstructor
8+
{
9+
public function __construct()
10+
{
11+
}
12+
}
13+
14+
?>
15+
-----
16+
<?php
17+
18+
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Fixture;
19+
20+
use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Source\ParentWithoutConstructor;
21+
22+
class RemovedEmptyConstructWhenNoParentConstruct extends ParentWithoutConstructor
23+
{
24+
}
25+
26+
?>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Fixture;
4+
5+
use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Source\TraitWithConstructor;
6+
7+
class SkipConstructFromTrait
8+
{
9+
use TraitWithConstructor;
10+
11+
public function __construct()
12+
{
13+
}
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Source;
6+
7+
class ParentWithoutConstructor
8+
{
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Source;
6+
7+
trait TraitWithConstructor
8+
{
9+
public function __construct()
10+
{
11+
return;
12+
}
13+
}

rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,6 @@ private function shouldSkipClassMethod(Class_ $class, ClassMethod $classMethod):
157157
return true;
158158
}
159159

160-
if ($this->isName($classMethod, MethodName::CONSTRUCT)) {
161-
// has parent class?
162-
return $class->extends instanceof FullyQualified;
163-
}
164-
165160
if ($this->isName($classMethod, MethodName::CLONE)) {
166161
return ! $classMethod->isPublic();
167162
}

0 commit comments

Comments
 (0)