Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\

use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Source\ParentWithoutConstructor;

class RemovedEmptyConstructWhenNoParentConstruct extends ParentWithoutConstructor
final class RemovedEmptyConstructWhenNoParentConstruct extends ParentWithoutConstructor
{
public function __construct()
{
Expand All @@ -19,7 +19,7 @@ namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\

use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Source\ParentWithoutConstructor;

class RemovedEmptyConstructWhenNoParentConstruct extends ParentWithoutConstructor
final class RemovedEmptyConstructWhenNoParentConstruct extends ParentWithoutConstructor
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Fixture;

class Simple
final class Simple
{
public function __construct()
{
Expand All @@ -20,7 +20,7 @@ class Simple

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Fixture;

class Simple
final class Simple
{
public function boom()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Fixture;

abstract class SkipPublicConstructorOnAbstractClass
{
public function __construct()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector\Fixture;

/**
* child class can call parent::__construct()
*/
class SkipPublicConstructorOnNonFinalClass
{
public function __construct()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getRuleDefinition(): RuleDefinition
[
new CodeSample(
<<<'CODE_SAMPLE'
class OrphanClass
final class OrphanClass
{
public function __construct()
{
Expand All @@ -53,7 +53,7 @@ public function __construct()
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
class OrphanClass
final class OrphanClass
{
}
CODE_SAMPLE
Expand Down Expand Up @@ -115,11 +115,12 @@ public function refactor(Node $node): ?Class_

private function shouldSkipNonFinalNonPrivateClassMethod(Class_ $class, ClassMethod $classMethod): bool
{
if ($class->isFinal() || FeatureFlags::treatClassesAsFinal($class)) {
if ($class->isFinal() || $class->isAnonymous() || FeatureFlags::treatClassesAsFinal($class)) {
return false;
}

if ($classMethod->isMagic()) {
// child class can call parent::__construct()
if ($classMethod->isMagic() && ! $this->isName($classMethod, MethodName::CONSTRUCT)) {
return false;
}

Expand Down
Loading