Skip to content

Commit

Permalink
Merge pull request #31 from Xaxxis/master
Browse files Browse the repository at this point in the history
Fix the rest of deprecated array_key_exists on php 7.4
  • Loading branch information
rizdaprasetya authored Jul 21, 2020
2 parents fa7a381 + 120cb9e commit 94cdca1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
composer.lock
composer.phar
vendor/
.idea
.idea
.DS_STORE
2 changes: 1 addition & 1 deletion Midtrans/CoreApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function charge($params)
'payment_type' => 'credit_card'
);

if (array_key_exists('item_details', $params)) {
if (isset($params['item_details'])) {
$gross_amount = 0;
foreach ($params['item_details'] as $item) {
$gross_amount += $item['quantity'] * $item['price'];
Expand Down
13 changes: 6 additions & 7 deletions Midtrans/Sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public static function jsonRequest(&$json)
{
$keys = array('item_details', 'customer_details');
foreach ($keys as $key) {
if (!array_key_exists($key, $json)) continue;

if (!isset($json[$key])) continue;
$camel = static::upperCamelize($key);
$function = "field$camel";
static::$function($json[$key]);
Expand All @@ -55,7 +54,7 @@ private static function fieldCustomerDetails(&$field)
$field['first_name'] = $first_name
->maxLength(20)
->apply($field['first_name']);
if (array_key_exists('last_name', $field)) {
if (isset($field['last_name'])) {
$last_name = new self;
$field['last_name'] = $last_name
->maxLength(20)
Expand All @@ -71,7 +70,7 @@ private static function fieldCustomerDetails(&$field)
if (!empty($field['billing_address']) || !empty($field['shipping_address'])) {
$keys = array('billing_address', 'shipping_address');
foreach ($keys as $key) {
if (!array_key_exists($key, $field)) continue;
if (!isset($field[$key])) continue;

$camel = static::upperCamelize($key);
$function = "field$camel";
Expand All @@ -92,22 +91,22 @@ private static function fieldBillingAddress(&$field)
);

foreach ($fields as $key => $value) {
if (array_key_exists($key, $field)) {
if (isset($field[$key])) {
$self = new self;
$field[$key] = $self
->maxLength($value)
->apply($field[$key]);
}
}

if (array_key_exists('postal_code', $field)) {
if (isset($field['postal_code'])) {
$postal_code = new self;
$field['postal_code'] = $postal_code
->whitelist('A-Za-z0-9\\- ')
->maxLength(10)
->apply($field['postal_code']);
}
if (array_key_exists('phone', $field)) {
if (isset($field['phone'])) {
static::fieldPhone($field['phone']);
}
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "midtrans/midtrans-php",
"description": "PHP Wrapper for Midtrans Payment API.",
"homepage": "https://midtrans.com",
"version": "2.3.1",
"version": "2.3.2",
"type": "library",
"license":"GPL-3.0",
"authors": [
Expand Down
4 changes: 2 additions & 2 deletions tests/MidtransTransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function testStatus()
);

$fields = VT_Tests::lastReqOptions();
$this->assertFalse(array_key_exists("POST", $fields));
$this->assertFalse(array_key_exists("POSTFIELDS", $fields));
$this->assertFalse(isset($fields['POST']));
$this->assertFalse(isset($fields['POSTFIELDS']));
}

public function testFailureStatus()
Expand Down

0 comments on commit 94cdca1

Please sign in to comment.