Completed
Push — master ( 18d42b...fed0be )
by Rasmus
03:18
created

MySQLDriver::getExceptionType()   B

Complexity

Conditions 10
Paths 10

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 110

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
ccs 0
cts 13
cp 0
rs 7.2765
cc 10
eloc 15
nc 10
nop 3
crap 110

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\drivers;
4
5
use mindplay\sql\exceptions\ForeignKeyException;
6
use mindplay\sql\exceptions\SQLException;
7
use mindplay\sql\exceptions\UniqueConstraintException;
8
use mindplay\sql\framework\Driver;
9
10
class MySQLDriver implements Driver
11
{
12 1
    public function quoteName($name)
13
    {
14 1
        return '`' . $name . '`';
15
    }
16
17
    public function getExceptionType($sql_state, $error_code, $error_message)
18
    {
19
        switch ($error_code) {
20
            case '1216':
21
            case '1217':
22
            case '1451':
23
            case '1452':
24
            case '1701':
25
                return ForeignKeyException::class;
26
            
27
            case '1062':
28
            case '1557':
29
            case '1569':
30
            case '1586':
31
                return UniqueConstraintException::class;
32
            
33
            default:
34
                return SQLException::class;
35
        }
36
    }
37
}
38