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.

Logger   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 14
lcom 0
cbo 1
dl 0
loc 58
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A __destruct() 0 6 2
A log() 0 10 1
C levelToPriority() 0 23 9
1
<?php
2
3
/**
4
 * eduVPN - End-user friendly VPN.
5
 *
6
 * Copyright: 2016-2017, The Commons Conservancy eduVPN Programme
7
 * SPDX-License-Identifier: AGPL-3.0+
8
 */
9
10
namespace SURFnet\VPN\Common;
11
12
use Psr\Log\AbstractLogger;
13
use Psr\Log\LogLevel;
14
use RuntimeException;
15
16
class Logger extends AbstractLogger
17
{
18
    public function __construct($ident)
19
    {
20
        if (false === openlog($ident, LOG_PERROR | LOG_ODELAY, LOG_USER)) {
21
            throw new RuntimeException('unable to open syslog');
22
        }
23
    }
24
25
    public function __destruct()
26
    {
27
        if (false === closelog()) {
28
            throw new RuntimeException('unable to close syslog');
29
        }
30
    }
31
32
    /**
33
     * Logs with an arbitrary level.
34
     *
35
     * @param mixed  $level
36
     * @param string $message
37
     * @param array  $context
38
     */
39
    public function log($level, $message, array $context = [])
40
    {
41
        // convert level to syslog level
42
        $syslogPriority = self::levelToPriority($level);
43
44
        syslog(
45
            $syslogPriority,
46
            $message
47
        );
48
    }
49
50
    private static function levelToPriority($level)
51
    {
52
        switch ($level) {
53
            case LogLevel::EMERGENCY:
54
                return LOG_EMERG;
55
            case LogLevel::ALERT:
56
                return LOG_ALERT;
57
            case LogLevel::CRITICAL:
58
                return LOG_CRIT;
59
            case LogLevel::ERROR:
60
                return LOG_ERR;
61
            case LogLevel::WARNING:
62
                return LOG_WARNING;
63
            case LogLevel::NOTICE:
64
                return LOG_NOTICE;
65
            case LogLevel::INFO:
66
                return LOG_INFO;
67
            case LogLevel::DEBUG:
68
                return LOG_DEBUG;
69
            default:
70
                throw new RuntimeException('unknown log level');
71
        }
72
    }
73
}
74