Completed
Pull Request — master (#3759)
by Benjamin
63:00
created

PDOException::fromNativePDOException()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Driver;
6
7
/**
8
 * Tiny wrapper for PDOException instances to implement the {@link DriverException} interface.
9
 */
10
class PDOException extends AbstractDriverException
11
{
12
    public static function fromNativePDOException(\PDOException $exception) : PDOException
13
    {
14
        if ($exception->errorInfo !== null) {
15
            [$sqlState, $code] = $exception->errorInfo;
16
        } else {
17
            $code     = $exception->getCode();
18
            $sqlState = null;
19
        }
20
21
        return new self($exception->getMessage(), $sqlState, $code, $exception);
22
    }
23
}
24