GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 400b73...6936b8 )
by Cees-Jan
17:50 queued 16:45
created

functions.php ➔ checkCorrectLogLevel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 12
ccs 6
cts 6
cp 1
crap 2
rs 9.8666
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\PSR3;
4
5
use Psr\Log\InvalidArgumentException;
6
use Psr\Log\LogLevel;
7
8
/**
9
 * Logging levels PSR-3 LogLevel enum.
10
 *
11
 * @var array $levels Logging levels
12
 */
13
const LOG_LEVELS = [
14
    LogLevel::DEBUG     => 'DEBUG',
15
    LogLevel::INFO      => 'INFO',
16
    LogLevel::NOTICE    => 'NOTICE',
17
    LogLevel::WARNING   => 'WARNING',
18
    LogLevel::ERROR     => 'ERROR',
19
    LogLevel::CRITICAL  => 'CRITICAL',
20
    LogLevel::ALERT     => 'ALERT',
21
    LogLevel::EMERGENCY => 'EMERGENCY',
22
];
23
24
/**
25
 * Functions in this file are a continuation of the code from this
26
 * https://github.com/Seldaek/monolog/blob/6e6586257d9fb231bf039563632e626cdef594e5/src/Monolog/Processor/PsrLogMessageProcessor.php file.
27
 */
28
29
/**
30
 * @param  string $message
31
 * @param  array  $context
32
 * @return string
33
 */
34
function processPlaceHolders(string $message, array $context): string
35
{
36 3
    if (false === \strpos($message, '{')) {
37 1
        return $message;
38
    }
39
40 2
    $replacements = [];
41 2
    foreach ($context as $key => $value) {
42 2
        $replacements['{'.$key.'}'] = formatValue($value);
43
    }
44
45 2
    return \strtr($message, $replacements);
46
}
47
48
function formatValue($value): string
49
{
50 10
    if (\is_null($value) || \is_scalar($value) || (\is_object($value) && \method_exists($value, '__toString'))) {
51 7
        return (string)$value;
52
    }
53
54 3
    if (\is_object($value)) {
55 2
        return '[object '.\get_class($value).']';
56
    }
57
58 1
    return '['.\gettype($value).']';
59
}
60
61
function normalizeContext(array $context): array
62
{
63 4
    foreach ($context as $index => $value) {
64 3
        if (\is_array($value)) {
65 2
            $context[$index] = normalizeContext($value);
66 2
            continue;
67
        }
68
69 2
        if (\is_resource($value)) {
70 2
            $context[$index] = \sprintf('[resource] (%s)', \get_resource_type($value));
71 2
            continue;
72
        }
73
    }
74
75 4
    return $context;
76
}
77
78
function normalizeContextWithFormatValue(array $context): array
79
{
80 5
    foreach ($context as $index => $value) {
81 4
        if (\is_array($value)) {
82 3
            $context[$index] = normalizeContextWithFormatValue($value);
83 3
            continue;
84
        }
85
86 3
        if (\is_resource($value)) {
87 2
            $context[$index] = \sprintf('[resource] (%s)', \get_resource_type($value));
88 2
            continue;
89
        }
90
91 1
        $context[$index] = formatValue($value);
92
    }
93
94 5
    return $context;
95
}
96
97
function checkCorrectLogLevel(string $level): bool
98
{
99 11
    $level = \strtolower($level);
100 11
    $levels = LOG_LEVELS;
101 11
    if (!isset($levels[$level])) {
102 3
        throw new InvalidArgumentException(
103 3
            'Level "' . $level . '" is not defined, use one of: '.\implode(', ', \array_keys(LOG_LEVELS))
104
        );
105
    }
106
107 8
    return true;
108
}
109