Failed Conditions
Pull Request — develop (#3154)
by Sergei
115:35 queued 50:33
created

PDOException::fromPDOException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Doctrine\DBAL\Driver;
4
5
/**
6
 * Tiny wrapper for PDOException instances to implement the {@link DriverException} interface.
7
 *
8
 * @author Steve Müller <[email protected]>
9
 * @link   www.doctrine-project.org
10
 * @since  2.5
11
 */
12
class PDOException extends AbstractDriverException
13
{
14
    /**
15
     * The driver specific error code.
16
     *
17
     * @var int|string|null
18
     */
19
    private $errorCode;
20
21
    /**
22
     * The SQLSTATE of the driver.
23
     *
24
     * @var string|null
25
     */
26
    private $sqlState;
27
28
    public static function fromPDOException(\PDOException $exception)
29
    {
30
        $e = new self(
31
            $exception->getMessage(),
32
            $exception->errorInfo[0] ?? $exception->getCode(),
33
            $exception->errorInfo[1] ?? $exception->getCode()
34
        );
35
36
        $e->code = $exception->getCode();
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getErrorCode()
43
    {
44
        return $this->errorCode;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getSQLState()
51
    {
52
        return $this->sqlState;
53
    }
54
}
55