Completed
Pull Request — master (#34)
by kacper
04:27
created

QueryDTO   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Test Coverage

Coverage 40%

Importance

Changes 0
Metric Value
dl 0
loc 96
ccs 10
cts 25
cp 0.4
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getDatabase() 0 3 1
A getExecutionTime() 0 3 1
A jsonSerialize() 0 3 1
A getQuery() 0 3 1
A __toString() 0 10 1
A __construct() 0 11 1
A getType() 0 3 1
1
<?php
2
3
namespace MySQLReplication\Event\DTO;
4
5
use MySQLReplication\Definitions\ConstEventsNames;
6
use MySQLReplication\Event\EventInfo;
7
8
/**
9
 * Class QueryDTO
10
 * @package MySQLReplication\Event\DTO
11
 */
12
class QueryDTO extends EventDTO
13
{
14
    /**
15
     * @var int
16
     */
17
    private $executionTime;
18
    /**
19
     * @var string
20
     */
21
    private $query;
22
    /**
23
     * @var string
24
     */
25
    private $database;
26
    /**
27
     * @var string
28
     */
29
    private $type = ConstEventsNames::QUERY;
30
31
    /**
32
     * QueryEventDTO constructor.
33
     * @param EventInfo $eventInfo
34
     * @param string $database
35
     * @param int $executionTime
36
     * @param string $query
37
     */
38 54
    public function __construct(
39
        EventInfo $eventInfo,
40
        $database,
41
        $executionTime,
42
        $query
43
    ) {
44 54
        parent::__construct($eventInfo);
45
46 54
        $this->executionTime = $executionTime;
47 54
        $this->query = $query;
48 54
        $this->database = $database;
49 54
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function getDatabase()
55
    {
56
        return $this->database;
57
    }
58
59
    /**
60
     * @return int
61
     */
62
    public function getExecutionTime()
63
    {
64
        return $this->executionTime;
65
    }
66
67
    /**
68
     * @return string
69
     */
70 3
    public function getQuery()
71
    {
72 3
        return $this->query;
73
    }
74
75
    /**
76
     * @return string
77
     */
78 54
    public function getType()
79
    {
80 54
        return $this->type;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function __toString()
87
    {
88
        return PHP_EOL .
89
            '=== Event ' . $this->getType() . ' === ' . PHP_EOL .
90
            'Date: ' . $this->eventInfo->getDateTime() . PHP_EOL .
91
            'Log position: ' . $this->eventInfo->getPos() . PHP_EOL .
92
            'Event size: ' . $this->eventInfo->getSize() . PHP_EOL .
93
            'Database: ' . $this->database . PHP_EOL .
94
            'Execution time: ' . $this->executionTime . PHP_EOL .
95
            'Query: ' . $this->query . PHP_EOL;
96
    }
97
98
    /**
99
     * Specify data which should be serialized to JSON
100
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
101
     * @return mixed data which can be serialized by <b>json_encode</b>,
102
     * which is a value of any type other than a resource.
103
     * @since 5.4.0
104
     */
105
    public function jsonSerialize()
106
    {
107
        return get_object_vars($this);
108
    }
109
}
110
111