Failed Conditions
Pull Request — develop (#3367)
by Benjamin
14:32
created

DriverException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 71
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSQLState() 0 3 1
A __construct() 0 6 1
A noSuchSequence() 0 3 1
A getErrorCode() 0 3 1
A noInsertId() 0 3 1
1
<?php
2
3
namespace Doctrine\DBAL\Driver;
4
5
use Exception;
6
use Throwable;
7
8
/**
9
 * A driver exception.
10
 *
11
 * Driver exceptions provide the SQLSTATE of the driver
12
 * and the driver specific error code at the time the error occurred.
13
 */
14
class DriverException extends Exception
15
{
16
    /**
17
     * The driver specific error code.
18
     *
19
     * @var int|string|null
20
     */
21
    private $errorCode;
22
23
    /**
24
     * The SQLSTATE of the driver.
25
     *
26
     * @var string|null
27
     */
28
    private $sqlState;
29
30
    /**
31
     * @param string          $message   The driver error message.
32
     * @param string|null     $sqlState  The SQLSTATE the driver is in at the time the error occurred, if any.
33
     * @param int|string|null $errorCode The driver specific error code if any.
34
     * @param Throwable|null  $previous  The previous throwable used for the exception chaining.
35
     */
36 3502
    public function __construct(string $message, ?string $sqlState = null, $errorCode = null, ?Throwable $previous = null)
37
    {
38 3502
        parent::__construct($message, 0, $previous);
39
40 3502
        $this->errorCode = $errorCode;
41 3502
        $this->sqlState  = $sqlState;
42 3502
    }
43
44
    /**
45
     * @return DriverException
46
     */
47 28
    public static function noInsertId() : self
48
    {
49 28
        return new self('No identity value was generated by the last statement.');
50
    }
51
52
    /**
53
     * @param string $name The sequence name.
54
     *
55
     * @return DriverException
56
     */
57 2
    public static function noSuchSequence(string $name) : self
58
    {
59 2
        return new self('No sequence with name "' . $name . '" found.');
60
    }
61
62
    /**
63
     * Returns the driver specific error code if available.
64
     *
65
     * Returns null if no driver specific error code is available
66
     * for the error raised by the driver.
67
     *
68
     * @return int|string|null
69
     */
70 2014
    public function getErrorCode()
71
    {
72 2014
        return $this->errorCode;
73
    }
74
75
    /**
76
     * Returns the SQLSTATE the driver was in at the time the error occurred.
77
     *
78
     * Returns null if the driver does not provide a SQLSTATE for the error occurred.
79
     *
80
     * @return string|null
81
     */
82 1156
    public function getSQLState() : ?string
83
    {
84 1156
        return $this->sqlState;
85
    }
86
}
87