Passed
Pull Request — main (#122)
by Andreas
02:00
created

Exception::new()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 12
ccs 0
cts 7
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Crate\DBAL\Driver\PDOCrate;
6
7
use Doctrine\DBAL\Driver\AbstractException;
8
use PDOException;
9
10
/** @internal */
11
final class Exception extends AbstractException
12
{
13
    public static function new(PDOException $exception): self
14
    {
15
        if ($exception->errorInfo !== null) {
16
            [$sqlState, $code] = $exception->errorInfo;
17
18
            $code ??= 0;
19
        } else {
20
            $code     = $exception->getCode();
21
            $sqlState = null;
22
        }
23
24
        return new self($exception->getMessage(), $sqlState, $code, $exception);
25
    }
26
}
27