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