ErrorHandlerBuilder   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Test Coverage

Coverage 90.32%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 127
ccs 28
cts 31
cp 0.9032
rs 10
c 0
b 0
f 0
wmc 13

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getExceptionLevel() 0 3 1
A getErrorLevelMap() 0 3 1
A build() 0 3 2
A getFatalLevel() 0 3 1
A getLogger() 0 3 1
A getDefaultLogger() 0 5 1
A setErrorLevelMap() 0 5 1
A setLogger() 0 5 1
A buildAndRegister() 0 7 2
A setExceptionLevel() 0 5 1
A setFatalLevel() 0 5 1
1
<?php
2
/*
3
 * This file is part of Monolog Extensions
4
 *
5
 * Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @see  http://github.com/graze/MonologExtensions/blob/master/LICENSE
11
 * @link http://github.com/graze/MonologExtensions
12
 */
13
namespace Graze\Monolog;
14
15
use Monolog\ErrorHandler;
16
use Monolog\Logger;
17
use Psr\Log\LogLevel;
18
19
class ErrorHandlerBuilder
20
{
21
    /**
22
     * @var array
23
     */
24
    protected $errorLevelMap = [];
25
26
    /**
27
     * @var string
28
     */
29
    protected $exceptionLevel = LogLevel::CRITICAL;
30
31
    /**
32
     * @var string
33
     */
34
    protected $fatalLevel;
35
36
    /**
37
     * @var Logger
38
     */
39
    protected $logger;
40
41
    /**
42
     * @return ErrorHandler
43
     */
44 1
    public function build()
45
    {
46 1
        return new ErrorHandler($this->getLogger() ?: $this->getDefaultLogger());
47
    }
48
49
    /**
50
     * @return ErrorHandler
51
     */
52 1
    public function buildAndRegister()
53
    {
54 1
        return ErrorHandler::register(
55 1
            $this->getLogger() ?: $this->getDefaultLogger(),
56 1
            $this->getErrorLevelMap(),
57 1
            $this->getExceptionLevel(),
0 ignored issues
show
Bug introduced by
$this->getExceptionLevel() of type string is incompatible with the type false|integer expected by parameter $exceptionLevel of Monolog\ErrorHandler::register(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
            /** @scrutinizer ignore-type */ $this->getExceptionLevel(),
Loading history...
58 1
            $this->getFatalLevel()
0 ignored issues
show
Bug introduced by
$this->getFatalLevel() of type string is incompatible with the type false|integer expected by parameter $fatalLevel of Monolog\ErrorHandler::register(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

58
            /** @scrutinizer ignore-type */ $this->getFatalLevel()
Loading history...
59
        );
60
    }
61
62
    /**
63
     * @return string
64
     */
65 3
    public function getFatalLevel()
66
    {
67 3
        return $this->fatalLevel;
68
    }
69
70
    /**
71
     * @param string $level
72
     * @return ErrorHandlerBuilder
73
     */
74 1
    public function setFatalLevel($level)
75
    {
76 1
        $this->fatalLevel = $level;
77
78 1
        return $this;
79
    }
80
81
    /**
82
     * @return array
83
     */
84 3
    public function getErrorLevelMap()
85
    {
86 3
        return $this->errorLevelMap;
87
    }
88
89
    /**
90
     * @param array $map
91
     * @return ErrorHandlerBuilder
92
     */
93 1
    public function setErrorLevelMap(array $map)
94
    {
95 1
        $this->errorLevelMap = $map;
96
97 1
        return $this;
98
    }
99
100
    /**
101
     * @return string
102
     */
103 3
    public function getExceptionLevel()
104
    {
105 3
        return $this->exceptionLevel;
106
    }
107
108
    /**
109
     * @param string $level
110
     * @return ErrorHandlerBuilder
111
     */
112 1
    public function setExceptionLevel($level)
113
    {
114 1
        $this->exceptionLevel = $level;
115
116 1
        return $this;
117
    }
118
119
    /**
120
     * @return Logger
121
     */
122 2
    public function getLogger()
123
    {
124 2
        return $this->logger;
125
    }
126
127
    /**
128
     * @param Logger $logger
129
     * @return ErrorHandlerBuilder
130
     */
131
    public function setLogger(Logger $logger)
132
    {
133
        $this->logger = $logger;
134
135
        return $this;
136
    }
137
138
    /**
139
     * @return Logger
140
     */
141 2
    protected function getDefaultLogger()
142
    {
143 2
        $builder = new LoggerBuilder();
144
145 2
        return $builder->build();
146
    }
147
}
148