Config   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 5
c 4
b 0
f 2
lcom 1
cbo 2
dl 0
loc 64
ccs 20
cts 20
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setLevel() 0 18 2
A getLevel() 0 4 1
A doesBubble() 0 4 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