psalm-plugin-symfony
psalm-plugin-symfony copied to clipboard
DenormalizerInterface stub doesn't handle nulls
Hi there,
The following:
public function denormalize($data, $type, $format = null, array $context = []): ?Money
{
if (null === $data) {
return null;
}
if (!isset($data['amount'], $data['currency'])) {
return null;
}
return $this->parser->parse((string) $data['amount'], new Currency($data['currency']));
}
will trigger:
ERROR: InvalidNullableReturnType - MoneyNormalizer.php:45:85 - The declared return type 'Money\Money' for MoneyNormalizer::denormalize is not nullable, but 'Money\Money|null' contains null (see https://psalm.dev/144)
public function denormalize($data, $type, $format = null, array $context = []): ?Money
ERROR: NullableReturnStatement - MoneyNormalizer.php:48:20 - The declared return type 'Money\Money' for MoneyNormalizer::denormalize is not nullable, but the function returns 'null' (see https://psalm.dev/139)
return null;
ERROR: NullableReturnStatement - MoneyNormalizer.php:52:20 - The declared return type 'Money\Money' for MoneyNormalizer::denormalize is not nullable, but the function returns 'null' (see https://psalm.dev/139)
return null;
Thanks