Passed
Pull Request — master (#26)
by
unknown
02:08
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
/**
5
 * @param $message
6
 * @param $fileName
7
 * @param $withDate bool
8
 *
9
 * @return false|int
10
 */
11
function writeLog(
12
    $message,
13
    $fileName,
14
    $withDate
15
) {
16
    $dateFormat = '[D M j G:i:s o]';
17
    if ($withDate) {
18
        $date = getCurrentDate($dateFormat);
19
        return file_put_contents('logs/pagantis.log', $date . " " . jsonEncoded($fileName)
20
            . " $message.\n",
21
            FILE_APPEND);
22
    }
23
    return file_put_contents('logs/pagantis.log', " " . jsonEncoded($fileName) . " $message.\n",
24
        FILE_APPEND);
25
}
26
27
/**
28
 * @param $dateFormat
29
 *
30
 * @return false|string
31
 */
32
function getCurrentDate($dateFormat)
33
{
34
    // TODO https://www.php.net/manual/en/function.date-default-timezone-set.php
35
    $currentDate = date($dateFormat);
36
    return $currentDate;
37
}
38
39
/**
40
 * @param $object
41
 *
42
 * @return false|string
43
 */
44
function jsonEncoded($object)
45
{
46
    return json_encode($object,
47
        JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT
48
    );
49
}
50
51
52
/**
53
 * @param $jsonString
54
 *
55
 * @return mixed
56
 */
57
function jsonToArray($jsonString)
58
{
59
    $myArray = json_decode($jsonString, true);
60
    return $myArray;
61
}
62
63
/**
64
 * @param array $array
65
 * @param       $key
66
 *
67
 * @return mixed
68
 */
69
function getValueOfKey(array $array, $key)
70
{
71
    if (!is_string($key)) {
72
        new \Exception($key . ' must be a string' . gettype($key)
73
            . ' was provided');
74
    }
75
    $value = $array[$key];
76
    return $value;
77
}
78
79
/**
80
 * @param $authorizedOrders
81
 *
82
 * @return bool
83
 */
84
function isAuthorizedOrderCountAboveZero($authorizedOrders)
85
{
86
87
    if (count($authorizedOrders) >= 1) {
88
        return true;
89
    }
90
    return false;
91
}