Completed
Pull Request — master (#20)
by Christian
04:46 queued 01:40
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
c 1
b 1
f 0
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.6666
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
        $this->actor = $actor;
49
        $this->verb = $verb;
50
        $this->object = $object;
51
        $this->result = $result;
52
        $this->context = $context;
53
    }
54
55
    /**
56
     * Returns the Statement's {@link Verb}.
57
     *
58
     * @return Verb The Verb
59
     */
60
    public function getVerb()
61
    {
62
        return $this->verb;
63
    }
64
65
    /**
66
     * Returns the Statement's {@link Actor}.
67
     *
68
     * @return Actor The Actor
69
     */
70
    public function getActor()
71
    {
72
        return $this->actor;
73
    }
74
75
    /**
76
     * Returns the Statement's {@link Object}.
77
     *
78
     * @return \Xabbuh\XApi\Model\Object The Object
79
     */
80
    public function getObject()
81
    {
82
        return $this->object;
83
    }
84
85
    /**
86
     * Returns the {@link Activity} {@link Result}.
87
     *
88
     * @return Result The Result
89
     */
90
    public function getResult()
91
    {
92
        return $this->result;
93
    }
94
95
    /**
96
     * Returns the {@link Statement} {@link Context}.
97
     *
98
     * @return Context The Context
99
     */
100
    public function getContext()
101
    {
102
        return $this->context;
103
    }
104
105
    /**
106
     * Tests whether or not this Statement is a void Statement (i.e. it voids
107
     * another Statement).
108
     *
109
     * @return bool True if the Statement voids another Statement, false otherwise
110
     */
111
    public function isVoidStatement()
112
    {
113
        return $this->verb->isVoidVerb();
114
    }
115
116
    /**
117
     * Returns a {@link StatementReference} for the Statement.
118
     *
119
     * @return StatementReference The reference
120
     */
121
    public function getStatementReference()
122
    {
123
        $reference = new StatementReference($this->id);
0 ignored issues
show
Bug introduced by
The property id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
124
125
        return $reference;
126
    }
127
128
    /**
129
     * Returns a Statement that voids the current Statement.
130
     *
131
     * @param Actor $actor The Actor voiding this Statement
132
     *
133
     * @return Statement The voiding Statement
134
     */
135
    public function getVoidStatement(Actor $actor)
136
    {
137
        return new Statement(
138
            null,
139
            $actor,
140
            Verb::createVoidVerb(),
141
            $this->getStatementReference()
142
        );
143
    }
144
145
    /**
146
     * {@inheritdoc}
147
     */
148
    public function equals(Object $statement)
149
    {
150
        if ('Xabbuh\XApi\Model\SubStatement' !== get_class($statement)) {
151
            return false;
152
        }
153
154
        /** @var SubStatement $statement */
155
156
        if (!$this->actor->equals($statement->actor)) {
157
            return false;
158
        }
159
160
        if (!$this->verb->equals($statement->verb)) {
161
            return false;
162
        }
163
164
        if (!$this->object->equals($statement->object)) {
165
            return false;
166
        }
167
168
        if (null === $this->result && null !== $statement->result) {
169
            return false;
170
        }
171
172
        if (null !== $this->result && null === $statement->result) {
173
            return false;
174
        }
175
176
        if (null !== $this->result && !$this->result->equals($statement->result)) {
177
            return false;
178
        }
179
180
        if (null !== $this->context xor null !== $statement->context) {
181
            return false;
182
        }
183
184
        if (null !== $this->context && !$this->context->equals($statement->context)) {
185
            return false;
186
        }
187
188
        return true;
189
    }
190
}
191