Completed
Push — master ( 748631...59ad9d )
by Alec
02:49
created

DoesProcessException::doesThrowsOnError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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
        $this->debugException($e);
45 1
    }
46
47
    /**
48
     * @param \Throwable $e
49
     */
50 1
    protected function debugException(\Throwable $e): void
51
    {
52 1
        if (\defined('APP_DEBUG') && APP_DEBUG) {
53 1
            if (\defined('DEBUG_DUMP_EXCEPTION') && DEBUG_DUMP_EXCEPTION) {
54 1
                $exceptionMessage = '[' . \get_class($e) . '] ' . $e->getMessage();
55 1
                $this->dump($exceptionMessage, $e->getTraceAsString());
56
            }
57 1
            if (\defined('DEBUG_DUMP_EXCEPTION_CLASS') && DEBUG_DUMP_EXCEPTION_CLASS) {
58 1
                $this->dump($e);
59
            }
60
        }
61 1
    }
62
63
    /**
64
     * @param mixed ...$that
65
     */
66 1
    protected function dump(...$that): void
67
    {
68 1
        if (\function_exists('dump')) {
69 1
            dump(...$that);
70
        } else {
71
            // @codeCoverageIgnoreStart
72
            var_dump(...$that);
1 ignored issue
show
Security Debugging Code introduced by
var_dump($that) looks like debug code. Are you sure you do not want to remove it?
Loading history...
73
            // @codeCoverageIgnoreEnd
74
        }
75 1
    }
76
}
77