PostgreSQLRetryStrategy::errorCode()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Ez\DbLinker\RetryStrategy;
4
5
use Exception;
6
use Ez\DbLinker\RetryStrategy as RetryStrategyInterface;
7
8
class PostgreSQLRetryStrategy implements RetryStrategyInterface
9
{
10
    use RetryStrategy;
11
12
    private function errorCodeStrategies() {
13
        return [
14
            // CONNECTION FAILURE
15
            "08006" => ["changeServer" => true],
16
            // TOO MANY CONNECTIONS
17
            "53300" => ["wait" => 1],
18
        ];
19
    }
20
21
    private function errorCode(Exception $exception)
22
    {
23
        if(preg_match("/SQLSTATE\[(?<errorCode>[A-Z0-9]*)\]/", $exception->getMessage(), $matches)) {
24
            $code = $matches["errorCode"];
25
            if ($code === 'HY000') {
26
                $code = '08006';
27
            }
28
            return $code;
29
        }
30
    }
31
}
32