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

DefaultExceptionHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 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
}