Skip to content

Commit

Permalink
Apply code styling according to Code Sniffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
guzzilar committed Jan 7, 2019
1 parent 5db6ed7 commit 86ba196
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
49 changes: 32 additions & 17 deletions lib/omise/OmiseCapabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,28 @@ public function reload()
* (muliple arguments, or a single array)
*
* @param [func1,fun2,...] OR func1, func2,...
*
*
* @return array
*/
public function getBackends()
{
// check for filters
if ($filters = func_get_args()) $filter = self::combineFilters(self::argsToVariadic($filters));
$backends = $this['payment_backends'];
array_walk(
$backends,
function($value, $key) use (&$backends) {
$id = array_keys($value)[0];
$backends[$key][$id]['_id'] = $id;
}

// check for filters
if ($filters = func_get_args()) {
$filter = self::combineFilters(self::argsToVariadic($filters));
}

$backends = array_map(
function ($backend) {
$id = array_keys($backend)[0];
$backend[$id]['_id'] = $id;
return (object)reset($backend);
},
$backends
);
$backends = array_map(function($backend) { return (object)reset($backend); }, $backends);
return !empty($filter) ? array_filter($backends, $filter) : $backends;

return !empty($filter) ? array_values(array_filter($backends, $filter)) : $backends;
}

/**
Expand All @@ -73,7 +78,9 @@ function($value, $key) use (&$backends) {
*/
public function makeBackendFilterCurrency($currency)
{
return function($backend) use ($currency) { return in_array(strtoupper($currency), $backend->currencies); };
return function ($backend) use ($currency) {
return in_array(strtoupper($currency), $backend->currencies);
};
}

/**
Expand All @@ -85,7 +92,9 @@ public function makeBackendFilterCurrency($currency)
*/
public function makeBackendFilterType($type)
{
return function($backend) use ($type) { return $backend->type==$type; };
return function ($backend) use ($type) {
return $backend->type == $type;
};
}

/**
Expand All @@ -99,7 +108,7 @@ public function makeBackendFilterChargeAmount($amount)
{
$defMin = $this['limits']['charge_amount']['min'];
$defMax = $this['limits']['charge_amount']['max'];
return function($backend) use ($amount, $defMin, $defMax) {
return function ($backend) use ($amount, $defMin, $defMax) {
// temporary hack for now to correct min value for instalments to 500000
if ($backend->type == 'installment') {
$min = 500000;
Expand All @@ -125,7 +134,9 @@ protected function setupFilterShortcuts()
$tempArr = &$this->$filterArrayName;
foreach ($availableFilters as $type) {
$funcName = 'make' . ucfirst($filterSubject) . 'Filter' . $type;
$tempArr[$type] = function() use ($funcName) { return call_user_func_array(array($this, $funcName), func_get_args()); };
$tempArr[$type] = function () use ($funcName) {
return call_user_func_array(array($this, $funcName), func_get_args());
};
}
}
}
Expand All @@ -139,8 +150,12 @@ protected function setupFilterShortcuts()
*/
private static function combineFilters($filters)
{
return function($a) use ($filters) {
foreach ($filters as $filter) if (!$filter($a)) return false;
return function ($value) use ($filters) {
foreach ($filters as $filter) {
if (!$filter($value)) {
return false;
}
}
return true;
};
}
Expand Down
2 changes: 1 addition & 1 deletion lib/omise/res/OmiseApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected function execute($url, $requestMethod, $key, $params = null)
* Checks if response from API was valid.
*
* @param array $array - decoded JSON response
*
*
* @return boolean
*/
protected function isValidAPIResponse($array)
Expand Down

0 comments on commit 86ba196

Please sign in to comment.