Issues (43)

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/Data/EntityRepository.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
 * Created by IntelliJ IDEA.
4
 * User: gerk
5
 * Date: 06.01.17
6
 * Time: 11:50
7
 */
8
9
namespace PeekAndPoke\Component\Slumber\Data;
10
11
use PeekAndPoke\Component\Slumber\Core\Exception\SlumberRuntimeException;
12
use PeekAndPoke\Component\Slumber\Data\Error\DuplicateError;
13
use PeekAndPoke\Component\Slumber\Data\MongoDb\MongoDbUtil;
14
use PeekAndPoke\Component\Slumber\Data\Result\InsertOneResult;
15
use PeekAndPoke\Component\Slumber\Data\Result\SaveOneResult;
16
17
18
/**
19
 * @author Karsten J. Gerber <[email protected]>
20
 */
21
class EntityRepository implements Repository
22
{
23
    /** @var string */
24
    private $name;
25
    /** @var StorageDriver */
26
    private $driver;
27
28
    public function __construct($name, StorageDriver $driver)
29
    {
30
        $this->name   = $name;
31
        $this->driver = $driver;
32
    }
33
34
    /**
35
     * @return string
36
     */
37 4
    public function getName()
38
    {
39 4
        return $this->name;
40
    }
41
42
    /**
43
     * @return \ReflectionClass
44
     */
45
    public function getEntityClass()
46
    {
47
        return $this->driver->getEntityBaseClass();
48
    }
49
50
    /**
51
     * TODO: remove me! It was only used to find a repo by sub-classes ... we no longer need this
52
     * @return string[]
53
     */
54
    public function getEntityClassAliases()
55
    {
56
        return [];
57
    }
58
59
    /**
60
     * @return mixed
61
     */
62
    public function buildIndexes()
63
    {
64
        return $this->driver->buildIndexes();
65
    }
66
67
    /**
68
     * Insert a database entry
69
     *
70
     * @param mixed $subject
71
     *
72
     * @return InsertOneResult
73
     *
74
     * @throws SlumberRuntimeException When the given subject cannot be stored in this repository
75
     * @throws DuplicateError          When the underlying database permits the insert, due to a duplicate key exception
76
     */
77 3 View Code Duplication
    public function insert($subject)
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...
78
    {
79 3
        if ($subject === null || ! \is_object($subject)) {
80
            return null;
81
        }
82
83 3
        $this->checkObjectCompatibility($subject);
84
85 3
        return $this->driver->insert($subject);
86
    }
87
88
    /**
89
     * @param mixed $subject
90
     *
91
     * @return SaveOneResult
92
     *
93
     * @throws SlumberRuntimeException When the given subject cannot be stored in this repository
94
     * @throws DuplicateError          When the underlying database permits the insert, due to a duplicate key exception
95
     */
96 25 View Code Duplication
    public function save($subject)
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...
97
    {
98 25
        if ($subject === null || ! \is_object($subject)) {
99 17
            return null;
100
        }
101
102 25
        $this->checkObjectCompatibility($subject);
103
104 25
        return $this->driver->save($subject);
105
    }
106
107
    /**
108
     * @param $query
109
     *
110
     * @return Cursor
111
     */
112 11
    public function find(array $query = null)
113
    {
114 11
        return $this->driver->find($query);
115
    }
116
117
    /**
118
     * @param array|null $query
119
     *
120
     * @return mixed|null
121
     */
122 19
    public function findOne(array $query = null)
123
    {
124 19
        return $this->driver->findOne($query);
125
    }
126
127
    /**
128
     * @param mixed $id
129
     *
130
     * @return mixed|null
131
     */
132 19
    public function findById($id)
133
    {
134 19
        return $this->findOne([
135 19
            '_id' => MongoDbUtil::ensureMongoId($id),
136
        ]);
137
    }
138
139
    /**
140
     * Find one object by its public reference
141
     *
142
     * @param string $reference
143
     *
144
     * @return mixed|null
145
     */
146 1
    public function findByReference($reference)
147
    {
148 1
        return $this->findOne([
149 1
            'reference' => $reference,
150
        ]);
151
    }
152
153
    /**
154
     * @param $entity
155
     *
156
     * @return Result\RemoveResult
157
     */
158 3
    public function remove($entity)
159
    {
160 3
        return $this->driver->remove($entity);
161
    }
162
163
    /**
164
     * Remove all from this collection
165
     *
166
     * @param array|null $query
167
     *
168
     * @return Result\RemoveResult
169
     */
170 25
    public function removeAll(array $query = null)
171
    {
172 25
        return $this->driver->removeAll($query);
173
    }
174
175
    /**
176
     * @param $subject
177
     *
178
     * @throw SlumberRuntimeException
179
     */
180 28
    private function checkObjectCompatibility($subject)
181
    {
182 28
        $entityClassName = $this->driver->getEntityBaseClass()->name;
183
184 28
        $isOk = \is_object($subject) && $subject instanceof $entityClassName;
185
186 28
        if (! $isOk) {
187
            throw new SlumberRuntimeException(
188
                'Repository ' . \get_class($this) . ' can only store objects of type ' . $entityClassName .
189
                ' but a ' . \get_class($subject) . ' was given!'
190
            );
191
        }
192 28
    }
193
}
194