Slave::disable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Ez\DbLinker;
4
5
6
class Slave extends ExtendedServer
7
{
8
    /**
9
     * @var int
10
     */
11
    protected $weight;
12
13
    /**
14
     * @return int
15
     */
16
    public function getWeight(): int
17
    {
18
        return $this->weight;
19
    }
20
21
    public function status() {
22
        if (stripos($this->driver, 'pgsql') !== false) {
23
            try {
24
                $sss = $this->connection()->query('SELECT now() - pg_last_xact_replay_timestamp() AS replication_lag')->fetch();
25
                return $this->setSlaveStatus(true, $sss['replication_lag']);
0 ignored issues
show
Bug introduced by
The method setSlaveStatus() does not exist on Ez\DbLinker\Slave. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
26
            } catch (\Exception $e) {
27
                return $this->setSlaveStatus(false, null);
0 ignored issues
show
Bug introduced by
The method setSlaveStatus() does not exist on Ez\DbLinker\Slave. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
28
            }
29
        } else {
30
            try {
31
                $sss = $this->connection()->query('SHOW SLAVE STATUS')->fetch();
32
                if ($sss['Slave_IO_Running'] === 'No' || $sss['Slave_SQL_Running'] === 'No') {
33
                    // slave is STOPPED
34
                    return $this->setSlaveStatus(false, null);
0 ignored issues
show
Bug introduced by
The method setSlaveStatus() does not exist on Ez\DbLinker\Slave. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
35
                } else {
36
                    return $this->setSlaveStatus(true, $sss['Seconds_Behind_Master']);
0 ignored issues
show
Bug introduced by
The method setSlaveStatus() does not exist on Ez\DbLinker\Slave. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
37
                }
38
            } catch (\Exception $e) {
39
                if (stripos($e->getMessage(), 'Access denied') !== false) {
40
                    return $this->setSlaveStatus(true, 0);
0 ignored issues
show
Bug introduced by
The method setSlaveStatus() does not exist on Ez\DbLinker\Slave. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
41
                }
42
                return $this->setSlaveStatus(false, null);
0 ignored issues
show
Bug introduced by
The method setSlaveStatus() does not exist on Ez\DbLinker\Slave. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
43
            }
44
        }
45
    }
46
47
    public function disable() {
48
        $this->weight = 0;
49
        $this->connection = null;
50
    }
51
}