Completed
Push — master ( 50e176...8c9387 )
by Joschi
03:11
created

MetaProperties::getLicense()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * apparat-object
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Object
8
 * @subpackage  Apparat\Object\Application
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Object\Domain\Model\Properties;
38
39
use Apparat\Object\Domain\Model\Object\ObjectInterface;
40
41
/**
42
 * Meta object properties collection
43
 *
44
 * @package Apparat\Object
45
 * @subpackage Apparat\Object\Application
46
 */
47
class MetaProperties extends AbstractProperties
48
{
49
    /**
50
     * Collection name
51
     *
52
     * @var string
53
     */
54
    const COLLECTION = 'meta';
55
    /**
56
     * Title property
57
     *
58
     * @var string
59
     */
60
    const PROPERTY_TITLE = 'title';
61
    /**
62
     * Slug property
63
     *
64
     * @var string
65
     */
66
    const PROPERTY_SLUG = 'slug';
67
    /**
68
     * Description property
69
     *
70
     * @var string
71
     */
72
    const PROPERTY_DESCRIPTION = 'description';
73
    /**
74
     * Abstract property
75
     *
76
     * @var string
77
     */
78
    const PROPERTY_ABSTRACT = 'abstract';
79
    /**
80
     * License property
81
     *
82
     * @var string
83
     */
84
    const PROPERTY_LICENSE = 'license';
85
    /**
86
     * Privacy property
87
     *
88
     * @var string
89
     */
90
    const PROPERTY_PRIVACY = 'privacy';
91
    /**
92
     * Keywords property
93
     *
94
     * @var string
95
     */
96
    const PROPERTY_KEYWORDS = 'keywords';
97
    /**
98
     * Categories property
99
     *
100
     * @var string
101
     */
102
    const PROPERTY_CATEGORIES = 'categories';
103
    /**
104
     * Private
105
     *
106
     * @var string
107
     */
108
    const PRIVACY_PRIVATE = 'private';
109
    /**
110
     * Public
111
     *
112
     * @var string
113
     */
114
    const PRIVACY_PUBLIC = 'public';
115
    /**
116
     * Object title
117
     *
118
     * @var string
119
     */
120
    protected $title = '';
121
    /**
122
     * Object slug
123
     *
124
     * @var string
125
     */
126
    protected $slug = '';
127
    /**
128
     * Object description
129
     *
130
     * @var string
131
     */
132
    protected $description = '';
133
    /**
134
     * Object abstract
135
     *
136
     * @var string
137
     */
138
    protected $abstract = '';
139
    /**
140
     * Object license
141
     *
142
     * @var string
143
     */
144
    protected $license = '';
145
    /**
146
     * Object privacy
147
     *
148
     * @var string
149
     */
150
    protected $privacy = self::PRIVACY_PRIVATE;
151
    /**
152
     * Object keywords
153
     *
154
     * @var array
155
     */
156
    protected $keywords = [];
157
    /**
158
     * Object categories
159
     *
160
     * @var array
161
     */
162
    protected $categories = [];
163
    /**
164
     * Privacy levels
165
     *
166
     * @var array
167
     */
168
    protected static $privacyLevels = [
169
        self::PRIVACY_PRIVATE,
170
        self::PRIVACY_PUBLIC,
171
    ];
172
173
    /*******************************************************************************
174
     * PUBLIC METHODS
175
     *******************************************************************************/
176
177
    /**
178
     * Meta properties constructor
179
     *
180
     * @param array $data Property data
181
     * @param ObjectInterface $object Owner object
182
     */
183 18
    public function __construct(array $data, ObjectInterface $object)
184
    {
185 18
        parent::__construct($data, $object);
186
187
        // Initialize the title
188 18
        if (array_key_exists(self::PROPERTY_TITLE, $data)) {
189 14
            $this->title = $data[self::PROPERTY_TITLE];
190 14
        }
191
192
        // Initialize the slug
193 18
        if (array_key_exists(self::PROPERTY_SLUG, $data)) {
194 14
            $this->slug = $data[self::PROPERTY_SLUG];
195 14
        }
196
197
        // Initialize the description
198 18
        if (array_key_exists(self::PROPERTY_DESCRIPTION, $data)) {
199 14
            $this->description = $data[self::PROPERTY_DESCRIPTION];
200 14
        }
201
202
        // Initialize the abstract
203 18
        if (array_key_exists(self::PROPERTY_ABSTRACT, $data)) {
204 14
            $this->abstract = $data[self::PROPERTY_ABSTRACT];
205 14
        }
206
207
        // Initialize the keywords
208 18
        if (array_key_exists(self::PROPERTY_KEYWORDS, $data)) {
209 17
            $this->keywords = $this->normalizeSortedPropertyValues((array)$data[self::PROPERTY_KEYWORDS]);
210 17
        }
211
212
        // Initialize the categories
213 18
        if (array_key_exists(self::PROPERTY_CATEGORIES, $data)) {
214 17
            $this->categories = $this->normalizeSortedPropertyValues((array)$data[self::PROPERTY_CATEGORIES]);
215 17
        }
216 18
    }
217
218
    /**
219
     * Return the object title
220
     *
221
     * @return string Object title
222
     */
223 1
    public function getTitle()
224
    {
225 1
        return $this->title;
226
    }
227
228
    /**
229
     * Set the object title
230
     *
231
     * @param string $title Object title
232
     * @return MetaProperties Self reference
233
     */
234 1
    public function setTitle($title)
235
    {
236 1
        return $this->mutateStringProperty(self::PROPERTY_TITLE, $title);
237
    }
238
239
    /**
240
     * Return the object slug
241
     *
242
     * @return string Object slug
243
     */
244 1
    public function getSlug()
245
    {
246 1
        return $this->slug;
247
    }
248
249
    /**
250
     * Set the object slug
251
     *
252
     * @param string $slug Object slug
253
     * @return MetaProperties Self reference
254
     */
255 1
    public function setSlug($slug)
256
    {
257 1
        return $this->mutateStringProperty(self::PROPERTY_SLUG, $slug);
258
    }
259
260
    /**
261
     * Return the object description
262
     *
263
     * @return string Object description
264
     */
265 2
    public function getDescription()
266
    {
267 2
        return $this->description;
268
    }
269
270
    /**
271
     * Set the object description
272
     *
273
     * @param string $description Object description
274
     * @return MetaProperties Self reference
275
     */
276 1
    public function setDescription($description)
277
    {
278 1
        return $this->mutateStringProperty(self::PROPERTY_DESCRIPTION, $description);
279
    }
280
281
    /**
282
     * Return the object abstract
283
     *
284
     * @return string Object abstract
285
     */
286 2
    public function getAbstract()
287
    {
288 2
        return $this->abstract;
289
    }
290
291
    /**
292
     * Set the object abstract
293
     *
294
     * @param string $abstract Object abstract
295
     * @return MetaProperties Self reference
296
     */
297 1
    public function setAbstract($abstract)
298
    {
299 1
        return $this->mutateStringProperty(self::PROPERTY_ABSTRACT, $abstract);
300
    }
301
302
    /**
303
     * Return the object license
304
     *
305
     * @return string Object license
306
     */
307 1
    public function getLicense()
308
    {
309 1
        return $this->license;
310
    }
311
312
    /**
313
     * Set the object license
314
     *
315
     * @param string $license Object license
316
     * @return MetaProperties Self reference
317
     */
318 1
    public function setLicense($license)
319
    {
320 1
        return $this->mutateStringProperty(self::PROPERTY_LICENSE, $license);
321
    }
322
323
    /**
324
     * Return the object privacy
325
     *
326
     * @return string Object privacy
327
     */
328 1
    public function getPrivacy()
329
    {
330 1
        return $this->privacy;
331
    }
332
333
    /**
334
     * Set the object privacy
335
     *
336
     * @param string $privacy Object privacy
337
     * @return MetaProperties Self reference
338
     */
339 1
    public function setPrivacy($privacy)
340
    {
341
        // If the privacy level is unknown
342 1
        if (!in_array($privacy, self::$privacyLevels)) {
343 1
            throw new OutOfBoundsException(
344 1
                sprintf('Invalid privacy level "%s"', $privacy),
345
                OutOfBoundsException::INVALID_PRIVACY_LEVEL
346 1
            );
347
        }
348
349 1
        return $this->mutateStringProperty(self::PROPERTY_PRIVACY, $privacy);
350
    }
351
352
    /**
353
     * Return the object keywords
354
     *
355
     * @return array Object keywords
356
     */
357 2
    public function getKeywords()
358
    {
359 2
        return $this->keywords;
360
    }
361
362
    /**
363
     * Set the object keywords
364
     *
365
     * @param array $keywords Object keywords
366
     * @return MetaProperties Self reference
367
     */
368 1
    public function setKeywords(array $keywords)
369
    {
370 1
        return $this->mutateListProperty(self::PROPERTY_KEYWORDS, $this->normalizeSortedPropertyValues($keywords));
371
    }
372
373
    /**
374
     * Return the object categories
375
     *
376
     * @return array Object categories
377
     */
378 2
    public function getCategories()
379
    {
380 2
        return $this->categories;
381
    }
382
383
    /**
384
     * Set the object categories
385
     *
386
     * @param array $categories Object categories
387
     * @return MetaProperties Self reference
388
     */
389 1
    public function setCategories(array $categories)
390
    {
391 1
        return $this->mutateListProperty(self::PROPERTY_CATEGORIES, $this->normalizeSortedPropertyValues($categories));
392
    }
393
394
    /**
395
     * Return the property values as array
396
     *
397
     * @return array Property values
398
     */
399 5
    public function toArray()
400
    {
401 5
        return array_filter([
402 5
            self::PROPERTY_DESCRIPTION => $this->description,
403 5
            self::PROPERTY_ABSTRACT => $this->abstract,
404 5
            self::PROPERTY_KEYWORDS => $this->keywords,
405 5
            self::PROPERTY_CATEGORIES => $this->categories,
406 5
        ]);
407
    }
408
}
409