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
@@ -0,0 +1,33 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\NarrowObjectReturnTypeRector\Fixture;

use Rector\Tests\TypeDeclaration\Rector\ClassMethod\NarrowObjectReturnTypeRector\Source\TalkInterface;
use Rector\Tests\TypeDeclaration\Rector\ClassMethod\NarrowObjectReturnTypeRector\Source\ConferenceTalkImplementation;

final class AllowInterfaceReturnOnPrivateMethod
{
private function create(): TalkInterface
{
return new ConferenceTalkImplementation();
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\NarrowObjectReturnTypeRector\Fixture;

use Rector\Tests\TypeDeclaration\Rector\ClassMethod\NarrowObjectReturnTypeRector\Source\TalkInterface;
use Rector\Tests\TypeDeclaration\Rector\ClassMethod\NarrowObjectReturnTypeRector\Source\ConferenceTalkImplementation;

final class AllowInterfaceReturnOnPrivateMethod
{
private function create(): \Rector\Tests\TypeDeclaration\Rector\ClassMethod\NarrowObjectReturnTypeRector\Source\ConferenceTalkImplementation
{
return new ConferenceTalkImplementation();
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ public function refactor(Node $node): ?Node
}

// this rule narrows only object or class types, not interfaces
if (! $declaredTypeClassReflection->isClass()) {
// except private methods, as they are not part of contract, and not mockable from tests
if (! $declaredTypeClassReflection->isClass() && ! $node->isPrivate()) {
return null;
}
}
Expand Down