QueryException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 3
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Magister\Services\Database;
4
5
/**
6
 * Class QueryException.
7
 */
8
class QueryException extends \Exception
9
{
10
    /**
11
     * The url which the query is targeting.
12
     *
13
     * @var string
14
     */
15
    protected $query;
16
17
    /**
18
     * The bindings for the query.
19
     *
20
     * @var array
21
     */
22
    protected $bindings;
23
24
    /**
25
     * Create a new query exception instance.
26
     *
27
     * @param string     $query
28
     * @param array      $bindings
29
     * @param \Exception $previous
30
     */
31
    public function __construct($query, array $bindings, $previous)
32
    {
33
        parent::__construct('', 0, $previous);
34
35
        $this->query = $query;
36
        $this->bindings = $bindings;
37
        $this->previous = $previous;
0 ignored issues
show
Bug introduced by
The property previous cannot be accessed from this context as it is declared private in class Exception.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
38
        $this->code = $previous->getCode();
39
        $this->message = $this->formatMessage($query, $bindings, $previous);
40
    }
41
42
    /**
43
     * Format the error message.
44
     *
45
     * @param string     $query
46
     * @param array      $bindings
47
     * @param \Exception $previous
48
     *
49
     * @return string
50
     */
51
    protected function formatMessage($query, $bindings, $previous)
52
    {
53
        return $previous->getMessage().' (Query: '.$query.', '.print_r($bindings, true).')';
54
    }
55
56
    /**
57
     * Get the url which the query is targeting.
58
     *
59
     * @return string
60
     */
61
    public function getQuery()
62
    {
63
        return $this->query;
64
    }
65
66
    /**
67
     * Get the bindings for the query.
68
     *
69
     * @return array
70
     */
71
    public function getBindings()
72
    {
73
        return $this->bindings;
74
    }
75
}
76