Payload   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 1
Metric Value
wmc 7
eloc 11
c 6
b 0
f 1
dl 0
loc 37
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 3 1
A __construct() 0 4 2
A __get() 0 3 1
A insert() 0 3 1
A assertRequiredParameters() 0 3 1
A __call() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace OniBus;
5
6
use Countable;
7
use IteratorAggregate;
8
use JsonSerializable;
9
use OniBus\Utility\Assert;
10
use OniBus\Utility\KeyValueList;
11
12
class Payload implements JsonSerializable, IteratorAggregate, Countable
13
{
14
    use KeyValueList {
15
        set as protected;
16
        delete as protected;
17
    }
18
19
    public function __construct(array $data = [])
20
    {
21
        foreach ($data as $item => $value) {
22
            $this->insert($item, $value);
23
        }
24
    }
25
26
    protected function insert($item, $value)
27
    {
28
        $this->set($item, $value);
29
    }
30
31
    protected function assertRequiredParameters(array $required): void
32
    {
33
        Assert::requiredParameters($required, $this->toArray(), $this);
34
    }
35
36
    public function __get($name)
37
    {
38
        return $this->get($name);
39
    }
40
41
    public function __call($name, $arguments)
42
    {
43
        return $this->get($name);
44
    }
45
46
    public function jsonSerialize(): array
47
    {
48
        return $this->toArray();
49
    }
50
}
51