MySQLConnection::getExceptionType()   B
last analyzed

Complexity

Conditions 10
Paths 10

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 110

Importance

Changes 0
Metric Value
cc 10
eloc 14
c 0
b 0
f 0
nc 10
nop 3
dl 0
loc 18
ccs 0
cts 13
cp 0
crap 110
rs 7.6666

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace mindplay\sql\mysql;
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 MySQLConnection extends PDOConnection
11
{
12
    public function getExceptionType(string $sql_state, int $error_code, string $error_message): string
13
    {
14
        switch ($error_code) {
15
            case '1216':
16
            case '1217':
17
            case '1451':
18
            case '1452':
19
            case '1701':
20
                return ForeignKeyException::class;
21
22
            case '1062':
23
            case '1557':
24
            case '1569':
25
            case '1586':
26
                return UniqueConstraintException::class;
27
28
            default:
29
                return SQLException::class;
30
        }
31
    }
32
}
33