oscarotero / psr7-middlewares

[DEPRECATED] Collection of PSR-7 middlewares
MIT License
668 stars 56 forks source link

add default param to AttributeTrait::getAttribute #59

Closed abacaphiliac closed 7 years ago

abacaphiliac commented 7 years ago

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?

oscarotero commented 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)

abacaphiliac commented 7 years ago

@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.

oscarotero commented 7 years ago

Ok, fair enough. Merged. Thank you.