Db::user()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Events\Span\Context;
4
5
use ZoiloMora\ElasticAPM\Helper\Encoding;
6
7
/**
8
 * An object containing contextual data for database spans
9
 */
10
final class Db implements \JsonSerializable
11
{
12
    /**
13
     * Database instance name
14
     *
15
     * @var string|null
16
     */
17
    private $instance;
18
19
    /**
20
     * Database link
21
     *
22
     * @var string|null
23
     */
24
    private $link;
25
26
    /**
27
     * A database statement (e.g. query) for the given database type
28
     *
29
     * @var string|null
30
     */
31
    private $statement;
32
33
    /**
34
     * Database type. For any SQL database, "sql".
35
     * For others, the lower-case database category, e.g. "cassandra", "hbase", or "redis"
36
     *
37
     * @var string|null
38
     */
39
    private $type;
40
41
    /**
42
     * Username for accessing database
43
     *
44
     * @var string|null
45
     */
46
    private $user;
47
48
    /**
49
     * Number of rows affected by the SQL statement (if applicable)
50
     *
51
     * @var string|null
52
     */
53
    private $rowsAffected;
54
55
    /**
56
     * @param string|null $instance
57
     * @param string|null $link
58
     * @param string|null $statement
59
     * @param string|null $type
60
     * @param string|null $user
61
     * @param string|null $rowsAffected
62
     */
63 3
    public function __construct(
64
        $instance = null,
65
        $link = null,
66
        $statement = null,
67
        $type = null,
68
        $user = null,
69
        $rowsAffected = null
70
    ) {
71 3
        $this->instance = $instance;
72 3
        $this->link = $link;
73 3
        $this->statement = $statement;
74 3
        $this->type = $type;
75 3
        $this->user = $user;
76 3
        $this->rowsAffected = $rowsAffected;
77 3
    }
78
79
    /**
80
     * @return string|null
81
     */
82 1
    public function instance()
83
    {
84 1
        return $this->instance;
85
    }
86
87
    /**
88
     * @return string|null
89
     */
90 1
    public function link()
91
    {
92 1
        return $this->link;
93
    }
94
95
    /**
96
     * @return string|null
97
     */
98 1
    public function statement()
99
    {
100 1
        return $this->statement;
101
    }
102
103
    /**
104
     * @return string|null
105
     */
106 1
    public function type()
107
    {
108 1
        return $this->type;
109
    }
110
111
    /**
112
     * @return string|null
113
     */
114 1
    public function user()
115
    {
116 1
        return $this->user;
117
    }
118
119
    /**
120
     * @return string|null
121
     */
122 1
    public function rowsAffected()
123
    {
124 1
        return $this->rowsAffected;
125
    }
126
127
    /**
128
     * @return array
129
     */
130 1
    public function jsonSerialize()
131
    {
132
        return [
133 1
            'instance' => $this->instance,
134 1
            'link' => Encoding::keywordField($this->link),
135 1
            'statement' => $this->statement,
136 1
            'type' => $this->type,
137 1
            'user' => $this->user,
138 1
            'rows_affected' => $this->rowsAffected,
139 1
        ];
140
    }
141
}
142