Issues (39)

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.

Api/StatementsApiClient.php (7 issues)

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\Client\Api;
13
14
use Xabbuh\XApi\Client\Request\HandlerInterface;
15
use Xabbuh\XApi\Serializer\ActorSerializerInterface;
16
use Xabbuh\XApi\Serializer\StatementResultSerializerInterface;
17
use Xabbuh\XApi\Serializer\StatementSerializerInterface;
18
use Xabbuh\XApi\Model\Actor;
19
use Xabbuh\XApi\Model\Statement;
20
use Xabbuh\XApi\Model\StatementResult;
21
use Xabbuh\XApi\Model\StatementsFilter;
22
23
/**
24
 * Client to access the statements API of an xAPI based learning record store.
25
 *
26
 * @author Christian Flothmann <[email protected]>
27
 */
28
class StatementsApiClient extends ApiClient implements StatementsApiClientInterface
29
{
30
    /**
31
     * @var StatementSerializerInterface
32
     */
33
    private $statementSerializer;
34
35
    /**
36
     * @var StatementResultSerializerInterface
37
     */
38
    private $statementResultSerializer;
39
40
    /**
41
     * @var ActorSerializerInterface
42
     */
43
    private $actorSerializer;
44
45
    /**
46
     * @param HandlerInterface                   $requestHandler            The HTTP request handler
47
     * @param string                             $version                   The xAPI version
48
     * @param StatementSerializerInterface       $statementSerializer       The statement serializer
49
     * @param StatementResultSerializerInterface $statementResultSerializer The statement result serializer
50
     * @param ActorSerializerInterface           $actorSerializer           The actor serializer
51
     */
52
    public function __construct(
53
        HandlerInterface $requestHandler,
54
        $version,
55
        StatementSerializerInterface $statementSerializer,
56
        StatementResultSerializerInterface $statementResultSerializer,
57
        ActorSerializerInterface $actorSerializer
58
    ) {
59
        parent::__construct($requestHandler, $version);
60
        $this->statementSerializer = $statementSerializer;
61
        $this->statementResultSerializer = $statementResultSerializer;
62
        $this->actorSerializer = $actorSerializer;
63
    }
64
65
    /**
66
     * {@inheritDoc}
67
     */
68
    public function storeStatement(Statement $statement)
69
    {
70
        if (null !== $statement->getId()) {
71
            return $this->doStoreStatements(
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->doStoreStatements...tement->getId()), 204); of type array|Xabbuh\XApi\Model\Statement adds the type array to the return on line 71 which is incompatible with the return type declared by the interface Xabbuh\XApi\Client\Api\S...terface::storeStatement of type Xabbuh\XApi\Model\Statement.
Loading history...
72
                $statement,
73
                'put',
74
                array('statementId' => $statement->getId()),
75
                204
76
            );
77
        } else {
78
            return $this->doStoreStatements($statement);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->doStoreStatements($statement); of type array|Xabbuh\XApi\Model\Statement adds the type array to the return on line 78 which is incompatible with the return type declared by the interface Xabbuh\XApi\Client\Api\S...terface::storeStatement of type Xabbuh\XApi\Model\Statement.
Loading history...
79
        }
80
    }
81
82
    /**
83
     * {@inheritDoc}
84
     */
85
    public function storeStatements(array $statements)
86
    {
87
        // check that only Statements without ids will be sent to the LRS
88
        foreach ($statements as $statement) {
89
            /** @var Statement $statement */
90
91
            $isStatement = is_object($statement) && $statement instanceof Statement;
92
93
            if (!$isStatement || null !== $statement->getId()) {
94
                throw new \InvalidArgumentException('API can only handle statements without ids');
95
            }
96
        }
97
98
        return $this->doStoreStatements($statements);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->doStoreStatements($statements); of type array|Xabbuh\XApi\Model\Statement adds the type Xabbuh\XApi\Model\Statement to the return on line 98 which is incompatible with the return type declared by the interface Xabbuh\XApi\Client\Api\S...erface::storeStatements of type Xabbuh\XApi\Model\Statement[].
Loading history...
99
    }
100
101
    /**
102
     * {@inheritDoc}
103
     */
104
    public function voidStatement(Statement $statement, Actor $actor)
105
    {
106
        return $this->storeStatement($statement->getVoidStatement($actor));
107
    }
108
109
    /**
110
     * {@inheritDoc}
111
     */
112
    public function getStatement($statementId)
113
    {
114
        return $this->doGetStatements('statements', array('statementId' => $statementId));
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->doGetStatements('...tId' => $statementId)); of type Xabbuh\XApi\Model\Statem...i\Model\StatementResult adds the type Xabbuh\XApi\Model\StatementResult to the return on line 114 which is incompatible with the return type declared by the interface Xabbuh\XApi\Client\Api\S...Interface::getStatement of type Xabbuh\XApi\Model\Statement.
Loading history...
115
    }
116
117
    /**
118
     * {@inheritDoc}
119
     */
120
    public function getVoidedStatement($statementId)
121
    {
122
        return $this->doGetStatements('statements', array('voidedStatementId' => $statementId));
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->doGetStatements('...tId' => $statementId)); of type Xabbuh\XApi\Model\Statem...i\Model\StatementResult adds the type Xabbuh\XApi\Model\StatementResult to the return on line 122 which is incompatible with the return type declared by the interface Xabbuh\XApi\Client\Api\S...ace::getVoidedStatement of type Xabbuh\XApi\Model\Statement.
Loading history...
123
    }
124
125
    /**
126
     * {@inheritDoc}
127
     */
128
    public function getStatements(StatementsFilter $filter = null)
129
    {
130
        $urlParameters = array();
131
132
        if (null !== $filter) {
133
            $urlParameters = $filter->getFilter();
134
        }
135
136
        // the Agent must be JSON encoded
137
        if (isset($urlParameters['agent'])) {
138
            $urlParameters['agent'] = $this->actorSerializer->serializeActor($urlParameters['agent']);
139
        }
140
141
        return $this->doGetStatements('statements', $urlParameters);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->doGetStatements('...ents', $urlParameters); of type Xabbuh\XApi\Model\Statem...i\Model\StatementResult adds the type Xabbuh\XApi\Model\Statement to the return on line 141 which is incompatible with the return type declared by the interface Xabbuh\XApi\Client\Api\S...nterface::getStatements of type Xabbuh\XApi\Model\StatementResult.
Loading history...
142
    }
143
144
    /**
145
     * {@inheritDoc}
146
     */
147
    public function getNextStatements(StatementResult $statementResult)
148
    {
149
        return $this->doGetStatements($statementResult->getMoreUrlPath());
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->doGetStatements($...ult->getMoreUrlPath()); of type Xabbuh\XApi\Model\Statem...i\Model\StatementResult adds the type Xabbuh\XApi\Model\Statement to the return on line 149 which is incompatible with the return type declared by the interface Xabbuh\XApi\Client\Api\S...face::getNextStatements of type Xabbuh\XApi\Model\StatementResult.
Loading history...
150
    }
151
152
    /**
153
     * @param Statement|Statement[] $statements
154
     * @param string                $method
155
     * @param string[]              $parameters
156
     * @param int                   $validStatusCode
157
     *
158
     * @return Statement|Statement[] The created statement(s)
159
     */
160
    private function doStoreStatements($statements, $method = 'post', $parameters = array(), $validStatusCode = 200)
161
    {
162
        if (is_array($statements)) {
163
            $serializedStatements = $this->statementSerializer->serializeStatements($statements);
164
        } else {
165
            $serializedStatements = $this->statementSerializer->serializeStatement($statements);
166
        }
167
168
        $request = $this->requestHandler->createRequest(
169
            $method,
170
            'statements',
171
            $parameters,
172
            $serializedStatements
173
        );
174
        $response = $this->requestHandler->executeRequest($request, array($validStatusCode));
175
        $statementIds = json_decode($response->getBody(true));
176
177
        if (is_array($statements)) {
178
            /** @var Statement[] $statements */
179
            $createdStatements = array();
180
181
            foreach ($statements as $index => $statement) {
182
                $createdStatements[] = new Statement(
183
                    $statementIds[$index],
184
                    $statement->getActor(),
185
                    $statement->getVerb(),
186
                    $statement->getObject(),
187
                    $statement->getResult()
188
                );
189
            }
190
191
            return $createdStatements;
192
        } else {
193
            /** @var Statement $statements */
194
195
            if (200 === $validStatusCode) {
196
                return new Statement(
197
                    $statementIds[0],
198
                    $statements->getActor(),
199
                    $statements->getVerb(),
200
                    $statements->getObject(),
201
                    $statements->getResult()
202
                );
203
            } else {
204
                return new Statement(
205
                    $statements->getId(),
206
                    $statements->getActor(),
207
                    $statements->getVerb(),
208
                    $statements->getObject(),
209
                    $statements->getResult()
210
                );
211
            }
212
        }
213
    }
214
215
    /**
216
     * Fetch one or more Statements.
217
     *
218
     * @param string $url           URL to request
219
     * @param array  $urlParameters URL parameters
220
     *
221
     * @return Statement|StatementResult
222
     */
223
    private function doGetStatements($url, array $urlParameters = array())
224
    {
225
        $request = $this->requestHandler->createRequest('get', $url, $urlParameters);
226
        $response = $this->requestHandler->executeRequest($request, array(200));
227
228
        if (isset($urlParameters['statementId']) || isset($urlParameters['voidedStatementId'])) {
229
            return $this->statementSerializer->deserializeStatement($response->getBody(true));
230
        } else {
231
            return $this->statementResultSerializer->deserializeStatementResult($response->getBody(true));
232
        }
233
    }
234
}
235