Event::__construct()   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;
4
5
use ZoiloMora\ElasticAPM\Helper\Cryptography;
6
use ZoiloMora\ElasticAPM\Helper\Encoding;
7
8
abstract class Event implements \JsonSerializable
9
{
10
    const EVENT_ID_BITS = 64;
11
12
    /**
13
     * Hex encoded 64 random bits ID of the transaction.
14
     *
15
     * @var string
16
     */
17
    protected $id;
18
19 32
    public function __construct()
20
    {
21 32
        $this->id = $this->generateId();
22 32
    }
23
24
    /**
25
     * @return string
26
     */
27 5
    public function id()
28
    {
29 5
        return $this->id;
30
    }
31
32
    /**
33
     * @return string
34
     *
35
     * @throws \Exception
36
     */
37 32
    private function generateId()
38
    {
39 32
        return Cryptography::generateRandomBitsInHex(self::EVENT_ID_BITS);
40
    }
41
42
    /**
43
     * @return array
44
     */
45 5
    public function jsonSerialize()
46
    {
47
        return [
48 5
            'id' => Encoding::keywordField($this->id),
49 5
        ];
50
    }
51
}
52