Completed
Push — master ( 935bb4...18349c )
by Christian
02:42
created

Statement::getVoidStatement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 1
eloc 6
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Model;
13
14
/**
15
 * An Experience API {@link https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#statement Statement}.
16
 *
17
 * @author Christian Flothmann <[email protected]>
18
 */
19
final class Statement
20
{
21
    /**
22
     * @var string The unique identifier
23
     */
24
    private $id;
25
26
    /**
27
     * @var Verb $verb The {@link Verb}
28
     */
29
    private $verb;
30
31
    /**
32
     * @var Actor The {@link Actor}
33
     */
34
    private $actor;
35
36
    /**
37
     * @var Object The {@link Object}
38
     */
39
    private $object;
40
41
    /**
42
     * @var Result The {@link Activity} {@link Result}
43
     */
44
    private $result;
45
46
    /**
47
     * @var Actor The Authority that asserted the Statement true
48
     */
49
    private $authority;
50
51
    /**
52
     * @var \DateTime The timestamp of when the events described in this statement occurred
53
     */
54
    private $created;
55
56
    /**
57
     * @var \DateTime The timestamp of when this statement was recorded by the LRS
58
     */
59
    private $stored;
60
61 4
    public function __construct($id, Actor $actor, Verb $verb, Object $object, Result $result = null, Actor $authority = null, \DateTime $created = null, \DateTime $stored = null)
62
    {
63 4
        $this->id = $id;
64 4
        $this->actor = $actor;
65 4
        $this->verb = $verb;
66 4
        $this->object = $object;
67 4
        $this->result = $result;
68 4
        $this->authority = $authority;
69 4
        $this->created = $created;
70 4
        $this->stored = $stored;
71 4
    }
72
73
    /**
74
     * Returns the Statement's unique identifier.
75
     *
76
     * @return string The identifier
77
     */
78 2
    public function getId()
79
    {
80 2
        return $this->id;
81
    }
82
83
    /**
84
     * Returns the Statement's {@link Verb}.
85
     *
86
     * @return Verb The Verb
87
     */
88 3
    public function getVerb()
89
    {
90 3
        return $this->verb;
91
    }
92
93
    /**
94
     * Returns the Statement's {@link Actor}.
95
     *
96
     * @return Actor The Actor
97
     */
98 3
    public function getActor()
99
    {
100 3
        return $this->actor;
101
    }
102
103
    /**
104
     * Returns the Statement's {@link Object}.
105
     *
106
     * @return \Xabbuh\XApi\Model\Object The Object
107
     */
108 3
    public function getObject()
109
    {
110 3
        return $this->object;
111
    }
112
113
    /**
114
     * Returns the {@link Activity} {@link Result}.
115
     *
116
     * @return Result The Result
117
     */
118
    public function getResult()
119
    {
120
        return $this->result;
121
    }
122
123
    /**
124
     * Returns the Authority that asserted the Statement true.
125
     *
126
     * @return Actor The Authority
127
     */
128 2
    public function getAuthority()
129
    {
130 2
        return $this->authority;
131
    }
132
133
    /**
134
     * Returns the timestamp of when the events described in this statement
135
     * occurred.
136
     *
137
     * @return \DateTime The timestamp
138
     */
139
    public function getCreated()
140
    {
141
        return $this->created;
142
    }
143
144
    /**
145
     * Returns the timestamp of when this statement was recorded by the LRS.
146
     *
147
     * @return \DateTime The timestamp
148
     */
149
    public function getStored()
150
    {
151
        return $this->stored;
152
    }
153
154
    /**
155
     * Tests whether or not this Statement is a void Statement (i.e. it voids
156
     * another Statement).
157
     *
158
     * @return bool True if the Statement voids another Statement, false otherwise
159
     */
160
    public function isVoidStatement()
161
    {
162
        return $this->verb->isVoidVerb();
163
    }
164
165
    /**
166
     * Returns a {@link StatementReference} for the Statement.
167
     *
168
     * @return StatementReference The reference
169
     */
170 2
    public function getStatementReference()
171
    {
172 2
        $reference = new StatementReference($this->id);
173
174 2
        return $reference;
175
    }
176
177
    /**
178
     * Returns a Statement that voids the current Statement.
179
     *
180
     * @param Actor $actor The Actor voiding this Statement
181
     *
182
     * @return Statement The voiding Statement
183
     */
184 1
    public function getVoidStatement(Actor $actor)
185
    {
186 1
        return new Statement(
187 1
            null,
188
            $actor,
189 1
            Verb::createVoidVerb(),
190 1
            $this->getStatementReference()
191
        );
192
    }
193
194
    /**
195
     * Creates a new Statement based on the current one containing an Authority
196
     * that asserts the Statement true.
197
     *
198
     * @param Actor $authority The Authority asserting the Statement true
199
     *
200
     * @return Statement The new Statement
201
     */
202 2
    public function withAuthority(Actor $authority)
203
    {
204 2
        return new Statement($this->id, $this->actor, $this->verb, $this->object, $this->result, $authority);
205
    }
206
207
    /**
208
     * Checks if another statement is equal.
209
     *
210
     * Two statements are equal if and only if all of their properties are equal.
211
     *
212
     * @param Statement $statement The statement to compare with
213
     *
214
     * @return bool True if the statements are equal, false otherwise
215
     */
216 2
    public function equals(Statement $statement)
217
    {
218 2
        if ($this->id !== $statement->id) {
219
            return false;
220
        }
221
222 2
        if (!$this->actor->equals($statement->actor)) {
223
            return false;
224
        }
225
226 2
        if (!$this->verb->equals($statement->verb)) {
227
            return false;
228
        }
229
230 2
        if (!$this->object->equals($statement->object)) {
231
            return false;
232
        }
233
234 2
        if (null === $this->result && null !== $statement->result) {
235
            return false;
236
        }
237
238 2
        if (null !== $this->result && null === $statement->result) {
239
            return false;
240
        }
241
242 2
        if (null !== $this->result && !$this->result->equals($statement->result)) {
243
            return false;
244
        }
245
246 2
        if (null === $this->authority && null !== $statement->authority) {
247 1
            return false;
248
        }
249
250 1
        if (null !== $this->authority && null === $statement->authority) {
251
            return false;
252
        }
253
254 1
        if (null !== $this->authority && !$this->authority->equals($statement->authority)) {
255 1
            return false;
256
        }
257
258
        return true;
259
    }
260
}
261