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

Context::withTeam()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 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
 * Contextual information for an xAPI statement.
16
 *
17
 * @author Christian Flothmann <[email protected]>
18
 */
19
final class Context
20
{
21
    private $registration;
22
    private $instructor;
23
    private $team;
24
    private $contextActivities;
25
    private $revision;
26
    private $platform;
27
    private $language;
28
    private $statement;
29
    private $extensions;
30
31
    /**
32
     * @param string $registration
33
     *
34
     * @return self
35
     */
36
    public function withRegistration($registration)
37
    {
38
        $context = clone $this;
39
        $context->registration = $registration;
40
41
        return $context;
42
    }
43
44
    public function withInstructor(Actor $instructor)
45
    {
46
        $context = clone $this;
47
        $context->instructor = $instructor;
48
49
        return $context;
50
    }
51
52
    public function withTeam(Group $team)
53
    {
54
        $context = clone $this;
55
        $context->team = $team;
56
57
        return $context;
58
    }
59
60
    public function withContextActivities(ContextActivities $contextActivities)
61
    {
62
        $context = clone $this;
63
        $context->contextActivities = $contextActivities;
64
65
        return $context;
66
    }
67
68
    /**
69
     * @param string $revision
70
     *
71
     * @return self
72
     */
73
    public function withRevision($revision)
74
    {
75
        $context = clone $this;
76
        $context->revision = $revision;
77
78
        return $context;
79
    }
80
81
    /**
82
     * @param string $platform
83
     *
84
     * @return self
85
     */
86
    public function withPlatform($platform)
87
    {
88
        $context = clone $this;
89
        $context->platform = $platform;
90
91
        return $context;
92
    }
93
94
    /**
95
     * @param string $language
96
     *
97
     * @return self
98
     */
99
    public function withLanguage($language)
100
    {
101
        $context = clone $this;
102
        $context->language = $language;
103
104
        return $context;
105
    }
106
107
    public function withStatement(StatementReference $statement)
108
    {
109
        $context = clone $this;
110
        $context->statement = $statement;
111
112
        return $context;
113
    }
114
115
    public function withExtensions(Extensions $extensions)
116
    {
117
        $context = clone $this;
118
        $context->extensions = $extensions;
119
120
        return $context;
121
    }
122
123
    /**
124
     * @return string|null
125
     */
126
    public function getRegistration()
127
    {
128
        return $this->registration;
129
    }
130
131
    /**
132
     * @return Actor|null
133
     */
134
    public function getInstructor()
135
    {
136
        return $this->instructor;
137
    }
138
139
    /**
140
     * @return Group|null
141
     */
142
    public function getTeam()
143
    {
144
        return $this->team;
145
    }
146
147
    /**
148
     * @return ContextActivities|null
149
     */
150
    public function getContextActivities()
151
    {
152
        return $this->contextActivities;
153
    }
154
155
    /**
156
     * @return string|null
157
     */
158
    public function getRevision()
159
    {
160
        return $this->revision;
161
    }
162
163
    /**
164
     * @return string|null
165
     */
166
    public function getPlatform()
167
    {
168
        return $this->platform;
169
    }
170
171
    /**
172
     * @return string|null
173
     */
174
    public function getLanguage()
175
    {
176
        return $this->language;
177
    }
178
179
    /**
180
     * @return StatementReference|null
181
     */
182
    public function getStatement()
183
    {
184
        return $this->statement;
185
    }
186
187
    /**
188
     * @return Extensions|null
189
     */
190
    public function getExtensions()
191
    {
192
        return $this->extensions;
193
    }
194
195
    public function equals(Context $context)
196
    {
197
        if ($this->registration !== $context->registration) {
198
            return false;
199
        }
200
201
        if (null !== $this->instructor xor null !== $context->instructor) {
202
            return false;
203
        }
204
205
        if (null !== $this->instructor && !$this->instructor->equals($context->instructor)) {
206
            return false;
207
        }
208
209
        if (null !== $this->team xor null !== $context->team) {
210
            return false;
211
        }
212
213
        if (null !== $this->team && !$this->team->equals($context->instructor)) {
214
            return false;
215
        }
216
217
        if ($this->contextActivities != $context->contextActivities) {
218
            return false;
219
        }
220
221
        if ($this->revision !== $context->revision) {
222
            return false;
223
        }
224
225
        if ($this->platform !== $context->platform) {
226
            return false;
227
        }
228
229
        if ($this->language !== $context->language) {
230
            return false;
231
        }
232
233
        if (null !== $this->statement xor null !== $context->statement) {
234
            return false;
235
        }
236
237
        if (null !== $this->statement && !$this->statement->equals($context->instructor)) {
238
            return false;
239
        }
240
241
        if (null !== $this->extensions xor null !== $context->extensions) {
242
            return false;
243
        }
244
245
        if (null !== $this->extensions && !$this->extensions->equals($context->instructor)) {
0 ignored issues
show
Documentation introduced by
$context->instructor is of type object<Xabbuh\XApi\Model\Actor>, but the function expects a object<Xabbuh\XApi\Model\Extensions>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
246
            return false;
247
        }
248
249
        return true;
250
    }
251
}
252