Passed
Push — master ( e3f7f1...6131eb )
by Emmanuel
02:18
created

helpers.php ➔ checkHistory()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 4
nop 3
dl 0
loc 20
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Laravel Payant package.
5
 *
6
 * (c) Emmanuel Awotunde <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Olaoluwa98\Payant;
13
14
use Olaoluwa98\Payant\Exceptions\ApiRequestError;
15
use Olaoluwa98\Payant\Exceptions\InvalidCredentials;
16
use Olaoluwa98\Payant\Exceptions\InvalidFeeBearer;
17
use Olaoluwa98\Payant\Exceptions\InvalidParameterType;
18
use Olaoluwa98\Payant\Exceptions\IsInvalid;
19
use Olaoluwa98\Payant\Exceptions\IsNull;
20
use Olaoluwa98\Payant\Exceptions\IsNullOrInvalid;
21
use Olaoluwa98\Payant\Exceptions\RequiredValueMissing;
22
use Olaoluwa98\Payant\Exceptions\RequiredValuesMissing;
23
24
use \Exception as phpException;
25
26
if (! function_exists('array_get'))
27
{
28
  /*
29
   *
30
   * @param array  $data
31
   * @param string $key
32
   * @param string $default
33
   *
34
   * @return mixed
35
   */
36
   function array_get($data, $key, $default = false) {
37
     if (!is_array($data)) {
38
         return $default;
39
     }
40
     return isset($data[$key]) ? $data[$key]: $default;
41
   }
42
}
43
44
if(!function_exists('array_keys_exist')){
45
    /**
46
     * Checks if multiple keys exist in an array
47
     *
48
     * @param array $array
49
     * @param array|string $keys
50
     *
51
     * @return bool
52
     */
53
    function array_keys_exist( array $array, $keys ) {
54
        $count = 0;
55
        if ( ! is_array( $keys ) ) {
56
            $keys = func_get_args();
57
            array_shift( $keys );
58
        }
59
        foreach ( $keys as $key ) {
60
            if ( array_key_exists( $key, $array ) ) {
61
                $count ++;
62
            }
63
        }
64
65
        return count( $keys ) === $count;
66
    }
67
}
68
69
function checkHistory($period, $start, $end){
70
    //Validate Period
71
    $valid_period_options = ["today", "week", "month", "30", "90", "year", "custom"];
72
73
    if (!in_array($period, $valid_period_options)) {
74
        throw new IsInvalid("Invalid Period - Available options: today, week, month, 30, 90, year or custom");
75
    }
76
77
    $post_data = [
78
        'period' => $period
79
    ];
80
81
    if ($period == 'custom'){
82
        if (!$start || !$end){
83
            throw new IsNull("Invalid custom Start or End date");
84
        }
85
        $post_data['start'] = $start;
86
        $post_data['end'] = $end;
87
    }
88
}
89
90
function cleanResponse($response){
91
  $result = $response->getBody();
92
  return $result;
93
}