Completed
Push — master ( 88eef6...81252c )
by Joschi
02:44
created

SystemProperties::__construct()   C

Complexity

Conditions 7
Paths 64

Size

Total Lines 34
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 7.3387

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 34
ccs 17
cts 21
cp 0.8095
rs 6.7272
cc 7
eloc 14
nc 64
nop 2
crap 7.3387
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
    /*******************************************************************************
102
     * PUBLIC METHODS
103
     *******************************************************************************/
104
105
    /**
106
     * System properties constructor
107
     *
108
     * @param array $data Property data
109
     * @param ObjectInterface $object Owner object
110
     */
111 2
    public function __construct(array $data, ObjectInterface $object)
112
    {
113 2
        parent::__construct($data, $object);
114
115
        // Initialize the object ID
116 2
        if (array_key_exists('id', $data)) {
117 1
            $this->_setId(Id::unserialize($data['id']));
118 1
        }
119
120
        // Initialize the object type
121 2
        if (array_key_exists('type', $data)) {
122 2
            $this->_setType(Type::unserialize($data['type']));
123 1
        }
124
125
        // Initialize the object revision
126 1
        if (array_key_exists('revision', $data)) {
127 1
            $this->_setRevision(Revision::unserialize($data['revision']));
128 1
        }
129
130
        // Initialize the object creation date
131 1
        if (array_key_exists('created', $data)) {
132
            $this->_setCreated(new \DateTimeImmutable('@'.$data['created']));
133
        }
134
135
        // Initialize the object publication date
136 1
        if (array_key_exists('published', $data)) {
137 1
            $this->_setPublished(new \DateTimeImmutable('@'.$data['published']));
138 1
        }
139
140
        // Initialize the object hash
141 1
        if (array_key_exists('hash', $data)) {
142
            $this->_setHash($data['hash']);
143
        }
144 1
    }
145
146
    /**
147
     * Return the object ID
148
     *
149
     * @return Id Object ID
150
     */
151
    public function getId()
152
    {
153
        return $this->_id;
154
    }
155
156
    /**
157
     * Return the object type
158
     *
159
     * @return Type Object type
160
     */
161
    public function getType()
162
    {
163
        return $this->_type;
164
    }
165
166
    /**
167
     * Return the object revision
168
     *
169
     * @return Revision Object revision
170
     */
171
    public function getRevision()
172
    {
173
        return $this->_revision;
174
    }
175
176
    /**
177
     * Return the creation date & time
178
     *
179
     * @return \DateTimeImmutable Creation date & time
180
     */
181
    public function getCreated()
182
    {
183
        return $this->_created;
184
    }
185
186
    /**
187
     * Return the publication date & time
188
     *
189
     * @return \DateTimeImmutable Publication date & time
190
     */
191
    public function getPublished()
192
    {
193
        return $this->_published;
194
    }
195
196
    /**
197
     * Return the object hash
198
     *
199
     * @return string Object hash
200
     */
201
    public function getHash()
202
    {
203
        return $this->_hash;
204
    }
205
206
    /*******************************************************************************
207
     * PRIVATE METHODS
208
     *******************************************************************************/
209
210
    /**
211
     * Set the object ID
212
     *
213
     * @param Id $id
214
     */
215 1
    protected function _setId(Id $id)
216
    {
217 1
        $this->_id = $id;
218 1
    }
219
220
    /**
221
     * Set the object type
222
     *
223
     * @param Type $type Object type
224
     */
225 1
    protected function _setType(Type $type)
226
    {
227 1
        $this->_type = $type;
228 1
    }
229
230
    /**
231
     * Set the object revision
232
     *
233
     * @param Revision $revision Object revision
234
     */
235 1
    protected function _setRevision(Revision $revision)
236
    {
237 1
        $this->_revision = $revision;
238 1
    }
239
240
    /**
241
     * Set the publication date & time
242
     *
243
     * @param \DateTimeImmutable $published Publication date & time
244
     */
245 1
    protected function _setPublished(\DateTimeImmutable $published)
246
    {
247 1
        $this->_published = $published;
248 1
    }
249
250
    /**
251
     * Set the creation date & time
252
     *
253
     * @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...
254
     */
255
    protected function _setCreated(\DateTimeImmutable $created)
256
    {
257
        $this->_created = $created;
258
    }
259
260
    /**
261
     * Set the object hash
262
     *
263
     * @param string $hash Object hash
264
     */
265
    protected function _setHash($hash)
266
    {
267
        $this->_hash = $hash;
268
    }
269
}
270