Passed
Push — main ( dd9fcf...7064c3 )
by BRUNO
02:37
created

DatabaseException::getParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace BMorais\Database;
4
5
use Exception;
6
use Throwable;
7
8
/**
9
 * Custom Database Exception
10
 *
11
 * @author Bruno Morais <[email protected]>
12
 * @copyright MIT, bmorais.com
13
 * @package bmorais\database
14
 */
15
class DatabaseException extends Exception
16
{
17
    private ?string $query;
18
    private ?array $parameters;
19
20
    public function __construct(
21
        string $message,
22
        int $code = 0,
23
        ?Throwable $previous = null,
24
        ?string $query = null,
25
        ?array $parameters = null
26
    ) {
27
        parent::__construct($message, $code, $previous);
28
        $this->query = $query;
29
        $this->parameters = $parameters;
30
    }
31
32
    public function getQuery(): ?string
33
    {
34
        return $this->query;
35
    }
36
37
    public function getParameters(): ?array
38
    {
39
        return $this->parameters;
40
    }
41
42
    public function getContextInfo(): array
43
    {
44
        return [
45
            'message' => $this->getMessage(),
46
            'query' => $this->query,
47
            'parameters' => $this->parameters,
48
            'file' => $this->getFile(),
49
            'line' => $this->getLine()
50
        ];
51
    }
52
}