Failed Conditions
Push — master ( 11c8ec...b620eb )
by Bas
05:48 queued 10s
created

DetectsLostConnections::causedByLostConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 10
c 3
b 1
f 0
dl 0
loc 23
ccs 4
cts 4
cp 1
rs 9.9332
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace LaravelFreelancerNL\Aranguent\Concerns;
4
5
use Throwable;
6
7
trait DetectsLostConnections
8
{
9
    /**
10
     * Determine if the given exception was caused by a lost connection.
11
     *
12
     * @param \Throwable $e
13
     *
14
     * @return bool
15
     */
16 2
    protected function causedByLostConnection(Throwable $e)
17
    {
18
        // https://www.arangodb.com/docs/stable/appendix-error-codes.html
19
        // 30 - ERROR_SHUTTING_DOWN
20
        // 500 - ERROR_HTTP_SERVER_ERROR
21
        // 503 - ERROR_HTTP_SERVICE_UNAVAILABLE
22
        // 504 - ERROR_HTTP_GATEWAY_TIMEOUT
23
        // 1302 - ERROR_ARANGO_TRY_AGAIN
24
        // 1303 - ERROR_ARANGO_BUSY
25
        // 1464 - ERROR_CLUSTER_SHARD_GONE
26
        // 1465 - ERROR_CLUSTER_CONNECTION_LOST
27
28 2
        $code = $e->getCode();
29
30 2
        return in_array($code, [
31 2
            30,
32
            500,
33
            503,
34
            504,
35
            1302,
36
            1303,
37
            1464,
38
            1465,
39
        ]);
40
    }
41
}
42