Completed
Push — master ( 2cb75f...2f465a )
by jelmer
02:38
created

Config::getConnectionString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
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
     * @var float How long the connection can be open before it times out.
28
     */
29
    private $connectionTimeout;
30
31
    /**
32
     * Config constructor.
33
     *
34
     * @param int $level
35
     * @param bool $doesBubble
36
     */
37
    public function __construct($level, $doesBubble = true)
38
    {
39
        $this->setLevel($level);
40
        $this->doesBubble = $doesBubble;
41
        $this->connectionTimeout = (float) ini_get('default_socket_timeout');
42 6
    }
43
44 6
    /**
45 5
     * @param int $level
46 5
     *
47 5
     * @return self
48
     */
49
    private function setLevel($level)
50
    {
51
        $availableLevels = array_flip(Logger::getLevels());
52
53
        if (!isset($availableLevels[$level])) {
54 6
            throw new InvalidLoggerLevelException(
55
                sprintf(
56 6
                    'The level: "%d" does not exist. The available levels are: "%s"',
57
                    $level,
58 6
                    implode(', ', array_keys($availableLevels))
59 1
                ),
60 1
                400
61 1
            );
62 1
        }
63 1
        $this->level = $level;
64 1
65
        return $this;
66 1
    }
67
68 5
    /**
69
     * {@inheritdoc}
70 5
     */
71
    public function getLevel()
72
    {
73
        return $this->level;
74
    }
75
76 1
    /**
77
     * {@inheritdoc}
78 1
     */
79
    public function doesBubble()
80
    {
81
        return $this->doesBubble;
82
    }
83
}
84