Passed
Push — master ( 45be64...e3c02a )
by Peter
02:31
created

PageLayout::getClasses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Domain\Entities;
6
7
use AbterPhp\Framework\Domain\Entities\IStringerEntity;
8
use AbterPhp\Website\Domain\Entities\PageLayout\Assets;
9
10
class PageLayout implements IStringerEntity
11
{
12
    /** @var string */
13
    protected $id;
14
15
    /** @var string */
16
    protected $name;
17
18
    /** @var string */
19
    protected $identifier;
20
21
    /** @var string */
22
    protected $classes;
23
24
    /** @var string */
25
    protected $body;
26
27
    /** @var Assets|null */
28
    protected $assets;
29
30
    /**
31
     * PageLayout constructor.
32
     *
33
     * @param string      $id
34
     * @param string      $name
35
     * @param string      $identifier
36
     * @param string      $classes
37
     * @param string      $body
38
     * @param Assets|null $assets
39
     */
40
    public function __construct(
41
        string $id,
42
        string $name,
43
        string $identifier,
44
        string $classes,
45
        string $body,
46
        ?Assets $assets
47
    ) {
48
        $this->id         = $id;
49
        $this->name       = $name;
50
        $this->identifier = $identifier;
51
        $this->classes    = $classes;
52
        $this->body       = $body;
53
        $this->assets     = $assets;
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getId()
60
    {
61
        return $this->id;
62
    }
63
64
    /**
65
     * @param string $id
66
     */
67
    public function setId($id)
68
    {
69
        $this->id = $id;
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function getName(): string
76
    {
77
        return $this->name;
78
    }
79
80
    /**
81
     * @param string $name
82
     *
83
     * @return $this
84
     */
85
    public function setName(string $name): PageLayout
86
    {
87
        $this->name = $name;
88
89
        return $this;
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    public function getIdentifier(): string
96
    {
97
        return $this->identifier;
98
    }
99
100
    /**
101
     * @param string $identifier
102
     *
103
     * @return $this
104
     */
105
    public function setIdentifier(string $identifier): PageLayout
106
    {
107
        $this->identifier = $identifier;
108
109
        return $this;
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    public function getClasses(): string
116
    {
117
        return $this->classes;
118
    }
119
120
    /**
121
     * @param string $classes
122
     *
123
     * @return $this
124
     */
125
    public function setClasses(string $classes): PageLayout
126
    {
127
        $this->classes = $classes;
128
129
        return $this;
130
    }
131
132
    /**
133
     * @return string
134
     */
135
    public function getBody(): string
136
    {
137
        return $this->body;
138
    }
139
140
    /**
141
     * @param string $body
142
     *
143
     * @return $this
144
     */
145
    public function setBody(string $body): PageLayout
146
    {
147
        $this->body = $body;
148
149
        return $this;
150
    }
151
152
    /**
153
     * @return Assets|null
154
     */
155
    public function getAssets(): ?Assets
156
    {
157
        return $this->assets;
158
    }
159
160
    /**
161
     * @param Assets|null $assets
162
     *
163
     * @return $this
164
     */
165
    public function setAssets(?Assets $assets): PageLayout
166
    {
167
        $this->assets = $assets;
168
169
        return $this;
170
    }
171
172
    /**
173
     * @return string
174
     */
175
    public function __toString(): string
176
    {
177
        return $this->getIdentifier();
178
    }
179
180
    /**
181
     * @return array|null
182
     */
183
    public function toData(): ?array
184
    {
185
        $assetsData = null;
186
        if ($this->getAssets()) {
187
            $assets = $this->getAssets();
188
189
            $assetsData = [
190
                'key'       => $assets->getKey(),
191
                'header'    => $assets->getHeader(),
192
                'footer'    => $assets->getFooter(),
193
                'css_files' => $assets->getCssFiles(),
194
                'js_files'  => $assets->getJsFiles(),
195
            ];
196
        }
197
198
        return [
199
            'id'         => $this->getId(),
200
            'identifier' => $this->getIdentifier(),
201
            'classes'    => $this->getClasses(),
202
            'body'       => $this->getBody(),
203
            'assets'     => $assetsData,
204
        ];
205
    }
206
207
    /**
208
     * @return string
209
     */
210
    public function toJSON(): string
211
    {
212
        return json_encode($this->toData());
213
    }
214
}
215