AdminResource::toData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Domain\Entities;
6
7
use AbterPhp\Framework\Domain\Entities\IStringerEntity;
8
9
class AdminResource implements IStringerEntity
10
{
11
    protected string $id;
12
13
    protected string $identifier;
14
15
    /**
16
     * Block constructor.
17
     *
18
     * @param string $id
19
     * @param string $identifier
20
     */
21
    public function __construct(string $id, string $identifier)
22
    {
23
        $this->id         = $id;
24
        $this->identifier = $identifier;
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    public function getId()
31
    {
32
        return $this->id;
33
    }
34
35
    /**
36
     * @param string $id
37
     */
38
    public function setId($id)
39
    {
40
        $this->id = $id;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getIdentifier(): string
47
    {
48
        return $this->identifier;
49
    }
50
51
    /**
52
     * @param string $identifier
53
     *
54
     * @return $this
55
     */
56
    public function setIdentifier(string $identifier): AdminResource
57
    {
58
        $this->identifier = $identifier;
59
60
        return $this;
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function __toString(): string
67
    {
68
        return $this->getIdentifier();
69
    }
70
71
    /**
72
     * @return array|null
73
     */
74
    public function toData(): ?array
75
    {
76
        return [
77
            "id"         => $this->getId(),
78
            "identifier" => $this->getIdentifier(),
79
        ];
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function toJSON(): string
86
    {
87
        return json_encode($this->toData());
88
    }
89
}
90