Passed
Push — master ( d4d417...37f3ab )
by Mike
03:14
created

DefaultExceptionHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 39
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shutdownXervicelication() 0 4 2
A __construct() 0 6 1
A handleException() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\ExceptionHandler\Business\Handler;
6
7
8
use Xervice\ExceptionHandler\Business\Printer\ExceptionPrinterInterface;
9
10
class DefaultExceptionHandler implements ExceptionHandlerInterface
11
{
12
    /**
13
     * @var ExceptionPrinterInterface
14
     */
15
    private $printer;
16
17
    /**
18
     * @var bool
19
     */
20
    private $shutdownIfError;
21
22
    /**
23
     * DefaultExceptionHandler constructor.
24
     *
25
     * @param ExceptionPrinterInterface $printer
26
     * @param bool $shutdownIfError
27
     */
28 1
    public function __construct(
29
        ExceptionPrinterInterface $printer,
30
        bool $shutdownIfError
31
    ) {
32 1
        $this->printer = $printer;
33 1
        $this->shutdownIfError = $shutdownIfError;
34 1
    }
35
36
    /**
37
     * @param \Exception $exception
38
     */
39 1
    public function handleException(\Exception $exception): void
40
    {
41 1
        $this->printer->printExeption($exception);
42 1
        $this->shutdownXervicelication();
43 1
    }
44
45 1
    protected function shutdownXervicelication(): void
46
    {
47 1
        if ($this->shutdownIfError) {
48
            exit;
1 ignored issue
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
49
        }
50
    }
51
}