Issues (9)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Statement.php (3 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
 * An Experience API {@link https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#statement Statement}.
16
 *
17
 * @author Christian Flothmann <[email protected]>
18
 */
19
final class Statement
20
{
21
    private $id;
22
    private $verb;
23
    private $actor;
24
    private $object;
25
    private $result;
26
    private $authority;
27
    private $created;
28
    private $stored;
29
    private $context;
30
    private $attachments;
31
    private $version;
32
33
    /**
34
     * @param Attachment[]|null $attachments
35
     */
36
    public function __construct(StatementId $id = null, Actor $actor, Verb $verb, StatementObject $object, Result $result = null, Actor $authority = null, \DateTime $created = null, \DateTime $stored = null, Context $context = null, array $attachments = null, string $version = null)
37
    {
38
        $this->id = $id;
39
        $this->actor = $actor;
40
        $this->verb = $verb;
41
        $this->object = $object;
42
        $this->result = $result;
43
        $this->authority = $authority;
44
        $this->created = $created;
45
        $this->stored = $stored;
46
        $this->context = $context;
47
        $this->attachments = null !== $attachments ? array_values($attachments) : null;
48
        $this->version = $version;
49
    }
50
51
    public function withId(StatementId $id = null): self
52
    {
53
        $statement = clone $this;
54
        $statement->id = $id;
55
56
        return $statement;
57
    }
58
59
    public function withActor(Actor $actor): self
60
    {
61 4
        $statement = clone $this;
62
        $statement->actor = $actor;
63 4
64 4
        return $statement;
65 4
    }
66 4
67 4
    public function withVerb(Verb $verb): self
68 4
    {
69 4
        $statement = clone $this;
70 4
        $statement->verb = $verb;
71 4
72
        return $statement;
73
    }
74
75
    public function withObject(StatementObject $object): self
76
    {
77
        $statement = clone $this;
78 2
        $statement->object = $object;
79
80 2
        return $statement;
81
    }
82
83
    public function withResult(Result $result = null): self
84
    {
85
        $statement = clone $this;
86
        $statement->result = $result;
87
88 3
        return $statement;
89
    }
90 3
91
    /**
92
     * Creates a new Statement based on the current one containing an Authority
93
     * that asserts the Statement true.
94
     */
95
    public function withAuthority(Actor $authority = null): self
96
    {
97
        $statement = clone $this;
98 3
        $statement->authority = $authority;
99
100 3
        return $statement;
101
    }
102
103
    public function withCreated(\DateTime $created = null): self
104
    {
105
        $statement = clone $this;
106
        $statement->created = $created;
107
108 3
        return $statement;
109
    }
110 3
111
    public function withStored(\DateTime $stored = null): self
112
    {
113
        $statement = clone $this;
114
        $statement->stored = $stored;
115
116
        return $statement;
117
    }
118
119
    public function withContext(Context $context = null): self
120
    {
121
        $statement = clone $this;
122
        $statement->context = $context;
123
124
        return $statement;
125
    }
126
127
    /**
128 2
     * @param Attachment[]|null $attachments
129
     */
130 2
    public function withAttachments(array $attachments = null): self
131
    {
132
        $statement = clone $this;
133
        $statement->attachments = null !== $attachments ? array_values($attachments) : null;
134
135
        return $statement;
136
    }
137
138
    public function withVersion(string $version = null): self
139
    {
140
        $statement = clone $this;
141
        $statement->version = $version;
142
143
        return $statement;
144
    }
145
146
    /**
147
     * Returns the Statement's unique identifier.
148
     */
149
    public function getId(): ?StatementId
150
    {
151
        return $this->id;
152
    }
153
154
    /**
155
     * Returns the Statement's {@link Verb}.
156
     */
157
    public function getVerb(): Verb
158
    {
159
        return $this->verb;
160
    }
161
162
    /**
163
     * Returns the Statement's {@link Actor}.
164
     */
165
    public function getActor(): Actor
166
    {
167
        return $this->actor;
168
    }
169
170 2
    /**
171
     * Returns the Statement's {@link StatementObject}.
172 2
     */
173
    public function getObject(): StatementObject
174 2
    {
175
        return $this->object;
176
    }
177
178
    /**
179
     * Returns the {@link Activity} {@link Result}.
180
     */
181
    public function getResult(): ?Result
182
    {
183
        return $this->result;
184 1
    }
185
186 1
    /**
187 1
     * Returns the Authority that asserted the Statement true.
188
     */
189 1
    public function getAuthority(): ?Actor
190 1
    {
191
        return $this->authority;
192
    }
193
194
    /**
195
     * Returns the timestamp of when the events described in this statement
196
     * occurred.
197
     */
198
    public function getCreated(): ?\DateTime
199
    {
200
        return $this->created;
201
    }
202 2
203
    /**
204 2
     * Returns the timestamp of when this statement was recorded by the LRS.
205
     */
206
    public function getStored(): ?\DateTime
207
    {
208
        return $this->stored;
209
    }
210
211
    /**
212
     * Returns the context that gives the statement more meaning.
213
     */
214
    public function getContext(): ?Context
215
    {
216 2
        return $this->context;
217
    }
218 2
219
    /**
220
     * @return Attachment[]|null
221
     */
222 2
    public function getAttachments(): ?array
223
    {
224
        return $this->attachments;
225
    }
226 2
227
    public function getVersion(): ?string
228
    {
229
        return $this->version;
230 2
    }
231
232
    /**
233
     * Tests whether or not this Statement is a void Statement (i.e. it voids
234 2
     * another Statement).
235
     */
236
    public function isVoidStatement(): bool
237
    {
238 2
        return $this->verb->isVoidVerb();
239
    }
240
241
    /**
242 2
     * Returns a {@link StatementReference} for the Statement.
243
     */
244
    public function getStatementReference(): StatementReference
245
    {
246 2
        return new StatementReference($this->id);
0 ignored issues
show
It seems like $this->id can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
247 1
    }
248
249
    /**
250 1
     * Returns a Statement that voids the current Statement.
251
     */
252
    public function getVoidStatement(Actor $actor): self
253
    {
254 1
        return new Statement(
255 1
            null,
256
            $actor,
257
            Verb::createVoidVerb(),
258
            $this->getStatementReference()
259
        );
260
    }
261
262
    /**
263
     * Checks if another statement is equal.
264
     *
265
     * Two statements are equal if and only if all of their properties are equal.
266
     */
267
    public function equals(Statement $statement): bool
268
    {
269
        if (null !== $this->id xor null !== $statement->id) {
270
            return false;
271
        }
272
273
        if (null !== $this->id && null !== $statement->id && !$this->id->equals($statement->id)) {
274
            return false;
275
        }
276
277
        if (!$this->actor->equals($statement->actor)) {
278
            return false;
279
        }
280
281
        if (!$this->verb->equals($statement->verb)) {
282
            return false;
283
        }
284
285
        if (!$this->object->equals($statement->object)) {
286
            return false;
287
        }
288
289
        if (null === $this->result && null !== $statement->result) {
290
            return false;
291
        }
292
293
        if (null !== $this->result && null === $statement->result) {
294
            return false;
295
        }
296
297
        if (null !== $this->result && !$this->result->equals($statement->result)) {
0 ignored issues
show
It seems like $statement->result can be null; however, equals() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
298
            return false;
299
        }
300
301
        if (null === $this->authority && null !== $statement->authority) {
302
            return false;
303
        }
304
305
        if (null !== $this->authority && null === $statement->authority) {
306
            return false;
307
        }
308
309
        if (null !== $this->authority && !$this->authority->equals($statement->authority)) {
0 ignored issues
show
It seems like $statement->authority can be null; however, equals() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
310
            return false;
311
        }
312
313
        if ($this->created != $statement->created) {
314
            return false;
315
        }
316
317
        if (null !== $this->context xor null !== $statement->context) {
318
            return false;
319
        }
320
321
        if (null !== $this->context && null !== $statement->context && !$this->context->equals($statement->context)) {
322
            return false;
323
        }
324
325
        if (null !== $this->attachments xor null !== $statement->attachments) {
326
            return false;
327
        }
328
329
        if (null !== $this->attachments && null !== $statement->attachments) {
330
            if (count($this->attachments) !== count($statement->attachments)) {
331
                return false;
332
            }
333
334
            foreach ($this->attachments as $key => $attachment) {
335
                if (!$attachment->equals($statement->attachments[$key])) {
336
                    return false;
337
                }
338
            }
339
        }
340
341
        return true;
342
    }
343
}
344