Passed
Pull Request — master (#26)
by
unknown
01:54
created

getValueOfKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 8
rs 10
1
<?php
2
3
/**
4
 * @return \Pagantis\OrdersApiClient\Client
5
 * @throws \Httpful\Exception\ConnectionErrorException
6
 * @throws \Pagantis\OrdersApiClient\Exception\ClientException
7
 */
8
function getClient()
9
{
10
    if (PUBLIC_KEY == '' || PRIVATE_KEY == '') {
0 ignored issues
show
introduced by
The condition PUBLIC_KEY == '' is always true.
Loading history...
11
        throw new \Exception('You need set the public and private key');
12
    }
13
    $orderClient = new \Pagantis\OrdersApiClient\Client(PUBLIC_KEY, PRIVATE_KEY);
14
    return $orderClient;
15
}
16
/**
17
 * @param $message
18
 * @param $fileName
19
 * @param $withDate bool
20
 *
21
 * @return false|int
22
 */
23
function writeLog(
24
    $message,
25
    $fileName,
26
    $withDate
27
) {
28
    $dateFormat = '[D M j G:i:s o]';
29
    if ($withDate) {
30
        $path = dirname(__FILE__);
0 ignored issues
show
Unused Code introduced by
The assignment to $path is dead and can be removed.
Loading history...
31
        $date = getCurrentDate($dateFormat);
32
        return file_put_contents('../pagantis.log', $date . " " . jsonEncoded($fileName)
33
            . " $message.\n",
34
            FILE_APPEND);
35
    }
36
    return file_put_contents('../pagantis.log', " " . jsonEncoded($fileName) . " $message.\n",
37
        FILE_APPEND);
38
}
39
40
/**
41
 * @param $dateFormat
42
 *
43
 * @return false|string
44
 */
45
function getCurrentDate($dateFormat)
46
{
47
    // TODO https://www.php.net/manual/en/function.date-default-timezone-set.php
48
    $currentDate = date($dateFormat);
49
    return $currentDate;
50
}
51
52
/**
53
 * @param $object
54
 *
55
 * @return false|string
56
 */
57
function jsonEncoded($object)
58
{
59
    return json_encode($object,
60
        JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT
61
    );
62
}
63
64
65
/**
66
 * @param $jsonString
67
 *
68
 * @return mixed
69
 */
70
function jsonToArray($jsonString)
71
{
72
    $myArray = json_decode($jsonString, true);
73
    return $myArray;
74
}
75
76
/**
77
 * @param array $array
78
 * @param       $key
79
 *
80
 * @return mixed
81
 */
82
function getValueOfKey(array $array, $key)
83
{
84
    if (!is_string($key)) {
85
        new \Exception($key . ' must be a string' . gettype($key)
86
            . ' was provided');
87
    }
88
    $value = $array[$key];
89
    return $value;
90
}
91
92
/**
93
 * @param $authorizedOrders
94
 *
95
 * @return bool
96
 */
97
function isAuthorizedOrderCountAboveZero($authorizedOrders)
98
{
99
100
    if (count($authorizedOrders) >= 1) {
101
        return true;
102
    }
103
    return false;
104
}