Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DenormalizerInterface stub doesn't handle nulls #217

Open
bendavies opened this issue Sep 3, 2021 · 0 comments
Open

DenormalizerInterface stub doesn't handle nulls #217

bendavies opened this issue Sep 3, 2021 · 0 comments

Comments

@bendavies
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant