Failed Conditions
Pull Request — develop (#3348)
by Sergei
22:47
created

DriverException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 36
rs 10
c 0
b 0
f 0
ccs 11
cts 11
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A getSQLState() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Exception;
6
7
use Doctrine\DBAL\DBALException;
8
use Doctrine\DBAL\Driver\DriverException as DriverExceptionInterface;
9
use Exception;
10
11
/**
12
 * Base class for all errors detected in the driver.
13
 */
14
class DriverException extends DBALException implements DriverExceptionInterface
15
{
16
    /**
17
     * The previous DBAL driver exception.
18
     *
19
     * @var DriverExceptionInterface
20
     */
21
    private $driverException;
22
23
    /**
24
     * @param string                   $message         The exception message.
25
     * @param DriverExceptionInterface $driverException The DBAL driver exception to chain.
26
     */
27 3104
    public function __construct(string $message, DriverExceptionInterface $driverException)
28
    {
29 3104
        $exception = null;
30 3104
        $code      = 0;
31
32 3104
        if ($driverException instanceof Exception) {
33 3104
            $exception = $driverException;
34 3104
            $code      = $driverException->getCode();
35
        }
36
37 3104
        parent::__construct($message, $code, $exception);
38
39 3104
        $this->driverException = $driverException;
40 3104
    }
41
42
    /**
43
     * Returns the SQLSTATE the driver was in at the time the error occurred, if given.
44
     *
45
     * Returns null if no SQLSTATE was given by the driver.
46
     */
47 2808
    public function getSQLState() : ?string
48
    {
49 2808
        return $this->driverException->getSQLState();
50
    }
51
}
52