Passed
Push — master ( aa4e87...f3213a )
by Alec
02:08
created

DoesProcessException   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
eloc 22
dl 0
loc 52
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A doNotThrowOnError() 0 4 1
A throwOnError() 0 4 1
B processException() 0 23 10
A doesThrowsOnError() 0 3 1
1
<?php
2
/**
3
 * User: alec
4
 * Date: 28.12.18
5
 * Time: 15:21
6
 */
7
8
namespace AlecRabbit\Traits;
9
10
trait DoesProcessException
11
{
12
    /** @var bool */
13
    protected $throwOnError = true;
14
15
    /** @return self */
16 1
    public function doNotThrowOnError(): self
17
    {
18 1
        $this->throwOnError = false;
19 1
        return $this;
20
    }
21
22
    /** @return self */
23 1
    public function throwOnError(): self
24
    {
25 1
        $this->throwOnError = true;
26 1
        return $this;
27
    }
28
29
    /** @return bool */
30 2
    public function doesThrowsOnError(): bool
31
    {
32 2
        return $this->throwOnError;
33
    }
34
35
    /**
36
     * @param \Throwable $e
37
     * @throws \Throwable
38
     */
39 2
    protected function processException(\Throwable $e): void
40
    {
41 2
        if ($this->throwOnError) {
42 1
            throw $e;
43
        }
44 1
        if (\defined('APP_DEBUG') && APP_DEBUG) {
45 1
            $hasDumpFunction = \function_exists('dump');
46 1
            if (\defined('DEBUG_DUMP_EXCEPTION') && DEBUG_DUMP_EXCEPTION) {
47 1
                $exceptionMessage = '[' . \get_class($e) . '] ' . $e->getMessage();
48 1
                if ($hasDumpFunction) {
49 1
                    dump($exceptionMessage, $e->getTraceAsString());
50
                } else {
51
                    // @codeCoverageIgnoreStart
52
                    var_dump($exceptionMessage, $e->getTraceAsString());
1 ignored issue
show
Security Debugging Code introduced by
var_dump($exceptionMessa...$e->getTraceAsString()) looks like debug code. Are you sure you do not want to remove it?
Loading history...
53
                    // @codeCoverageIgnoreEnd
54
                }
55
            }
56 1
            if (\defined('DEBUG_DUMP_EXCEPTION_CLASS') && DEBUG_DUMP_EXCEPTION_CLASS) {
57 1
                if ($hasDumpFunction) {
58 1
                    dump($e);
59
                } else {
60
                    // @codeCoverageIgnoreStart
61
                    var_dump($e);
62
                    // @codeCoverageIgnoreEnd
63
                }
64
            }
65
        }
66 1
    }
67
}
68