Closed dshafik closed 2 weeks ago
Describe the bug
Reproduction: https://phpstan.org/r/3c452035-5203-439f-8c93-372be51d80a8
The Bag::from() method has the following signature:
Bag::from()
public static function from(mixed $values): Bag { }
(link)
When calling MyValue::from() phpStorm doesn't like that it returns a Bag rather than static, but when changing to static phpstan has the following complaint:
MyValue::from()
Bag
static
Method Bag\Bag::from() should return static(Bag\Bag) but returns Bag\Bag.
This is because the return is the result ofInputPipeline::process() which returns Bag (public static function process(BagInput $input): Bag {}), but the actual return value is the value of new ($input->bagClassname) (which should be type-hinted class-string<Bag>) from the passed in BagInput for the InputPipeline::process() call.
InputPipeline::process()
public static function process(BagInput $input): Bag {}
new ($input->bagClassname)
class-string<Bag>
BagInput
What docblock is needed to type hint this correctly?
Fixed with c56f65a
Describe the bug
Reproduction: https://phpstan.org/r/3c452035-5203-439f-8c93-372be51d80a8
The
Bag::from()
method has the following signature:(link)
When calling
MyValue::from()
phpStorm doesn't like that it returns aBag
rather thanstatic
, but when changing tostatic
phpstan has the following complaint:This is because the return is the result of
InputPipeline::process()
which returnsBag
(public static function process(BagInput $input): Bag {}
), but the actual return value is the value ofnew ($input->bagClassname)
(which should be type-hintedclass-string<Bag>
) from the passed inBagInput
for theInputPipeline::process()
call.What docblock is needed to type hint this correctly?