mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-21 01:41:00 +01:00
Test case to demonstrate how refactoring order creates incompatible return types
This commit is contained in:
parent
1a197771cc
commit
c9d96c9cb0
@ -21,6 +21,7 @@ final class CovarianceTest extends AbstractRectorTestCase
|
||||
public function provideDataForTest(): iterable
|
||||
{
|
||||
yield [__DIR__ . '/Fixture/nikic/inheritance_covariance.php.inc'];
|
||||
yield [__DIR__ . '/Fixture/nikic/inheritance_covariance_order.php.inc'];
|
||||
yield [__DIR__ . '/Fixture/Covariance/return_interface_to_class.php.inc'];
|
||||
yield [__DIR__ . '/Fixture/Covariance/return_nullable_with_parent_interface.php.inc'];
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\ReturnTypeDeclarationRector\Fixture\InheritanceOrder;
|
||||
|
||||
class CCovariance extends ACovariance {
|
||||
/**
|
||||
* Technically valid return type, but against PHP's variance restrictions.
|
||||
* We use "ACovariance" instead, which is less accurate but valid.
|
||||
*
|
||||
* @return CCovariance
|
||||
*/
|
||||
public function test() {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
class ACovariance {
|
||||
/** @return ACovariance */
|
||||
public function test() {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\ReturnTypeDeclarationRector\Fixture\InheritanceOrder;
|
||||
|
||||
class CCovariance extends ACovariance {
|
||||
/**
|
||||
* Technically valid return type, but against PHP's variance restrictions.
|
||||
* We use "ACovariance" instead, which is less accurate but valid.
|
||||
*
|
||||
* @return CCovariance
|
||||
*/
|
||||
public function test(): \Rector\TypeDeclaration\Tests\Rector\ClassMethod\ReturnTypeDeclarationRector\Fixture\InheritanceOrder\ACovariance {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
class ACovariance {
|
||||
/** @return ACovariance */
|
||||
public function test(): self {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user