Config::setLevel()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 18
ccs 12
cts 12
cp 1
rs 9.4285
cc 2
eloc 11
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Pageon\SlackWebhookMonolog\Monolog;
4
5
use Monolog\Logger;
6
use Pageon\SlackWebhookMonolog\Monolog\Exceptions\InvalidLoggerLevelException;
7
use Pageon\SlackWebhookMonolog\Monolog\Interfaces\ConfigInterface;
8
9
/**
10
 * @author Jelmer Prins <[email protected]>
11
 *
12
 * @since 0.1.0
13
 */
14
class Config implements ConfigInterface
15
{
16
    /**
17
     * @var int The lowest level that we should listen to.
18
     */
19
    private $level;
20
21
    /**
22
     * @var bool Do the events need to bubble further.
23
     */
24
    private $doesBubble;
25
26
    /**
27
     * Config constructor.
28
     *
29
     * @param int $level
30
     * @param bool $doesBubble
31
     */
32 6
    public function __construct($level, $doesBubble = true)
33
    {
34 6
        $this->setLevel($level);
35 5
        $this->doesBubble = $doesBubble;
36 5
    }
37
38
    /**
39
     * @param int $level
40
     *
41
     * @return self
42
     */
43 6
    private function setLevel($level)
44
    {
45 6
        $availableLevels = array_flip(Logger::getLevels());
46
47 6
        if (!isset($availableLevels[$level])) {
48 1
            throw new InvalidLoggerLevelException(
49 1
                sprintf(
50 1
                    'The level: "%d" does not exist. The available levels are: "%s"',
51 1
                    $level,
52 1
                    implode(', ', array_keys($availableLevels))
53 1
                ),
54
                400
55 1
            );
56
        }
57 5
        $this->level = $level;
58
59 5
        return $this;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 3
    public function getLevel()
66
    {
67 3
        return $this->level;
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73 3
    public function doesBubble()
74
    {
75 3
        return $this->doesBubble;
76
    }
77
}
78