Completed
Push — master ( 87eb15...0541b3 )
by Mihail
20:09 queued 10:38
created

Syslog::process()   A

Complexity

Conditions 1
Paths 3

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 18
ccs 13
cts 13
cp 1
rs 9.7998
cc 1
nc 3
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Koded package.
5
 *
6
 * (c) Mihail Binev <[email protected]>
7
 *
8
 * Please view the LICENSE distributed with this source code
9
 * for the full copyright and license information.
10
 *
11
 */
12
13
namespace Koded\Logging\Processors;
14
15
use Koded\Logging\Logger;
16
17
/**
18
 * System log.
19
 *
20
 * @link http://www.php.net/manual/en/function.openlog.php
21
 */
22
class Syslog extends Processor
23
{
24
    protected string $format = '[levelname] message';
25
26 1
    protected function process(array $message): void
27
    {
28
        $levels = [
29 1
            Logger::DEBUG     => LOG_DEBUG,
30 1
            Logger::INFO      => LOG_INFO,
31 1
            Logger::NOTICE    => LOG_NOTICE,
32 1
            Logger::WARNING   => LOG_WARNING,
33 1
            Logger::ERROR     => LOG_ERR,
34 1
            Logger::CRITICAL  => LOG_CRIT,
35 1
            Logger::ALERT     => LOG_ALERT,
36 1
            Logger::EMERGENCY => LOG_EMERG
37
        ];
38
39
        try {
40 1
            \openlog(null, LOG_CONS, LOG_USER);
0 ignored issues
show
Bug introduced by
null of type null is incompatible with the type string expected by parameter $prefix of openlog(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
            \openlog(/** @scrutinizer ignore-type */ null, LOG_CONS, LOG_USER);
Loading history...
41 1
            \syslog($levels[$message['level']] ?? LOG_DEBUG, \strtr($this->format, $message));
42 1
        } finally {
43 1
            \closelog();
44
        }
45 1
    }
46
}
47