isGoneAwayInUpdateException()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 12
loc 12
c 0
b 0
f 0
ccs 0
cts 6
cp 0
rs 9.8666
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
namespace Adgoal\DBALFaultTolerance\Driver;
4
5
use Throwable;
6
7
/**
8
 * Trait ServerGoneAwayExceptionsAwareTrait.
9
 */
10
trait ServerGoneAwayExceptionsAwareTrait
11
{
12
    /** @var string[] */
13
    protected $goneAwayExceptions = [
14
        'MySQL server has gone away', //code 2006
15
        'Lost connection to MySQL server during query', //code 2013
16
        'The MySQL server is running with the --read-only option so it cannot execute this statement',
17
        'Connection refused',
18
        'Lost connection to MySQL server during query', //code 2013
19
        'Deadlock found when trying to get lock', //code 1213
20
        'Lock wait timeout exceeded', //code 1205
21
    ];
22
23
    /** @var string[] */
24
    protected $goneAwayInUpdateExceptions = [
25
        'MySQL server has gone away',
26
        'The MySQL server is running with the --read-only option so it cannot execute this statement',
27
        'Connection refused',
28
        'Deadlock found when trying to get lock', //code 1213
29
        'Lock wait timeout exceeded', //code 1205
30
    ];
31
32
    /**
33
     * @param Throwable $exception
34
     *
35
     * @return bool
36
     */
37 View Code Duplication
    public function isGoneAwayException(Throwable $exception): bool
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    {
39
        $message = $exception->getMessage();
40
41
        foreach ($this->goneAwayExceptions as $goneAwayException) {
42
            if (stripos($message, $goneAwayException) !== false) {
43
                return true;
44
            }
45
        }
46
47
        return false;
48
    }
49
50
    /**
51
     * @param Throwable $exception
52
     *
53
     * @return bool
54
     */
55 View Code Duplication
    public function isGoneAwayInUpdateException(Throwable $exception): bool
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        $message = $exception->getMessage();
58
59
        foreach ($this->goneAwayInUpdateExceptions as $goneAwayException) {
60
            if (stripos($message, $goneAwayException) !== false) {
61
                return true;
62
            }
63
        }
64
65
        return false;
66
    }
67
}
68