DatabaseException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 54
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addIgnoredException() 0 4 1
A getIgnoredExceptions() 0 4 1
A __toString() 0 13 3
1
<?php
2
namespace DAL\Exceptions;
3
4
use \Exception;
5
use \RuntimeException;
6
7
class DatabaseException extends RuntimeException
8
{
9
10
    /**
11
     * @var Exception[]
12
     */
13
    private $ignored = [];
14
15
    /**
16
     * Adds an exception that was most likely ignored to reattempt execution.
17
     *
18
     * @param Exception $value The exception that was ignored.
19
     * @return void
20
     */
21
    public function addIgnoredException(Exception $value)
22
    {
23
        $this->ignored[] = $value;
24
    }
25
26
    /**
27
     * Returns an array of all of the ignored exceptions.
28
     *
29
     * @return Exception[] A list of all of the ignored Exception objects.
30
     */
31
    public function getIgnoredExceptions()
32
    {
33
        return $this->ignored;
34
    }
35
36
    /**
37
     * Returns the string reprensentation of this exception.
38
     *
39
     * The returned string may include...
40
     *  1. The class name.
41
     *  2. Message.
42
     *  3. The previous exception with __toString called on it, if it exists.
43
     *  4. All of the ignored exceptions with __toString called on each of them.
44
     *
45
     * @return string
46
     */
47
    public function __toString()
48
    {
49
        $info     = get_class() . ' - ' . $this->getMessage();
50
        $previous = $this->getPrevious();
51
        if (null !== $previous) {
52
            $info .= ' - Previous Exception: ' . (string) $this->getPrevious();
53
        }
54
        foreach ($this->ignored as $exception) {
55
            $info .= "\nIgnored Exception: " . (string) $exception;
56
        }
57
58
        return $info;
59
    }
60
}
61