EchoLog::log()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
cc 2
nc 2
nop 3
crap 2
1
<?php
2
/**
3
 * @author Dmitry Gladyshev <[email protected]>
4
 * @created 02.11.16 13:52
5
 */
6
7
namespace Yandex\Direct\Logger;
8
9
use Psr\Log\AbstractLogger;
10
use Psr\Log\LogLevel;
11
use Psr\Log\InvalidArgumentException;
12
13
/**
14
 * Class EchoLog
15
 * @package Yandex\Direct\Logger
16
 */
17
class EchoLog extends AbstractLogger
18
{
19
    /**
20
     * @param string $level
21
     * @param string $message
22
     * @param array $context
23
     * @throws InvalidArgumentException
24
     */
25 11
    public function log($level, $message, array $context = [])
26
    {
27 11
        if (!$this->checkLevel($level)) {
28 1
            throw new InvalidArgumentException("Invalid log level {$level}");
29
        }
30 10
        echo "[$level] $message" . PHP_EOL;
31 10
    }
32
33 11
    private function checkLevel($level)
34
    {
35 11
        if (in_array($level, [
36 11
            LogLevel::ALERT,
37 11
            LogLevel::CRITICAL,
38 11
            LogLevel::EMERGENCY,
39 11
            LogLevel::ERROR,
40 11
            LogLevel::WARNING,
41 11
            LogLevel::DEBUG,
42 11
            LogLevel::INFO,
43 11
            LogLevel::NOTICE,
44 11
        ])) {
45 10
            return true;
46
        }
47 1
        return false;
48
    }
49
}
50