Samples   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 43
ccs 20
cts 20
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A from() 0 13 4
A jsonSerialize() 0 18 2
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Events\MetricSet;
4
5
use ZoiloMora\ElasticAPM\Utils\Collection;
6
7
final class Samples extends Collection
8
{
9
    /**
10
     * @param array $items
11
     *
12
     * @return Samples
13
     */
14 5
    public static function from(array $items)
15
    {
16 5
        foreach ($items as $item) {
17 4
            if (false === $item instanceof Sample) {
18 1
                throw new \InvalidArgumentException('All elements must be of type Sample.');
19
            }
20 4
        }
21
22 4
        if (0 === count($items)) {
23 1
            throw new \InvalidArgumentException('There must be at least one element.');
24
        }
25
26 3
        return parent::from($items);
27
    }
28
29
    /**
30
     * @return array
31
     */
32 2
    public function jsonSerialize()
33
    {
34 2
        $result = [];
35
36 2
        $items = parent::jsonSerialize();
37
38
        /** @var Sample $item */
39 2
        foreach ($items as $item) {
40 2
            $result = array_merge(
41 2
                $result,
42 2
                (array) json_decode(
43 2
                    (string) json_encode($item),
44
                    true
45 2
                )
46 2
            );
47 2
        }
48
49 2
        return $result;
50
    }
51
}
52