Completed
Push — master ( 3e0d05...5aac82 )
by Joschi
03:56
created

SystemProperties::_setCreated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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)
0 ignored issues
show
Coding Style introduced by
Spaces must be used for alignment; tabs are not allowed
Loading history...
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\Id;
40
use Apparat\Object\Domain\Model\Object\ObjectInterface;
41
use Apparat\Object\Domain\Model\Object\Revision;
42
use Apparat\Object\Domain\Model\Object\Type;
43
44
/**
45
 * System object properties collection
46
 *
47
 * @package Apparat\Object
48
 * @subpackage Apparat\Object\Application
49
 */
50
class SystemProperties extends AbstractProperties
51
{
52
    /**
53
     * Object ID
54
     *
55
     * @var Id
56
     */
57
    protected $id = 0;
58
59
    /**
60
     * Object type
61
     *
62
     * @var Type
63
     */
64
    protected $type = null;
65
66
    /**
67
     * Object revision
68
     *
69
     * @var Revision
70
     */
71
    protected $revision = null;
72
73
    /**
74
     * Creation date
75
     *
76
     * @var \DateTimeImmutable
77
     */
78
    protected $created = null;
79
80
    /**
81
     * Publication date
82
     *
83
     * @var \DateTimeImmutable
84
     */
85
    protected $published = null;
86
87
    /**
88
     * Object hash
89
     *
90
     * @var string
91
     */
92
    protected $hash = null;
93
94
    /**
95
     * Collection name
96
     *
97
     * @var string
98
     */
99
    const COLLECTION = 'system';
100
    /**
101
     * ID property
102
     *
103
     * @var string
104
     */
105
    const PROPERTY_ID = 'id';
106
    /**
107
     * Type property
108
     *
109
     * @var string
110
     */
111
    const PROPERTY_TYPE = 'type';
112
    /**
113
     * Revision property
114
     *
115
     * @var string
116
     */
117
    const PROPERTY_REVISION = 'revision';
118
    /**
119
     * Created property
120
     *
121
     * @var string
122
     */
123
    const PROPERTY_CREATED = 'created';
124
    /**
125
     * Published property
126
     *
127
     * @var string
128
     */
129
    const PROPERTY_PUBLISHED = 'published';
130
    /**
131
     * Hash property
132
     *
133
     * @var string
134
     */
135
    const PROPERTY_HASH = 'hash';
136
137
    /*******************************************************************************
138
     * PUBLIC METHODS
139
     *******************************************************************************/
140
141
    /**
142
     * System properties constructor
143
     *
144
     * @param array $data Property data
145
     * @param ObjectInterface $object Owner object
146
     */
147 3
    public function __construct(array $data, ObjectInterface $object)
148
    {
149 3
        parent::__construct($data, $object);
150
151
        // Initialize the object ID
152 3
        if (array_key_exists(self::PROPERTY_ID, $data)) {
153 2
            $this->setId(Id::unserialize($data[self::PROPERTY_ID]));
154 2
        }
155
156
        // Initialize the object type
157 3
        if (array_key_exists(self::PROPERTY_TYPE, $data)) {
158 3
            $this->setType(Type::unserialize($data[self::PROPERTY_TYPE]));
159 2
        }
160
161
        // Initialize the object revision
162 2
        if (array_key_exists(self::PROPERTY_REVISION, $data)) {
163 2
            $this->setRevision(Revision::unserialize($data[self::PROPERTY_REVISION]));
164 2
        }
165
166
        // Initialize the object creation date
167 2
        if (array_key_exists(self::PROPERTY_CREATED, $data)) {
168 1
            $this->setCreated(new \DateTimeImmutable('@'.$data[self::PROPERTY_CREATED]));
169 1
        }
170
171
        // Initialize the object publication date
172 2
        if (array_key_exists(self::PROPERTY_PUBLISHED, $data)) {
173 2
            $this->setPublished(new \DateTimeImmutable('@'.$data[self::PROPERTY_PUBLISHED]));
174 2
        }
175
176
        // Initialize the object hash
177 2
        if (array_key_exists(self::PROPERTY_HASH, $data)) {
178
            $this->setHash($data[self::PROPERTY_HASH]);
179
        }
180 2
    }
181
182
    /**
183
     * Return the object ID
184
     *
185
     * @return Id Object ID
186
     */
187 1
    public function getId()
188
    {
189 1
        return $this->id;
190
    }
191
192
    /**
193
     * Return the object type
194
     *
195
     * @return Type Object type
196
     */
197 1
    public function getType()
198
    {
199 1
        return $this->type;
200
    }
201
202
    /**
203
     * Return the object revision
204
     *
205
     * @return Revision Object revision
206
     */
207 1
    public function getRevision()
208
    {
209 1
        return $this->revision;
210
    }
211
212
    /**
213
     * Return the creation date & time
214
     *
215
     * @return \DateTimeImmutable Creation date & time
216
     */
217 1
    public function getCreated()
218
    {
219 1
        return $this->created;
220
    }
221
222
    /**
223
     * Return the publication date & time
224
     *
225
     * @return \DateTimeImmutable Publication date & time
226
     */
227 1
    public function getPublished()
228
    {
229 1
        return $this->published;
230
    }
231
232
    /**
233
     * Return the object hash
234
     *
235
     * @return string Object hash
236
     */
237
    public function getHash()
238
    {
239
        return $this->hash;
240
    }
241
242
    /**
243
     * Return the property values as array
244
     *
245
     * @return array Property values
246
     */
247 1
    public function toArray()
248
    {
249
        return [
250 1
            self::PROPERTY_ID => $this->id->getId(),
251 1
            self::PROPERTY_TYPE => $this->type->getType(),
252 1
            self::PROPERTY_REVISION => $this->revision->getRevision(),
253 1
            self::PROPERTY_CREATED => $this->created->format('c'),
254 1
            self::PROPERTY_PUBLISHED => $this->published->format('c'),
255 1
            self::PROPERTY_HASH => $this->hash,
256 1
        ];
257
    }
258
259
    /*******************************************************************************
260
     * PRIVATE METHODS
261
     *******************************************************************************/
262
263
    /**
264
     * Set the object ID
265
     *
266
     * @param Id $id
267
     */
268 2
    protected function setId(Id $id)
269
    {
270 2
        $this->id = $id;
271 2
    }
272
273
    /**
274
     * Set the object type
275
     *
276
     * @param Type $type Object type
277
     */
278 2
    protected function setType(Type $type)
279
    {
280 2
        $this->type = $type;
281 2
    }
282
283
    /**
284
     * Set the object revision
285
     *
286
     * @param Revision $revision Object revision
287
     */
288 2
    protected function setRevision(Revision $revision)
289
    {
290 2
        $this->revision = $revision;
291 2
    }
292
293
    /**
294
     * Set the publication date & time
295
     *
296
     * @param \DateTimeImmutable $published Publication date & time
297
     */
298 2
    protected function setPublished(\DateTimeImmutable $published)
299
    {
300 2
        $this->published = $published;
301 2
    }
302
303
    /**
304
     * Set the creation date & time
305
     *
306
     * @param \DateTimeImmutable $published Creation date & time
0 ignored issues
show
Bug introduced by
There is no parameter named $published. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
307
     */
308 1
    protected function setCreated(\DateTimeImmutable $created)
309
    {
310 1
        $this->created = $created;
311 1
    }
312
313
    /**
314
     * Set the object hash
315
     *
316
     * @param string $hash Object hash
317
     */
318
    protected function setHash($hash)
319
    {
320
        $this->hash = $hash;
321
    }
322
}
323