Skip to content
Closed
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 @@ -2,8 +2,10 @@

namespace Rector\Tests\TypeDeclaration\Rector\ClassLike\AddVoidReturnTypeWhereNoReturnRector\Fixture;

trait AuthUserTrait
enum EnumPublicMethod
{
case A;

public function getValues()
{
$value = 1000;
Expand All @@ -17,8 +19,10 @@ trait AuthUserTrait

namespace Rector\Tests\TypeDeclaration\Rector\ClassLike\AddVoidReturnTypeWhereNoReturnRector\Fixture;

trait AuthUserTrait
enum EnumPublicMethod
{
case A;

public function getValues(): void
{
$value = 1000;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassLike\AddVoidReturnTypeWhereNoReturnRector\Fixture;

class FinalMethodInNonFinalClass
{
final public function getValues()
{
$value = 1000;
return;
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassLike\AddVoidReturnTypeWhereNoReturnRector\Fixture;

class FinalMethodInNonFinalClass
{
final public function getValues(): void
{
$value = 1000;
return;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassLike\AddVoidReturnTypeWhereNoReturnRector\Fixture;

class SkipNonFinalPublicMethod
{
public function getValues()
{
$value = 1000;
return;
}
}

final class SkipNonFinalPublicMethodChild extends SkipNonFinalPublicMethod
{
public function getValues()
{
return [1];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassLike\AddVoidReturnTypeWhereNoReturnRector\Fixture;

trait SkipTraitPublicMethod
{
public function getValues()
{
$value = 1000;
return;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassLike\AddVoidReturnTypeWhereNoReturnRector\Fixture;

trait TraitPrivateMethod
{
private function getValues()
{
$value = 1000;
return;
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassLike\AddVoidReturnTypeWhereNoReturnRector\Fixture;

trait TraitPrivateMethod
{
private function getValues(): void
{
$value = 1000;
return;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ private function shouldSkipClassMethod(
return true;
}

if ($classMethod->isProtected()) {
return ! $isFinalClass;
// public or protected method of extendable class or trait can be overridden by child with return value
if (! $isFinalClass && ! $classMethod->isPrivate() && ! $classMethod->isFinal()) {
return true;
}

return $classReflection->isAbstract();
Expand Down
Loading