Syslog   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 74
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B setOptions() 0 29 6
A log() 0 4 1
1
<?php
2
declare(strict_types = 1);
3
4
/**
5
 * Micro
6
 *
7
 * @author    Raffael Sahli <[email protected]>
8
 * @copyright Copyright (c) 2017 gyselroth GmbH (https://gyselroth.com)
9
 * @license   MIT https://opensource.org/licenses/MIT
10
 */
11
12
namespace Micro\Log\Adapter;
13
14
use Micro\Log;
15
use Micro\Log\Adapter\AdapterInterface;
16
17
class Syslog extends AbstractAdapter
18
{
19
    /**
20
     * Syslog ident
21
     *
22
     * @var string
23
     */
24
    protected $ident;
25
26
27
    /**
28
     * Option
29
     *
30
     * @var int
31
     */
32
    protected $option = LOG_PID;
33
34
35
    /**
36
     * Facility
37
     *
38
     * @var string
39
     */
40
    protected $facility;
41
42
43
    /**
44
     * Set options
45
     *
46
     * @return  AdapterInterface
47
     */
48
    public function setOptions(? Iterable $config = null): AdapterInterface
49
    {
50
        if ($config === null) {
51
            return $this;
52
        }
53
54
        foreach ($config as $option => $value) {
55
            switch ($option) {
56
                case 'ident':
57
                    $this->ident = (string)$value;
58
                    unset($config[$option]);
59
                break;
60
                case 'option':
61
                    $this->option = (int)(string)$value;
62
                    unset($config[$option]);
63
                break;
64
                case 'facility':
65
                    $this->facility = (string)$value;
66
                    unset($config[$option]);
67
                break;
68
            }
69
        }
70
71
        parent::setOptions($config);
72
73
        openlog($this->ident, $this->option, $this->facility);
74
75
        return $this;
76
    }
77
78
79
    /**
80
     * Log
81
     *
82
     * @param   string $level
83
     * @param   string $message
84
     * @return  bool
85
     */
86
    public function log(string $level, string $message): bool
87
    {
88
        return syslog(Log::PRIORITIES[$level], $message);
89
    }
90
}
91