MetaPropertiesTrait   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 213
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 213
rs 10
c 0
b 0
f 0
ccs 49
cts 49
cp 1
wmc 20
lcom 1
cbo 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
A getTitle() 0 4 1
A setTitle() 0 5 1
A setMetaProperties() 0 16 4
A getSlug() 0 4 1
A setSlug() 0 5 1
A getDescription() 0 4 1
A setDescription() 0 5 1
A getAbstract() 0 4 1
A setAbstract() 0 5 1
A getLicense() 0 4 1
A setLicense() 0 5 1
A getPrivacy() 0 4 1
A setPrivacy() 0 5 1
A getKeywords() 0 4 1
A setKeywords() 0 5 1
A getCategories() 0 4 1
A setCategories() 0 5 1
setMutatedState() 0 1 ?
1
<?php
2
3
/**
4
 * apparat-object
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Object
8
 * @subpackage  Apparat\Object\Domain
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\Object\Traits;
38
39
use Apparat\Object\Domain\Model\Object\ObjectInterface;
40
use Apparat\Object\Domain\Model\Properties\MetaProperties;
41
42
/**
43
 * Meta properties trait
44
 *
45
 * @package Apparat\Object
46
 * @subpackage Apparat\Object\Domain
47
 * @property array $collectionStates
48
 */
49
trait MetaPropertiesTrait
50
{
51
    /**
52
     * Meta properties
53
     *
54
     * @var MetaProperties
55
     */
56
    protected $metaProperties;
57
58
    /**
59
     * Return the object title
60
     *
61
     * @return string Object title
62
     */
63 5
    public function getTitle()
64
    {
65 5
        return $this->metaProperties->getTitle();
66
    }
67
68
    /**
69
     * Set the title
70
     *
71
     * @param string $title Title
72
     * @return ObjectInterface Self reference
73
     */
74 4
    public function setTitle($title)
75
    {
76 4
        $this->setMetaProperties($this->metaProperties->setTitle($title));
77 4
        return $this;
78
    }
79
80
    /**
81
     * Set the meta properties collection
82
     *
83
     * @param MetaProperties $metaProperties Meta property collection
84
     * @param bool $overwrite Overwrite the existing collection (if present)
85
     */
86 45
    protected function setMetaProperties(MetaProperties $metaProperties, $overwrite = false)
87
    {
88 45
        $this->metaProperties = $metaProperties;
89 45
        $metaPropertiesState = spl_object_hash($this->metaProperties);
90
91
        // If the meta property collection state has changed
92 45
        if (!$overwrite
93 45
            && !empty($this->collectionStates[MetaProperties::COLLECTION])
94 45
            && ($metaPropertiesState !== $this->collectionStates[MetaProperties::COLLECTION])
95
        ) {
96
            // Flag this object as mutated
97 4
            $this->setMutatedState();
98
        }
99
100 45
        $this->collectionStates[MetaProperties::COLLECTION] = $metaPropertiesState;
101 45
    }
102
103
    /**
104
     * Return the object slug
105
     *
106
     * @return string Object slug
107
     */
108 1
    public function getSlug()
109
    {
110 1
        return $this->metaProperties->getSlug();
111
    }
112
113
    /**
114
     * Set the slug
115
     *
116
     * @param string $slug Slug
117
     * @return ObjectInterface Self reference
118
     */
119 1
    public function setSlug($slug)
120
    {
121 1
        $this->setMetaProperties($this->metaProperties->setSlug($slug));
122 1
        return $this;
123
    }
124
125
    /**
126
     * Return the object description
127
     *
128
     * @return string Object description
129
     */
130 2
    public function getDescription()
131
    {
132 2
        return $this->metaProperties->getDescription();
133
    }
134
135
    /**
136
     * Set the description
137
     *
138
     * @param string $description Description
139
     * @return ObjectInterface Self reference
140
     */
141 1
    public function setDescription($description)
142
    {
143 1
        $this->setMetaProperties($this->metaProperties->setDescription($description));
144 1
        return $this;
145
    }
146
147
    /**
148
     * Return the object abstract
149
     *
150
     * @return string Object abstract
151
     */
152 4
    public function getAbstract()
153
    {
154 4
        return $this->metaProperties->getAbstract();
155
    }
156
157
    /**
158
     * Set the abstract
159
     *
160
     * @param string $abstract Abstract
161
     * @return ObjectInterface Self reference
162
     */
163 2
    public function setAbstract($abstract)
164
    {
165 2
        $this->setMetaProperties($this->metaProperties->setAbstract($abstract));
166 2
        return $this;
167
    }
168
169
    /**
170
     * Return the license
171
     *
172
     * @return string License
173
     */
174 1
    public function getLicense()
175
    {
176 1
        return $this->metaProperties->getLicense();
177
    }
178
179
    /**
180
     * Set the license
181
     *
182
     * @param string $license License
183
     * @return MetaProperties Self reference
184
     */
185 1
    public function setLicense($license)
186
    {
187 1
        $this->setMetaProperties($this->metaProperties->setLicense($license));
188 1
        return $this;
189
    }
190
191
    /**
192
     * Return the privacy
193
     *
194
     * @return string Privacy
195
     */
196 2
    public function getPrivacy()
197
    {
198 2
        return $this->metaProperties->getPrivacy();
199
    }
200
201
    /**
202
     * Set the privacy
203
     *
204
     * @param string $privacy Privacy
205
     * @return MetaProperties Self reference
206
     */
207 1
    public function setPrivacy($privacy)
208
    {
209 1
        $this->setMetaProperties($this->metaProperties->setPrivacy($privacy));
210 1
        return $this;
211
    }
212
213
    /**
214
     * Return all object keywords
215
     *
216
     * @return array Object keywords
217
     */
218 2
    public function getKeywords()
219
    {
220 2
        return $this->metaProperties->getKeywords();
221
    }
222
223
    /**
224
     * Set the keywords
225
     *
226
     * @param array $keywords Keywords
227
     * @return ObjectInterface Self reference
228
     */
229 1
    public function setKeywords(array $keywords)
230
    {
231 1
        $this->setMetaProperties($this->metaProperties->setKeywords($keywords));
232 1
        return $this;
233
    }
234
235
    /**
236
     * Return all object categories
237
     *
238
     * @return array Object categories
239
     */
240 3
    public function getCategories()
241
    {
242 3
        return $this->metaProperties->getCategories();
243
    }
244
245
    /**
246
     * Set the categories
247
     *
248
     * @param array $categories Categories
249
     * @return ObjectInterface Self reference
250
     */
251 1
    public function setCategories(array $categories)
252
    {
253 1
        $this->setMetaProperties($this->metaProperties->setCategories($categories));
254 1
        return $this;
255
    }
256
257
    /**
258
     * Set the object state to mutated
259
     */
260
    abstract protected function setMutatedState();
261
}
262