Transaction::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 10
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