Completed
Push — master ( 6d673d...7f4ef4 )
by Sergei
40:47 queued 40:43
created

DB2Exception   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 6
dl 0
loc 24
c 0
b 0
f 0
ccs 0
cts 13
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromConnectionError() 0 7 2
A fromStatementError() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Driver\IBMDB2;
6
7
use Doctrine\DBAL\Driver\AbstractDriverException;
8
use function db2_conn_error;
9
use function db2_conn_errormsg;
10
use function db2_stmt_error;
11
use function db2_stmt_errormsg;
12
13
class DB2Exception extends AbstractDriverException
14
{
15
    /**
16
     * @param resource|null $connection
17
     */
18
    public static function fromConnectionError($connection = null) : self
19
    {
20
        if ($connection !== null) {
21
            return new self(db2_conn_errormsg($connection), db2_conn_error($connection));
22
        }
23
24
        return new self(db2_conn_errormsg(), db2_conn_error());
25
    }
26
27
    /**
28
     * @param resource|null $statement
29
     */
30
    public static function fromStatementError($statement = null) : self
31
    {
32
        if ($statement !== null) {
33
            return new self(db2_stmt_errormsg($statement), db2_stmt_error($statement));
34
        }
35
36
        return new self(db2_stmt_errormsg(), db2_stmt_error());
37
    }
38
}
39