Completed
Push — master ( afaf42...8ac772 )
by Raffael
20:10 queued 16:21
created

AbstractBootstrap::setErrorHandler()   B

Complexity

Conditions 6
Paths 1

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 0
cts 29
cp 0
rs 8.7377
c 0
b 0
f 0
cc 6
nc 1
nop 0
crap 42
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * balloon
7
 *
8
 * @copyright   Copryright (c) 2012-2018 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Balloon\Bootstrap;
13
14
use ErrorException;
15
use Psr\Log\LoggerInterface;
16
17
abstract class AbstractBootstrap
18
{
19
    /**
20
     * Logger.
21
     *
22
     * @var LoggerInterface
23
     */
24
    protected $logger;
25
26
    /**
27
     * Inject object.
28
     *
29
     *
30
     * @return AbstractBootstrap
31
     */
32
    public function inject($object): self
0 ignored issues
show
Unused Code introduced by
The parameter $object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
    {
34
        return $this;
35
    }
36
37
    /**
38
     * Set error handler.
39
     *
40
     * @return AbstractBootstrap
41
     */
42
    protected function setErrorHandler(): self
43
    {
44
        set_error_handler(function ($severity, $message, $file, $line) {
45
            $log = $message.' in '.$file.':'.$line;
46
47
            switch ($severity) {
48
                case E_ERROR:
49
                case E_USER_ERROR:
50
                    $this->logger->error($log, [
51
                        'category' => get_class($this),
52
                    ]);
53
54
                break;
55
                case E_WARNING:
56
                case E_USER_WARNING:
57
                    $this->logger->warning($log, [
58
                        'category' => get_class($this),
59
                    ]);
60
61
                break;
62
                default:
63
                    $this->logger->debug($log, [
64
                        'category' => get_class($this),
65
                    ]);
66
67
                break;
68
            }
69
70
            if (error_reporting() !== 0) {
71
                throw new ErrorException($message, 0, $severity, $file, $line);
72
            }
73
        });
74
75
        return $this;
76
    }
77
}
78