-
-
Notifications
You must be signed in to change notification settings - Fork 737
Closed
Description
There is this rule already that narrows union return types.
There is also this case of return type that can be narrowed
abstract class AbstractFactory
abstract protected function build() : object;
class AppleFactory extends AbstractFactory
#[Override]
protected function build(): object
{
return new Apple();
}
In the example above the return type of method build in AppleFactory can be narrowed down to Apple.
class AppleFactory extends AbstractFactory
#[Override]
protected function build(): Apple
{
return new Apple();
}
One approach is to check whether the method has the override attribute to make the rule less aggressive
But alternatively the rule can check any method that has a return type object and check what is actually returned, and replace the return type.
Would you consider adding such a rule if i make a pr ? If yes, which version ? the one that checks if the method has the Override attribute ? or the more generic
Metadata
Metadata
Assignees
Labels
No labels