Config::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
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