Closed abacaphiliac closed 7 years ago
I'm not against this, but why not simply:
$value = self::getAttribute($request, 'name') ?: [];
This is what I do in similar cases, working in 99% of cases (unless false
, 0
or any other similar value is expected)
@oscarotero yes of course, but we have an opportunity to write the branch and test one time so that everyone can use the tested branch, rather than all consumers having to implement the branch (and hopefully test) whenever they need to do the same.
Ok, fair enough. Merged. Thank you.
add default param to \Psr7Middlewares\Utils\AttributeTrait::getAttribute.
the optional default value is null, so the change should be backwards compatible.
this change allows me to specify, for example, that an array should be returned regardless. this saves me from having to do some other type-checking code in all of my consuming methods.
@oscarotero what do you think?