Completed
Pull Request — master (#19)
by Christian
02:16
created

SubStatement::getObject()   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 0
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 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 Context The {@link Statement} {@link Context}
48
     */
49
    private $context;
50
51
    public function __construct($id, Actor $actor, Verb $verb, Object $object, Result $result = null, Context $context = null)
52
    {
53
        $this->id = $id;
54
        $this->actor = $actor;
55
        $this->verb = $verb;
56
        $this->object = $object;
57
        $this->result = $result;
58
        $this->context = $context;
59
    }
60
61
    /**
62
     * Returns the Statement's unique identifier.
63
     *
64
     * @return string The identifier
65
     */
66
    public function getId()
67
    {
68
        return $this->id;
69
    }
70
71
    /**
72
     * Returns the Statement's {@link Verb}.
73
     *
74
     * @return Verb The Verb
75
     */
76
    public function getVerb()
77
    {
78
        return $this->verb;
79
    }
80
81
    /**
82
     * Returns the Statement's {@link Actor}.
83
     *
84
     * @return Actor The Actor
85
     */
86
    public function getActor()
87
    {
88
        return $this->actor;
89
    }
90
91
    /**
92
     * Returns the Statement's {@link Object}.
93
     *
94
     * @return \Xabbuh\XApi\Model\Object The Object
95
     */
96
    public function getObject()
97
    {
98
        return $this->object;
99
    }
100
101
    /**
102
     * Returns the {@link Activity} {@link Result}.
103
     *
104
     * @return Result The Result
105
     */
106
    public function getResult()
107
    {
108
        return $this->result;
109
    }
110
111
    /**
112
     * Returns the {@link Statement} {@link Context}.
113
     *
114
     * @return Context The Context
115
     */
116
    public function getContext()
117
    {
118
        return $this->context;
119
    }
120
121
    /**
122
     * Tests whether or not this Statement is a void Statement (i.e. it voids
123
     * another Statement).
124
     *
125
     * @return bool True if the Statement voids another Statement, false otherwise
126
     */
127
    public function isVoidStatement()
128
    {
129
        return $this->verb->isVoidVerb();
130
    }
131
132
    /**
133
     * Returns a {@link StatementReference} for the Statement.
134
     *
135
     * @return StatementReference The reference
136
     */
137
    public function getStatementReference()
138
    {
139
        $reference = new StatementReference($this->id);
140
141
        return $reference;
142
    }
143
144
    /**
145
     * Returns a Statement that voids the current Statement.
146
     *
147
     * @param Actor $actor The Actor voiding this Statement
148
     *
149
     * @return Statement The voiding Statement
150
     */
151
    public function getVoidStatement(Actor $actor)
152
    {
153
        return new Statement(
154
            null,
155
            $actor,
156
            Verb::createVoidVerb(),
157
            $this->getStatementReference()
158
        );
159
    }
160
161
    /**
162
     * {@inheritdoc}
163
     */
164
    public function equals(Object $statement)
165
    {
166
        if ('Xabbuh\XApi\Model\SubStatement' !== get_class($statement)) {
167
            return false;
168
        }
169
170
        /** @var SubStatement $statement */
171
172
        if ($this->id !== $statement->id) {
173
            return false;
174
        }
175
176
        if (!$this->actor->equals($statement->actor)) {
177
            return false;
178
        }
179
180
        if (!$this->verb->equals($statement->verb)) {
181
            return false;
182
        }
183
184
        if (!$this->object->equals($statement->object)) {
185
            return false;
186
        }
187
188
        if (null === $this->result && null !== $statement->result) {
189
            return false;
190
        }
191
192
        if (null !== $this->result && null === $statement->result) {
193
            return false;
194
        }
195
196
        if (null !== $this->result && !$this->result->equals($statement->result)) {
197
            return false;
198
        }
199
200
        if (null !== $this->context xor null !== $statement->context) {
201
            return false;
202
        }
203
204
        if (null !== $this->context && !$this->context->equals($statement->context)) {
205
            return false;
206
        }
207
208
        return true;
209
    }
210
}
211