Crell / ApiProblem

A simple implementation of the api-problem specification. Includes PSR-15 support.
MIT License
239 stars 21 forks source link

Error with type hint #22

Closed thomasvargiu closed 5 years ago

thomasvargiu commented 5 years ago

Crell\ApiProblem\ApiProblem sets $title (and $type) property only if argument isn't empty, but getters requires a string return value.

I think is possible to remove conditions in constructor. If you enable strict types, currently it would throw an error.

Same thing for other properties, they are null by default, but getters' return values aren't nullable.

Crell commented 5 years ago

Ak, I think you're correct. Removing the if checks in the constructor would resolve the issue for title and type, but not the other pre-defined properties. I think the solution is to give them all default values when declared, as an empty string is still easy enough for a caller to detect. (I really dislike nullables unless there's absolutely no other option.)

Happy to accept a PR if you get to it before I do. :smile:

thomasvargiu commented 5 years ago

I'm doing it. There is any reason why strict types is declared but disabled?

Crell commented 5 years ago

Uh. I don't know what that means...? Strict types are declared at the top of the file. They can't be disabled after that in that file.

More likely, the tests just didn't happen to catch that use case.

Crell commented 5 years ago

Oh. Wait, I just realized what you mean. No, that's just me being brain-dead stupid. Thanks for catching it. :smile: Yes, everything should always be strictly typed, always.

Crell commented 5 years ago

I revised the PR with a new one, but kept all of your commits so that you got credit for them. :smile:

3.1 release has been tagged. Assuming I have it setup correctly it should push out to Composer any minute now. Thanks @thomasvargiu!