Completed
Pull Request — master (#22)
by Christian
04:46 queued 02:13
created

SubStatement::getVoidStatement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 1
f 0
ccs 0
cts 5
cp 0
cc 1
eloc 6
nc 1
nop 1
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
    /**
60
     * Returns the Statement's {@link Verb}.
61
     *
62
     * @return Verb The Verb
63
     */
64
    public function getVerb()
65
    {
66
        return $this->verb;
67
    }
68
69
    /**
70
     * Returns the Statement's {@link Actor}.
71
     *
72
     * @return Actor The Actor
73
     */
74
    public function getActor()
75
    {
76
        return $this->actor;
77
    }
78
79
    /**
80
     * Returns the Statement's {@link Object}.
81
     *
82
     * @return \Xabbuh\XApi\Model\Object The Object
83
     */
84
    public function getObject()
85
    {
86
        return $this->object;
87
    }
88
89
    /**
90
     * Returns the {@link Activity} {@link Result}.
91
     *
92
     * @return Result The Result
93
     */
94
    public function getResult()
95
    {
96
        return $this->result;
97
    }
98
99
    /**
100
     * Returns the {@link Statement} {@link Context}.
101
     *
102
     * @return Context The Context
103
     */
104
    public function getContext()
105
    {
106
        return $this->context;
107
    }
108
109
    /**
110
     * Tests whether or not this Statement is a void Statement (i.e. it voids
111
     * another Statement).
112
     *
113
     * @return bool True if the Statement voids another Statement, false otherwise
114
     */
115
    public function isVoidStatement()
116
    {
117
        return $this->verb->isVoidVerb();
118
    }
119
120
    /**
121
     * {@inheritdoc}
122
     */
123
    public function equals(Object $statement)
124
    {
125
        if ('Xabbuh\XApi\Model\SubStatement' !== get_class($statement)) {
126
            return false;
127
        }
128
129
        /** @var SubStatement $statement */
130
131
        if (!$this->actor->equals($statement->actor)) {
132
            return false;
133
        }
134
135
        if (!$this->verb->equals($statement->verb)) {
136
            return false;
137
        }
138
139
        if (!$this->object->equals($statement->object)) {
140
            return false;
141
        }
142
143
        if (null === $this->result && null !== $statement->result) {
144
            return false;
145
        }
146
147
        if (null !== $this->result && null === $statement->result) {
148
            return false;
149
        }
150
151
        if (null !== $this->result && !$this->result->equals($statement->result)) {
152
            return false;
153
        }
154
155
        if (null !== $this->context xor null !== $statement->context) {
156
            return false;
157
        }
158
159
        if (null !== $this->context && !$this->context->equals($statement->context)) {
160
            return false;
161
        }
162
163
        return true;
164
    }
165
}
166