Skip to content

createNormalizationValueStatement does not handle nullable object in DateType and DateTimeType #817

@KhadaRoss

Description

@KhadaRoss

Jane version(s) affected: ^7.5

Description
When using nullable date or date time definitions the generated normalize method will throw a fatal error because a mandatory null check is missing:

Call to a member function format() on null

How to reproduce

schema:

dateProperty:
type: string
nullable: true
format: date
example: 2020-01-01

generated code in normalizer

$data['dateProperty'] = $object->getDateProperty()->format('Y-m-d');

Possible Solution

possible solution for php7.2 and php8:

$data['dateProperty'] = $object->getDateProperty() ? $object->getDateProperty()->format('Y-m-d') : null;

Additional context

Fix should be implemented in createNormalizationValueStatement in Guesser\Guess\Date(Time)?Type

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions