QueryException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A formatMessage() 0 4 1
A getQuery() 0 4 1
A getBindings() 0 4 1
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