Description
Currently, the way invalid data is handled in value objects and results is quite messy:
- getters are typed with the expected type of the value
- when creating the object, missing required fields are initialized to
null
, which will then throw a TypeError when calling the getter - for required timestamp fields, passing a wrong date string will assign
false
to the property, which also leads to a TypeError when calling the getter - for optional timestamp fields, passing a wrong date string will assign
null
to the property, which means it removes the date - for integer/long fields transmitted in headers (only happening in the S3 service among the services we support currently), an invalid integer string assigns
false
to the property (which also leads to a TypeError when calling the getter)
Additionally, for JSON response parsers, we use filter_var(..., FILTER_VALIDATE_BOOLEAN)
, which means we first cast the boolean value from the json to string before validating it again. This is quite inefficient way to ensure we have a boolean in the property.
This inconsistency between the expected property type and the assigned value gets caught by static analysis tools in #1467 once I actually define the expected property type in phpdoc.
Note: input objects are already clean in that regard. They define all fields as nullable in a consistent way (getters are also nullable) and validate things when creating the request body.
What should be the strategy to handle those values ?