MysqlRetryStrategy::errorCode()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
3
namespace Ez\DbLinker\RetryStrategy;
4
5
use Exception;
6
use Doctrine\DBAL\Driver\DriverException as DDriverException;
7
use Doctrine\DBAL\Exception\DriverException as EDriverException;
8
use Ez\DbLinker\RetryStrategy as RetryStrategyInterface;
9
10
class MysqlRetryStrategy implements RetryStrategyInterface
11
{
12
    use RetryStrategy;
13
14
    private function errorCodeStrategies() {
15
        return [
16
            // ER_CON_COUNT_ERROR
17
            1040 => ["wait" => 1],
18
            // ER_CON_USER_COUNT_ERROR
19
            1203 => ["wait" => 1],
20
            // ER_DBACCESS_DENIED_ERROR
21
            1044 => ["changeServer" => true],
22
            // ER_ACCESS_DENIED_ERROR
23
            1045 => ["changeServer" => true],
24
            // ER_BAD_DB_ERROR
25
            1049 => ["changeServer" => true],
26
            // ER_ABORTING_CONNECTION
27
            1152 => ["wait" => 1],
28
            // ER_LOCK_WAIT_TIMEOUT
29
            1205 => ["wait" => 1],
30
            // ER_LOCK_WAIT_TIMEOUT
31
            1213 => ["wait" => 1],
32
            // CR_SERVER_GONE_ERROR
33
            2006 => ["reconnect" => true],
34
        ];
35
    }
36
37
    private function errorCode(Exception $exception)
38
    {
39
        if ($exception instanceof DDriverException || $exception instanceof EDriverException) {
40
            return $exception->getErrorCode();
41
        }
42
    }
43
}
44