Completed
Push — master ( f0adbf...7c6605 )
by Joschi
03:16 queued 30s
created

SystemPropertiesTrait::setElevation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
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\Id;
40
use Apparat\Object\Domain\Model\Object\Revision;
41
use Apparat\Object\Domain\Model\Object\Type;
42
use Apparat\Object\Domain\Model\Properties\SystemProperties;
43
44
/**
45
 * System properties trait
46
 *
47
 * @package Apparat\Object
48
 * @subpackage Apparat\Object\Domain
49
 * @property array $collectionStates
50
 */
51
trait SystemPropertiesTrait
52
{
53
    /**
54
     * System properties
55
     *
56
     * @var SystemProperties
57
     */
58
    protected $systemProperties;
59
60
    /**
61
     * Return the object revision
62
     *
63
     * @return Revision Object revision
64
     */
65 24
    public function getRevision()
66
    {
67 24
        return $this->systemProperties->getRevision();
68
    }
69
70
    /**
71
     * Return the object ID
72
     *
73
     * @return Id Object ID
74
     */
75 5
    public function getId()
76
    {
77 5
        return $this->systemProperties->getId();
78
    }
79
80
    /**
81
     * Return the object type
82
     *
83
     * @return Type Object type
84
     */
85 1
    public function getType()
86
    {
87 1
        return $this->systemProperties->getType();
88
    }
89
90
    /**
91
     * Return the creation date & time
92
     *
93
     * @return \DateTimeImmutable Creation date & time
94
     */
95 1
    public function getCreated()
96
    {
97 1
        return $this->systemProperties->getCreated();
98
    }
99
100
    /**
101
     * Return the modification date & time
102
     *
103
     * @return \DateTimeImmutable Modification date & time
104
     */
105
    public function getModified()
106
    {
107
        return $this->systemProperties->getModified();
108
    }
109
110
    /**
111
     * Return the publication date & time
112
     *
113
     * @return \DateTimeImmutable|null Publication date & time
114
     */
115 1
    public function getPublished()
116
    {
117 1
        return $this->systemProperties->getPublished();
118
    }
119
120
    /**
121
     * Return the deletion date & time
122
     *
123
     * @return \DateTimeImmutable Deletion date & time
124
     */
125 1
    public function getDeleted()
126
    {
127 1
        return $this->systemProperties->getDeleted();
128
    }
129
130
    /**
131
     * Return the language
132
     *
133
     * @return string Language
134
     */
135 1
    public function getLanguage()
136
    {
137 1
        return $this->systemProperties->getLanguage();
138
    }
139
140
    /**
141
     * Return the latitude
142
     *
143
     * @return float Latitude
144
     */
145 1
    public function getLatitude()
146
    {
147 1
        return $this->systemProperties->getLatitude();
148
    }
149
150
    /**
151
     * Set the latitude
152
     *
153
     * @param float $latitude Latitude
154
     * @return SystemProperties Self reference
155
     */
156 1
    public function setLatitude($latitude)
157
    {
158 1
        $this->setSystemProperties($this->systemProperties->setLatitude($latitude));
159 1
        return $this;
160
    }
161
162
    /**
163
     * Set the system properties collection
164
     *
165
     * @param SystemProperties $systemProperties System property collection
166
     * @param bool $overwrite Overwrite the existing collection (if present)
167
     */
168 7
    protected function setSystemProperties(SystemProperties $systemProperties, $overwrite = false)
169
    {
170 7
        $this->systemProperties = $systemProperties;
171 7
        $systemPropsState = spl_object_hash($this->systemProperties);
172
173
        // If the system property collection state has changed
174
        if (!$overwrite
175 7
            && !empty($this->collectionStates[SystemProperties::COLLECTION])
176 7
            && ($systemPropsState !== $this->collectionStates[SystemProperties::COLLECTION])
177 7
        ) {
178
            // Flag this object as mutated
179 1
            $this->setModifiedState();
180 1
        }
181
182 7
        $this->collectionStates[SystemProperties::COLLECTION] = $systemPropsState;
183 7
    }
184
185
    /**
186
     * Return the longitude
187
     *
188
     * @return float Longitude
189
     */
190 1
    public function getLongitude()
191
    {
192 1
        return $this->systemProperties->getLongitude();
193
    }
194
195
    /**
196
     * Set the longitude
197
     *
198
     * @param float $longitude Longitude
199
     * @return SystemProperties Self reference
200
     */
201 1
    public function setLongitude($longitude)
202
    {
203 1
        $this->setSystemProperties($this->systemProperties->setLongitude($longitude));
204 1
        return $this;
205
    }
206
207
    /**
208
     * Return the elevation
209
     *
210
     * @return float Elevation
211
     */
212 1
    public function getElevation()
213
    {
214 1
        return $this->systemProperties->getElevation();
215
    }
216
217
    /**
218
     * Set the elevation
219
     *
220
     * @param float $elevation
221
     * @return SystemProperties Self reference
222
     */
223 1
    public function setElevation($elevation)
224
    {
225 1
        $this->setSystemProperties($this->systemProperties->setElevation($elevation));
226 1
        return $this;
227
    }
228
229
    /**
230
     * Set the object state to modified
231
     */
232
    abstract protected function setModifiedState();
233
}
234