Bug Report
| Subject |
Details |
| Rector version |
last dev-main |
| Installed as |
composer dependency |
Minimal PHP Code Causing Issue
When method implements interface with union of of parent method, the union return removed, then after it, it cause fatal error
Fatal error: Declaration of Imp::run() must be compatible with DoX::run(): FooInterface
see https://3v4l.org/4QVaj
this should copy method interface return instead.
See https://getrector.com/demo/80f293b5-ef36-4df0-bb0c-ede44636885a
<?php
interface FooInterface {}
class A implements FooInterface {}
class B implements FooInterface {}
interface DoX
{
public function run(): FooInterface;
}
class Imp implements DoX
{
public function run(): A|B
{
return new A();
}
}
Responsible rules
DowngradeUnionTypeDeclarationRector
Expected Behavior
/**
* @return \A|\B
*/
- public function run(): A|B
+ public function run(): FooInterface
{
return new A();
}
Bug Report
Minimal PHP Code Causing Issue
When method implements interface with union of of parent method, the union return removed, then after it, it cause fatal error
see https://3v4l.org/4QVaj
this should copy method interface return instead.
See https://getrector.com/demo/80f293b5-ef36-4df0-bb0c-ede44636885a
Responsible rules
DowngradeUnionTypeDeclarationRectorExpected Behavior
/** * @return \A|\B */ - public function run(): A|B + public function run(): FooInterface { return new A(); }