BootstrapPayload   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 5 1
A __construct() 0 4 1
A getCIMetadata() 0 3 1
A getCIAent() 0 3 1
A toArray() 0 5 1
1
<?php
2
3
namespace TheAentMachine\Aent\Payload\Bootstrap;
4
5
use TheAentMachine\Aent\Payload\JsonPayloadInterface;
6
use TheAentMachine\Aent\Registry\AentItemRegistry;
7
8
final class BootstrapPayload implements JsonPayloadInterface
9
{
10
    /** @var AentItemRegistry */
11
    private $CIAent;
12
13
    /** @var array<string,string> */
14
    private $CIMetadata;
15
16
    /**
17
     * BootstrapPayload constructor.
18
     * @param AentItemRegistry $CIAent
19
     * @param array<string,string> $CIMetadata
20
     */
21
    public function __construct(AentItemRegistry $CIAent, array $CIMetadata)
22
    {
23
        $this->CIAent = $CIAent;
24
        $this->CIMetadata = $CIMetadata;
25
    }
26
27
    /**
28
     * @return mixed[]
29
     */
30
    public function toArray(): array
31
    {
32
        return [
33
            'CI_AENT' => $this->CIAent->toArray(),
34
            'CI_METADATA' => $this->CIMetadata,
35
        ];
36
    }
37
38
    /**
39
     * @param mixed[] $assoc
40
     * @return self
41
     */
42
    public static function fromArray(array $assoc): self
43
    {
44
        $CIAent = AentItemRegistry::fromArray($assoc['CI_AENT']);
45
        $CIMetadata = $assoc['CI_METADATA'];
46
        return new self($CIAent, $CIMetadata);
47
    }
48
49
    /**
50
     * @return AentItemRegistry
51
     */
52
    public function getCIAent(): AentItemRegistry
53
    {
54
        return $this->CIAent;
55
    }
56
57
    /**
58
     * @return array<string,string>
59
     */
60
    public function getCIMetadata(): array
61
    {
62
        return $this->CIMetadata;
63
    }
64
}
65