Closed funivan closed 8 years ago
Hey @funivan, that's a good question! To answer it I'll just remind you that using strict types would raise a Fatal Error (Uncaught TypeError: Argument <argument number> passed to <function> must be of the type <expected type>, <received type> given
).
I'm fine having these kind of fatal errors being raised when passing an invalid argument to a service (as you can see later in the series, like in Event constructor or in AnEventHappened), but when it comes to the entry point of our domain (the Command objects like LandRover
) I'd rather have an InvalidArgumentException
.
I hope that makes sense for you.
I understand your position. But what benefits you get when you use InvalidArgumentException instead of type error?
Its mainly for error classification: let's say your logic is used in a HTTP application, an API. Then you only need to catch all InvalidArgumentException
and return a 422 UNPROCESSABLE ENTITY
response.
To be fair, instead of throwing \InvalidArgumentException
it might be better to throw a custom MarsRover\Exception\ValidationFailedException
.
Thanks. Error classification is good option to choose;)
Hi. Reading articles about Mars rover. Have one question. You are using php7 and write is_int to check the input arguments. Why? You can use strict types to leave php to do that. See constructor inside this file https://github.com/gnugat/gnugat.github.io/blob/master/_sculpin/source/_posts/2016-06-29-mars-rover-landing.md
Thanks ;)