Skip to content

Commit

Permalink
strip empty arrays as well as null fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Hickson committed Oct 27, 2017
1 parent 9f4eb10 commit 0b24ec6
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

All Notable changes to `omnipay/gocardlessv2` will be documented in this file

- 0.1.12 - Switch from is_null() to empty() to handle empty arrays when stripping blank params
- 0.1.11 - Add some methods to the Bank Account for returning data
- 0.1.10 - Add a mechanism to the payment response for querying if the payment is outstanding without needing to know the statuses (which are now available as constants on the payment response)
- 0.1.9 - Params from abstract now returns core values, search mechanism on payments via customer reference.
Expand Down
6 changes: 3 additions & 3 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function getCustomerBankAccountData()
'metadata' => $this->getBankAccountMetaData(),
],
function ($value) {
return !is_null($value);
return !empty($value);
}
);

Expand Down Expand Up @@ -446,7 +446,7 @@ public function getSubscriptionDayOfMonth()
public function setSubscriptionDayOfMonth($value = null)
{
// This block can be removed once PHP7 scalar type declarations are available
if (!is_null($value)) {
if (!empty($value)) {
if (!is_numeric($value)) {
throw new \InvalidArgumentException('Subscription day of month must be be null or numeric');
} else {
Expand All @@ -458,7 +458,7 @@ public function setSubscriptionDayOfMonth($value = null)
* GoCardless don't allow subscriptions to be set for the 29th, 30th, or 31st of the month, so map these to a
* special "-1" value which means "last working day of the month".
*/
if (!is_null($value) && $value > 28) {
if (!empty($value) && $value > 28) {
$value = -1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Message/CreateCustomerBankAccountRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function getData()
$response['links']['customer'] = $this->getCustomerReference();
// Remove null values
foreach($response as $key=>$value){
if(is_null($value)){
if(empty($value)){
unset($response[$key]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Message/CreatePaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getData()
'links' => ['mandate' => $this->getMandateReference()],
],
function ($value) {
return !is_null($value);
return !empty($value);
}
);

Expand Down
2 changes: 1 addition & 1 deletion src/Message/CreateSubscriptionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getData()

// Remove null values
foreach($data as $key=>$value){
if(is_null($value)){
if(empty($value)){
unset($data[$key]);
}
}
Expand Down

0 comments on commit 0b24ec6

Please sign in to comment.