Completed
Push — master ( 7d8595...567095 )
by Joschi
03:07
created

MetaProperties::__construct()   C

Complexity

Conditions 7
Paths 64

Size

Total Lines 34
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 7

Importance

Changes 8
Bugs 0 Features 2
Metric Value
cc 7
eloc 14
c 8
b 0
f 2
nc 64
nop 2
dl 0
loc 34
rs 6.7272
ccs 15
cts 15
cp 1
crap 7
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
     * Keywords property
81
     *
82
     * @var string
83
     */
84
    const PROPERTY_KEYWORDS = 'keywords';
85
    /**
86
     * Categories property
87
     *
88
     * @var string
89
     */
90
    const PROPERTY_CATEGORIES = 'categories';
91
    /**
92
     * Object title
93
     *
94
     * @var string
95
     */
96
    protected $title = '';
97
    /**
98
     * Object slug
99
     *
100
     * @var string
101
     */
102
    protected $slug = '';
103
    /**
104
     * Object description
105
     *
106
     * @var string
107
     */
108
    protected $description = '';
109
    /**
110
     * Object abstract
111
     *
112
     * @var string
113
     */
114
    protected $abstract = '';
115
    /**
116
     * Object keywords
117
     *
118
     * @var array
119
     */
120
    protected $keywords = [];
121
    /**
122
     * Object categories
123
     *
124
     * @var array
125
     */
126
    protected $categories = [];
127
128
    /*******************************************************************************
129
     * PUBLIC METHODS
130
     *******************************************************************************/
131
132
    /**
133
     * Meta properties constructor
134
     *
135
     * @param array $data Property data
136
     * @param ObjectInterface $object Owner object
137
     */
138 18
    public function __construct(array $data, ObjectInterface $object)
139
    {
140 18
        parent::__construct($data, $object);
141
142
        // Initialize the title
143 18
        if (array_key_exists(self::PROPERTY_TITLE, $data)) {
144 14
            $this->title = $data[self::PROPERTY_TITLE];
145
        }
146
147
        // Initialize the slug
148 18
        if (array_key_exists(self::PROPERTY_SLUG, $data)) {
149 14
            $this->slug = $data[self::PROPERTY_SLUG];
150
        }
151
152
        // Initialize the description
153 18
        if (array_key_exists(self::PROPERTY_DESCRIPTION, $data)) {
154 14
            $this->description = $data[self::PROPERTY_DESCRIPTION];
155
        }
156
157
        // Initialize the abstract
158 18
        if (array_key_exists(self::PROPERTY_ABSTRACT, $data)) {
159 14
            $this->abstract = $data[self::PROPERTY_ABSTRACT];
160
        }
161
162
        // Initialize the keywords
163 18
        if (array_key_exists(self::PROPERTY_KEYWORDS, $data)) {
164 17
            $this->keywords = $this->normalizeSortedPropertyValues((array)$data[self::PROPERTY_KEYWORDS]);
165
        }
166
167
        // Initialize the categories
168 18
        if (array_key_exists(self::PROPERTY_CATEGORIES, $data)) {
169 17
            $this->categories = $this->normalizeSortedPropertyValues((array)$data[self::PROPERTY_CATEGORIES]);
170
        }
171 18
    }
172
173
    /**
174
     * Return the object title
175
     *
176
     * @return string Object title
177
     */
178 1
    public function getTitle()
179
    {
180 1
        return $this->title;
181
    }
182
183
    /**
184
     * Set the object title
185
     *
186
     * @param string $title Object title
187
     * @return MetaProperties Self reference
188
     */
189 1
    public function setTitle($title)
190
    {
191 1
        return $this->mutateStringProperty(self::PROPERTY_TITLE, $title);
192
    }
193
194
    /**
195
     * Return the object slug
196
     *
197
     * @return string Object slug
198
     */
199 1
    public function getSlug()
200
    {
201 1
        return $this->slug;
202
    }
203
204
    /**
205
     * Set the object slug
206
     *
207
     * @param string $slug Object slug
208
     * @return MetaProperties Self reference
209
     */
210 1
    public function setSlug($slug)
211
    {
212 1
        return $this->mutateStringProperty(self::PROPERTY_SLUG, $slug);
213
    }
214
215
    /**
216
     * Return the object description
217
     *
218
     * @return string Object description
219
     */
220 2
    public function getDescription()
221
    {
222 2
        return $this->description;
223
    }
224
225
    /**
226
     * Set the object description
227
     *
228
     * @param string $description Object description
229
     * @return MetaProperties Self reference
230
     */
231 1
    public function setDescription($description)
232
    {
233 1
        return $this->mutateStringProperty(self::PROPERTY_DESCRIPTION, $description);
234
    }
235
236
    /**
237
     * Return the object abstract
238
     *
239
     * @return string Object abstract
240
     */
241 2
    public function getAbstract()
242
    {
243 2
        return $this->abstract;
244
    }
245
246
    /**
247
     * Set the object abstract
248
     *
249
     * @param string $abstract Object abstract
250
     * @return MetaProperties Self reference
251
     */
252 1
    public function setAbstract($abstract)
253
    {
254 1
        return $this->mutateStringProperty(self::PROPERTY_ABSTRACT, $abstract);
255
    }
256
257
    /**
258
     * Return the object keywords
259
     *
260
     * @return array Object keywords
261
     */
262 2
    public function getKeywords()
263
    {
264 2
        return $this->keywords;
265
    }
266
267
    /**
268
     * Set the object keywords
269
     *
270
     * @param array $keywords Object keywords
271
     * @return MetaProperties Self reference
272
     */
273 1
    public function setKeywords(array $keywords)
274
    {
275 1
        return $this->mutateListProperty(self::PROPERTY_KEYWORDS, $this->normalizeSortedPropertyValues($keywords));
276
    }
277
278
    /**
279
     * Return the object categories
280
     *
281
     * @return array Object categories
282
     */
283 2
    public function getCategories()
284
    {
285 2
        return $this->categories;
286
    }
287
288
    /**
289
     * Set the object categories
290
     *
291
     * @param array $categories Object categories
292
     * @return MetaProperties Self reference
293
     */
294 1
    public function setCategories(array $categories)
295
    {
296 1
        return $this->mutateListProperty(self::PROPERTY_CATEGORIES, $this->normalizeSortedPropertyValues($categories));
297
    }
298
299
    /**
300
     * Return the property values as array
301
     *
302
     * @return array Property values
303
     */
304 5
    public function toArray()
305
    {
306 5
        return array_filter([
307 5
            self::PROPERTY_DESCRIPTION => $this->description,
308 5
            self::PROPERTY_ABSTRACT => $this->abstract,
309 5
            self::PROPERTY_KEYWORDS => $this->keywords,
310 5
            self::PROPERTY_CATEGORIES => $this->categories,
311
        ]);
312
    }
313
}
314