Open TheDevick opened 6 months ago
Hey @TheDevick, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.
Hey @TheDevick, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.
I found these snippets:
I don't know why it's giving so much errors. Maybe because of the bc extension. But in my project, it just shows the errors I mentioned
Hey! Just wanted to metion that I did some tests and concluded that:
$watt = Watt::create('1.0') // This IS returning an Watt object, instead of the referred psalm return type Decimal&static;
Founded a solution. Add the following @return annotation to the Decimal::create() static method:
/**
* @return static
*/
public static function create(string $value): static
{
if (!is_numeric($value)) {
throw new InvalidDecimalValueException(sprintf('The decimal value "%s" is non-numeric', $value));
}
return new static($value);
}
Is it a bug? Because I'm already telling the PHP itself that the method returns static!
@TheDevick thanks for the workaround, adding @return static
fixes also my problem, it looks indeed like the phpdoc should be not needed since we have already the static
return type.
I encountered an issue with PSALM's, related to the return types of methods in my classes. PSALM is flagging errors regarding the specificity of return types, despite the code being logically correct.
Errors: