Completed
Push — master ( 9728d9...4d9a08 )
by Sergei
27s queued 16s
created

DB2Exception::fromConnectionError()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 0
cts 6
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\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 58
    public static function fromStatementError($statement = null) : self
31
    {
32 58
        if ($statement !== null) {
33
            return new self(db2_stmt_errormsg($statement), db2_stmt_error($statement));
34
        }
35
36 58
        return new self(db2_stmt_errormsg(), db2_stmt_error());
37
    }
38
}
39