PostgresConnection::getExceptionType()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 0
Metric Value
cc 3
eloc 7
c 0
b 0
f 0
nc 3
nop 3
dl 0
loc 11
ccs 4
cts 6
cp 0.6667
crap 3.3332
rs 10
1
<?php
2
3
namespace mindplay\sql\postgres;
4
5
use mindplay\sql\exceptions\ForeignKeyException;
6
use mindplay\sql\exceptions\SQLException;
7
use mindplay\sql\exceptions\UniqueConstraintException;
8
use mindplay\sql\framework\pdo\PDOConnection;
9
10
class PostgresConnection extends PDOConnection
11
{
12 1
    public function getExceptionType(string $sql_state, int $error_code, string $error_message): string
13
    {
14
        switch ($sql_state) {
15 1
            case '23503':
16
                return ForeignKeyException::class;
17
18 1
            case '23505':
19
                return UniqueConstraintException::class;
20
21
            default:
22 1
                return SQLException::class;
23
        }
24
    }
25
}
26