pronamic / wp-pronamic-pay-charitable

Charitable driver for the WordPress payment processing library.
2 stars 1 forks source link

Use of empty function instead of '' #1

Closed knit-pay closed 3 years ago

knit-pay commented 3 years ago

Hello

many extensions set config_id and description variable as null or 0 if it is not set by admin. so it's better to use empty function instead of '' === comparison. It's not only for charitable, it's for other extensions also like give and others. What do you think about it?

https://github.com/wp-pay-extensions/charitable/blob/5a16132dd77af8e56e71da4b79cbe7745a46a2c8/src/Gateway.php#L124

https://github.com/wp-pay-extensions/charitable/blob/5a16132dd77af8e56e71da4b79cbe7745a46a2c8/src/CharitableHelper.php#L52

rvdsteege commented 3 years ago

It's fine to use empty(), but in this specific case there's nothing 'wrong' with checking an empty string as that is exactly what the value results in if a setting in the Charitable gateway is not set or is empty.

I think I've came across gateways which could be enabled in the extension and then result in a null value if the gateway settings are not saved explicitly, but result in an empty string once the settings are saved (while leaving the setting unset/empty). In these cases, empty() is a nice and clean solution.