Payload::assertRequiredParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 1
c 4
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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