Issues (251)

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.

lib/Doctrine/ODM/CouchDB/DocumentManager.php (10 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
namespace Doctrine\ODM\CouchDB;
4
5
use Doctrine\Common\EventManager;
6
use Doctrine\Common\Persistence\ObjectManager;
7
use Doctrine\CouchDB\CouchDBClient;
8
use Doctrine\CouchDB\View;
9
use Doctrine\CouchDB\View\Query;
10
use Doctrine\ODM\CouchDB\Mapping\ClassMetadataFactory;
11
use Doctrine\ODM\CouchDB\View\ODMQuery;
12
use Doctrine\ODM\CouchDB\View\ODMLuceneQuery;
13
use Doctrine\ODM\CouchDB\CouchDBException;
14
15
class DocumentManager implements ObjectManager
16
{
17
    /**
18
     * @var Configuration
19
     */
20
    private $config;
21
22
    /**
23
     * @var Mapping\ClassMetadataFactory
24
     */
25
    private $metadataFactory;
26
27
    /**
28
     * @var UnitOfWork
29
     */
30
    private $unitOfWork = null;
31
32
    /**
33
     * @var \Doctrine\ODM\CouchDB\Proxy\ProxyFactory
34
     */
35
    private $proxyFactory = null;
36
37
    /**
38
     * @var array
39
     */
40
    private $repositories = array();
41
42
    /**
43
     * @var CouchDBClient
44
     */
45
    private $couchDBClient = null;
46
47
    /**
48
     * @var EventManager
49
     */
50
    private $evm;
51
52
    /**
53
     * @param CouchDBClient $couchClient
54
     * @param Configuration $config
55
     * @param EventManager $evm
56
     */
57
    public function __construct(CouchDBClient $couchClient, Configuration $config = null, EventManager $evm = null)
58
    {
59
        $this->couchDBClient = $couchClient;
60
        $this->config = $config ?: new Configuration();
61
        $this->evm = $evm ?: new EventManager();
62
        $this->metadataFactory = new ClassMetadataFactory($this);
63
        $this->unitOfWork = new UnitOfWork($this);
64
        $this->proxyFactory = new Proxy\ProxyFactory($this, $this->config->getProxyDir(), $this->config->getProxyNamespace(), $this->config->getAutoGenerateProxyClasses());
65
    }
66
67
    /**
68
     * @return EventManager
69
     */
70
    public function getEventManager()
71
    {
72
        return $this->evm;
73
    }
74
75
    /**
76
     * @return CouchDBClient
77
     */
78
    public function getCouchDBClient()
79
    {
80
        return $this->couchDBClient;
81
    }
82
83
    /**
84
     * Factory method for a Document Manager.
85
     *
86
     * @param array|CouchDBClient $couchParams
87
     * @param Configuration       $config
88
     * @param EventManager        $evm
89
     * @return DocumentManager
90
     * @throws \InvalidArgumentException
91
     */
92
    public static function create($couchParams, Configuration $config = null, EventManager $evm = null)
93
    {
94
        if (is_array($couchParams)) {
95
            $couchClient = CouchDBClient::create($couchParams);
96
        } else if ($couchParams instanceof CouchDBClient) {
97
            $couchClient = $couchParams;
98
        } else {
99
            throw new \InvalidArgumentException("Expecting array of instance of CouchDBClient as first argument to DocumentManager::create().");
100
        }
101
102
        return new DocumentManager($couchClient, $config, $evm);
103
    }
104
105
    /**
106
     * @return ClassMetadataFactory
107
     */
108
    public function getMetadataFactory()
109
    {
110
        return $this->metadataFactory;
111
    }
112
113
    /**
114
     * @return Proxy\ProxyFactory
115
     */
116
    public function getProxyFactory()
117
    {
118
        return $this->proxyFactory;
119
    }
120
121
    public function getHttpClient()
122
    {
123
        return $this->couchDBClient->getHttpClient();
124
    }
125
126
    public function getDatabase()
127
    {
128
        return $this->couchDBClient->getDatabase();
129
    }
130
131
    /**
132
     * @return Configuration
133
     */
134
    public function getConfiguration()
135
    {
136
        return $this->config;
137
    }
138
139
    /**
140
     * @return ClassMetadataFactory
141
     */
142
    public function getClassMetadataFactory()
143
    {
144
        return $this->metadataFactory;
145
    }
146
147
    /**
148
     * @param  string $class
149
     * @return \Doctrine\ODM\CouchDB\Mapping\ClassMetadata
150
     */
151
    public function getClassMetadata($class)
152
    {
153
        return $this->metadataFactory->getMetadataFor($class);
154
    }
155
156
    /**
157
     * Find the Document with the given id.
158
     *
159
     * Will return null if the document wasn't found.
160
     *
161
     * @param string $documentName
162
     * @param string $id
163
     * @return object
164
     */
165
    public function find($documentName, $id)
166
    {
167
        return $this->getRepository($documentName)->find($id);
168
    }
169
170
    /**
171
     * @param  string $documentName
172
     * @return \Doctrine\ODM\CouchDB\DocumentRepository
173
     */
174
    public function getRepository($documentName)
175
    {
176
        $documentName  = ltrim($documentName, '\\');
177
        if (!isset($this->repositories[$documentName])) {
178
            $class = $this->getClassMetadata($documentName);
179
            if ($class->customRepositoryClassName) {
180
                $repositoryClass = $class->customRepositoryClassName;
181
            } else {
182
                $repositoryClass = 'Doctrine\ODM\CouchDB\DocumentRepository';
183
            }
184
            $this->repositories[$documentName] = new $repositoryClass($this, $class);
185
        }
186
        return $this->repositories[$documentName];
187
    }
188
189
    /**
190
     * Create a Query for the view in the specified design document.
191
     *
192
     * @param  string $designDocName
193
     * @param  string $viewName
194
     * @return \Doctrine\ODM\CouchDB\View\ODMQuery
195
     */
196 View Code Duplication
    public function createQuery($designDocName, $viewName)
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...
197
    {
198
        $designDoc = $this->config->getDesignDocument($designDocName);
199
        if ($designDoc) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $designDoc of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
200
            $designDoc = new $designDoc['className']($designDoc['options']);
201
        }
202
        $query = new ODMQuery($this->couchDBClient->getHttpClient(), $this->couchDBClient->getDatabase(), $designDocName, $viewName, $designDoc);
0 ignored issues
show
$designDoc is of type object|array, but the function expects a null|object<Doctrine\CouchDB\View\DesignDocument>.

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...
203
        $query->setDocumentManager($this);
204
        return $query;
205
    }
206
207
    /**
208
     * Create a Native query for the view of the specified design document.
209
     *
210
     * A native query will return an array of data from the &include_docs=true parameter.
211
     *
212
     * @param  string $designDocName
213
     * @param  string $viewName
214
     * @return \Doctrine\CouchDB\View\Query
215
     */
216 View Code Duplication
    public function createNativeQuery($designDocName, $viewName)
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...
217
    {
218
        $designDoc = $this->config->getDesignDocument($designDocName);
219
        if ($designDoc) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $designDoc of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
220
            $designDoc = new $designDoc['className']($designDoc['options']);
221
        }
222
        $query = new Query($this->couchDBClient->getHttpClient(), $this->couchDBClient->getDatabase(), $designDocName, $viewName, $designDoc);
0 ignored issues
show
$designDoc is of type object|array, but the function expects a null|object<Doctrine\CouchDB\View\DesignDocument>.

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...
223
        return $query;
224
    }
225
226
    /**
227
     * Create a CouchDB-Lucene Query.
228
     *
229
     * @param string $designDocName
230
     * @param string $viewName
231
     * @return \Doctrine\ODM\CouchDB\View\ODMLuceneQuery
232
     */
233 View Code Duplication
    public function createLuceneQuery($designDocName, $viewName)
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...
234
    {
235
        $luceneHandlerName = $this->config->getLuceneHandlerName();
236
        $designDoc = $this->config->getDesignDocument($designDocName);
237
        if ($designDoc) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $designDoc of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
238
            $designDoc = new $designDoc['className']($designDoc['options']);
239
        }
240
        $query = new ODMLuceneQuery($this->couchDBClient->getHttpClient(),
241
            $this->couchDBClient->getDatabase(), $luceneHandlerName, $designDocName,
242
            $viewName, $designDoc
0 ignored issues
show
$designDoc is of type object|array, but the function expects a null|object<Doctrine\CouchDB\View\DesignDocument>.

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...
243
        );
244
        $query->setDocumentManager($this);
245
        return $query;
246
    }
247
248
    public function persist($object)
249
    {
250
        $this->unitOfWork->scheduleInsert($object);
251
    }
252
253
    public function remove($object)
254
    {
255
        $this->unitOfWork->scheduleRemove($object);
256
    }
257
258
    /**
259
     * Refresh the given document by querying the CouchDB to get the current state.
260
     *
261
     * @param object $document
262
     */
263
    public function refresh($document)
264
    {
265
        $this->getUnitOfWork()->refresh($document);
266
    }
267
268
    public function merge($document)
269
    {
270
        return $this->getUnitOfWork()->merge($document);
271
    }
272
273
    public function detach($document)
274
    {
275
        $this->getUnitOfWork()->detach($document);
276
    }
277
278
    /**
279
     * Gets a reference to the entity identified by the given type and identifier
280
     * without actually loading it, if the entity is not yet loaded.
281
     *
282
     * @param string $documentName The name of the entity type.
283
     * @param mixed $identifier The entity identifier.
284
     * @return object The entity reference.
285
     */
286
    public function getReference($documentName, $identifier)
287
    {
288
        $class = $this->metadataFactory->getMetadataFor(ltrim($documentName, '\\'));
289
290
        // Check identity map first, if its already in there just return it.
291
        if ($document = $this->unitOfWork->tryGetById($identifier)) {
292
            return $document;
293
        }
294
        $document = $this->proxyFactory->getProxy($class->name, $identifier);
295
        $this->unitOfWork->registerManaged($document, $identifier, null);
296
297
        return $document;
298
    }
299
300
    public function flush()
301
    {
302
        $this->unitOfWork->flush(); // todo: rename commit
303
    }
304
305
    /**
306
     * @param  object $document
307
     * @return bool
308
     */
309
    public function contains($document)
310
    {
311
        return $this->unitOfWork->contains($document);
312
    }
313
314
    /**
315
     * @return UnitOfWork
316
     */
317
    public function getUnitOfWork()
318
    {
319
        return $this->unitOfWork;
320
    }
321
322
    /**
323
     * Clears the ObjectManager. All objects that are currently managed
324
     * by this ObjectManager become detached.
325
     *
326
     * @param string $objectName if given, only objects of this type will get detached
327
     * @throws CouchDBException
328
     */
329
    public function clear($objectName = null)
330
    {
331
        if ($objectName === null) {
332
            // Todo: Do a real delegated clear?
333
            $this->unitOfWork = new UnitOfWork($this);
334
        } else {
335
            //TODO
336
            throw new CouchDBException("DocumentManager#clear(\$objectName) not yet implemented.");
337
        }
338
    }
339
340
    /**
341
     * Initialize an object that is a lazy load proxy, or do nothing.
342
     *
343
     * @param object $obj
344
     */
345
    public function initializeObject($obj)
346
    {
347
        if ($obj instanceof PersistentCollection) {
348
            $obj->initialize();
349
        } else if ($obj instanceof Proxy\Proxy) {
350
            $obj->__doctrineLoad__();
0 ignored issues
show
The method __doctrineLoad__() does not seem to exist on object<Doctrine\ODM\CouchDB\Proxy\Proxy>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
351
        }
352
    }
353
}
354