Completed
Pull Request — master (#24)
by Christian
02:26
created

SubStatement::isVoidStatement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 1
f 0
ccs 0
cts 3
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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
 * A {@link Statement} included as part of a parent Statement.
16
 *
17
 * @author Christian Flothmann <[email protected]>
18
 */
19
final class SubStatement extends Object
20
{
21
    /**
22
     * @var Verb $verb The {@link Verb}
23
     */
24
    private $verb;
25
26
    /**
27
     * @var Actor The {@link Actor}
28
     */
29
    private $actor;
30
31
    /**
32
     * @var Object The {@link Object}
33
     */
34
    private $object;
35
36
    /**
37
     * @var Result The {@link Activity} {@link Result}
38
     */
39
    private $result;
40
41
    /**
42
     * @var Context The {@link Statement} {@link Context}
43
     */
44
    private $context;
45
46
    public function __construct(Actor $actor, Verb $verb, Object $object, Result $result = null, Context $context = null)
47
    {
48
        if ($object instanceof SubStatement) {
49
            throw new \InvalidArgumentException('Nesting sub statements is forbidden by the xAPI spec.');
50
        }
51
52
        $this->actor = $actor;
53
        $this->verb = $verb;
54
        $this->object = $object;
55
        $this->result = $result;
56
        $this->context = $context;
57
    }
58
59
    public function withActor(Actor $actor)
60
    {
61
        $subStatement = clone $this;
62
        $subStatement->actor = $actor;
63
64
        return $subStatement;
65
    }
66
67
    public function withVerb(Verb $verb)
68
    {
69
        $subStatement = clone $this;
70
        $subStatement->verb = $verb;
71
72
        return $subStatement;
73
    }
74
75
    public function withObject(Object $object)
76
    {
77
        $subStatement = clone $this;
78
        $subStatement->object = $object;
79
80
        return $subStatement;
81
    }
82
83
    public function withResult(Result $result)
84
    {
85
        $subStatement = clone $this;
86
        $subStatement->result = $result;
87
88
        return $subStatement;
89
    }
90
91
    public function withContext(Context $context)
92
    {
93
        $subStatement = clone $this;
94
        $subStatement->context = $context;
95
96
        return $subStatement;
97
    }
98
99
    /**
100
     * Returns the Statement's {@link Verb}.
101
     *
102
     * @return Verb The Verb
103
     */
104
    public function getVerb()
105
    {
106
        return $this->verb;
107
    }
108
109
    /**
110
     * Returns the Statement's {@link Actor}.
111
     *
112
     * @return Actor The Actor
113
     */
114
    public function getActor()
115
    {
116
        return $this->actor;
117
    }
118
119
    /**
120
     * Returns the Statement's {@link Object}.
121
     *
122
     * @return \Xabbuh\XApi\Model\Object The Object
123
     */
124
    public function getObject()
125
    {
126
        return $this->object;
127
    }
128
129
    /**
130
     * Returns the {@link Activity} {@link Result}.
131
     *
132
     * @return Result The Result
133
     */
134
    public function getResult()
135
    {
136
        return $this->result;
137
    }
138
139
    /**
140
     * Returns the {@link Statement} {@link Context}.
141
     *
142
     * @return Context The Context
143
     */
144
    public function getContext()
145
    {
146
        return $this->context;
147
    }
148
149
    /**
150
     * Tests whether or not this Statement is a void Statement (i.e. it voids
151
     * another Statement).
152
     *
153
     * @return bool True if the Statement voids another Statement, false otherwise
154
     */
155
    public function isVoidStatement()
156
    {
157
        return $this->verb->isVoidVerb();
158
    }
159
160
    /**
161
     * {@inheritdoc}
162
     */
163
    public function equals(Object $statement)
164
    {
165
        if ('Xabbuh\XApi\Model\SubStatement' !== get_class($statement)) {
166
            return false;
167
        }
168
169
        /** @var SubStatement $statement */
170
171
        if (!$this->actor->equals($statement->actor)) {
172
            return false;
173
        }
174
175
        if (!$this->verb->equals($statement->verb)) {
176
            return false;
177
        }
178
179
        if (!$this->object->equals($statement->object)) {
180
            return false;
181
        }
182
183
        if (null === $this->result && null !== $statement->result) {
184
            return false;
185
        }
186
187
        if (null !== $this->result && null === $statement->result) {
188
            return false;
189
        }
190
191
        if (null !== $this->result && !$this->result->equals($statement->result)) {
192
            return false;
193
        }
194
195
        if (null !== $this->context xor null !== $statement->context) {
196
            return false;
197
        }
198
199
        if (null !== $this->context && !$this->context->equals($statement->context)) {
200
            return false;
201
        }
202
203
        return true;
204
    }
205
}
206