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

jsonEncoded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
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
        $date = getCurrentDate($dateFormat);
31
        return file_put_contents('logs/pagantis.log', $date . " " . jsonEncoded($fileName)
32
            . " $message.\n",
33
            FILE_APPEND);
34
    }
35
    return file_put_contents('logs/pagantis.log', " " . jsonEncoded($fileName) . " $message.\n",
36
        FILE_APPEND);
37
}
38
39
/**
40
 * @param $dateFormat
41
 *
42
 * @return false|string
43
 */
44
function getCurrentDate($dateFormat)
45
{
46
    // TODO https://www.php.net/manual/en/function.date-default-timezone-set.php
47
    $currentDate = date($dateFormat);
48
    return $currentDate;
49
}
50
51
/**
52
 * @param $object
53
 *
54
 * @return false|string
55
 */
56
function jsonEncoded($object)
57
{
58
    return json_encode($object,
59
        JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT
60
    );
61
}
62
63
64
/**
65
 * @param $jsonString
66
 *
67
 * @return mixed
68
 */
69
function jsonToArray($jsonString)
70
{
71
    $myArray = json_decode($jsonString, true);
72
    return $myArray;
73
}
74
75
/**
76
 * @param array $array
77
 * @param       $key
78
 *
79
 * @return mixed
80
 */
81
function getValueOfKey(array $array, $key)
82
{
83
    if (!is_string($key)) {
84
        new \Exception($key . ' must be a string' . gettype($key)
85
            . ' was provided');
86
    }
87
    $value = $array[$key];
88
    return $value;
89
}
90
91
/**
92
 * @param $authorizedOrders
93
 *
94
 * @return bool
95
 */
96
function isAuthorizedOrderCountAboveZero($authorizedOrders)
97
{
98
99
    if (count($authorizedOrders) >= 1) {
100
        return true;
101
    }
102
    return false;
103
}