Issues (6)

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.

StatementRepository.php (2 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\Storage\Api;
13
14
use Rhumsaa\Uuid\Uuid;
15
use Xabbuh\XApi\Model\Actor;
16
use Xabbuh\XApi\Model\Statement;
17
use Xabbuh\XApi\Model\StatementsFilter;
18
use Xabbuh\XApi\Storage\Api\Exception\NotFoundException;
19
use Xabbuh\XApi\Storage\Api\Mapping\MappedStatement;
20
21
/**
22
 * {@link Statement} repository.
23
 *
24
 * @author Christian Flothmann <[email protected]>
25
 */
26
abstract class StatementRepository
27
{
28
    /**
29
     * Finds a {@link Statement} by id.
30
     *
31
     * @param string     $statementId The statement id to filter by
32
     * @param Actor|null $authority   (Optional) actor that must be the authority
33
     *                                of the returned statement
34
     *
35
     * @return Statement The statement
36
     *
37
     * @throws NotFoundException if no Statement with the given UUID does exist
38
     */
39 View Code Duplication
    final public function findStatementById($statementId, Actor $authority = null)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        $criteria = array('id' => $statementId);
42
43
        if (null !== $authority) {
44
            $criteria['authority'] = $authority;
45
        }
46
47
        $mappedStatement = $this->findMappedStatement($criteria);
48
49
        if (null === $mappedStatement) {
50
            throw new NotFoundException();
51
        }
52
53
        $statement = $mappedStatement->getModel();
54
55
        if ($statement->isVoidStatement()) {
56
            throw new NotFoundException();
57
        }
58
59
        return $statement;
60
    }
61
62
    /**
63
     * Finds a voided {@link Statement} by id.
64
     *
65
     * @param string     $voidedStatementId The voided statement id to filter
66
     *                                      by
67
     * @param Actor|null $authority         (Optional) actor that must be the
68
     *                                      authority of the returned statement
69
     *
70
     * @return Statement The statement
71
     *
72
     * @throws NotFoundException if no voided Statement with the given UUID
73
     *                           does exist
74
     */
75 View Code Duplication
    final public function findVoidedStatementById($voidedStatementId, Actor $authority = null)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        $criteria = array('id' => $voidedStatementId);
78
79
        if (null !== $authority) {
80
            $criteria['authority'] = $authority;
81
        }
82
83
        $mappedStatement = $this->findMappedStatement($criteria);
84
85
        if (null === $mappedStatement) {
86
            throw new NotFoundException();
87
        }
88
89
        $statement = $mappedStatement->getModel();
90
91
        if (!$statement->isVoidStatement()) {
92
            throw new NotFoundException();
93
        }
94
95
        return $statement;
96
    }
97
98
    /**
99
     * Finds a collection of {@link Statement Statements} filtered by the given
100
     * criteria.
101
     *
102
     * @param StatementsFilter $criteria  The criteria to filter by
103
     * @param Actor|null       $authority (Optional) actor that must be the
104
     *                                    authority of the returned statements
105
     *
106
     * @return Statement[] The statements
107
     */
108
    final public function findStatementsBy(StatementsFilter $criteria, Actor $authority = null)
109
    {
110
        $criteria = $criteria->getFilter();
111
112
        if (null !== $authority) {
113
            $criteria['authority'] = $authority;
114
        }
115
116
        $mappedStatements = $this->findMappedStatements($criteria);
117
        $statements = array();
118
119
        foreach ($mappedStatements as $mappedStatement) {
120
            $statements[] = $mappedStatement->getModel();
121
        }
122
123
        return $statements;
124
    }
125
126
    /**
127
     * Writes a {@link Statement} to the underlying data storage.
128
     *
129
     * @param Statement $statement The statement to store
130
     * @param bool      $flush     Whether or not to flush the managed objects
131
     *                             immediately (i.e. write them to the data
132
     *                             storage)
133
     *
134
     * @return string The UUID of the created Statement
135
     */
136
    final public function storeStatement(Statement $statement, $flush = true)
137
    {
138
        $uuid = $statement->getId();
139
        $mappedStatement = MappedStatement::createFromModel($statement);
140
        $mappedStatement->stored = new \DateTime();
141
142
        if (null === $uuid) {
143
            $uuid = Uuid::uuid4()->toString();
144
            $mappedStatement->id = $uuid;
145
        }
146
147
        $this->storeMappedStatement($mappedStatement, $flush);
148
149
        return $uuid;
150
    }
151
152
    /**
153
     * Loads a certain {@link MappedStatement} from the data storage.
154
     *
155
     * @param array $criteria Criteria to filter a statement by
156
     *
157
     * @return MappedStatement The mapped statement
158
     */
159
    abstract protected function findMappedStatement(array $criteria);
160
161
    /**
162
     * Loads {@link MappedStatement mapped statements} from the data storage.
163
     *
164
     * @param array $criteria Criteria to filter statements by
165
     *
166
     * @return MappedStatement[] The mapped statements
167
     */
168
    abstract protected function findMappedStatements(array $criteria);
169
170
    /**
171
     * Writes a {@link MappedStatement mapped statement} to the underlying
172
     * data storage.
173
     *
174
     * @param MappedStatement $mappedStatement The statement to store
175
     * @param bool            $flush           Whether or not to flush the managed
176
     *                                         objects immediately (i.e. write
177
     *                                         them to the data storage)
178
     */
179
    abstract protected function storeMappedStatement(MappedStatement $mappedStatement, $flush);
180
}
181