Passed
Push — master ( 67cef4...aa4e87 )
by Alec
02:11
created

DoesProcessException::processException()   B

Complexity

Conditions 10
Paths 11

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 10

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 23
rs 7.6666
c 0
b 0
f 0
ccs 12
cts 12
cp 1
cc 10
nc 11
nop 1
crap 10

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
    public function throwOnError(): self
24
    {
25
        $this->throwOnError = true;
26
        return $this;
27
    }
28
29
    /**
30
     * @param \Throwable $e
31
     * @throws \Throwable
32
     */
33 2
    protected function processException(\Throwable $e): void
34
    {
35 2
        if ($this->throwOnError) {
36 1
            throw $e;
37
        }
38 1
        $hasDumpFunction = \function_exists('dump');
39 1
        if (\defined('APP_DEBUG') && APP_DEBUG) {
40 1
            if (\defined('DEBUG_DUMP_EXCEPTION') && DEBUG_DUMP_EXCEPTION) {
41 1
                $exceptionMessage = '[' . \get_class($e) . '] ' . $e->getMessage();
42 1
                if ($hasDumpFunction) {
43 1
                    dump($exceptionMessage, $e->getTraceAsString());
44
                } else {
45
                    // @codeCoverageIgnoreStart
46
                    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...
47
                    // @codeCoverageIgnoreEnd
48
                }
49
            }
50 1
            if (\defined('DEBUG_DUMP_EXCEPTION_CLASS') && DEBUG_DUMP_EXCEPTION_CLASS) {
51 1
                if ($hasDumpFunction) {
52 1
                    dump($e);
53
                } else {
54
                    // @codeCoverageIgnoreStart
55
                    var_dump($e);
56
                    // @codeCoverageIgnoreEnd
57
                }
58
            }
59
        }
60 1
    }
61
62
    public function doesThrowsOnError(): bool
63
    {
64
        return $this->throwOnError;
65
    }
66
}
67