Transaction   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 50
ccs 17
cts 17
cp 1
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A assertType() 0 4 2
A __construct() 0 7 1
A jsonSerialize() 0 5 1
A assertName() 0 4 2
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Events\MetricSet;
4
5
use ZoiloMora\ElasticAPM\Events\Common\TransactionName;
6
use ZoiloMora\ElasticAPM\Events\Common\TransactionType;
7
8
final class Transaction implements \JsonSerializable
9
{
10
    use TransactionName;
11
    use TransactionType;
12
13
    /**
14
     * @param string $name
15
     * @param string $type
16
     */
17 5
    public function __construct($name, $type)
18
    {
19 5
        $this->assertName($name);
20 4
        $this->assertType($type);
21
22 3
        $this->name = (string) $name;
23 3
        $this->type = (string) $type;
24 3
    }
25
26
    /**
27
     * @param mixed $name
28
     *
29
     * @return void
30
     */
31 5
    private function assertName($name)
32
    {
33 5
        if (false === is_string($name)) {
34 1
            throw new \InvalidArgumentException('The [name] must be of type string.');
35
        }
36 4
    }
37
38
    /**
39
     * @param mixed $type
40
     *
41
     * @return void
42
     */
43 4
    private function assertType($type)
44
    {
45 4
        if (false === is_string($type)) {
46 1
            throw new \InvalidArgumentException('The [type] must be of type string.');
47
        }
48 3
    }
49
50
    /**
51
     * @return array
52
     */
53 2
    public function jsonSerialize()
54
    {
55
        return [
56 2
            'name' => $this->getEncodingName(),
57 2
            'type' => $this->getEncodingType(),
58 2
        ];
59
    }
60
}
61