Issues (7)

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/Flat/Collection.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
namespace Mattbit\Flat;
4
5
use Mattbit\Flat\Query\Parser;
6
use Mattbit\Flat\Query\Matcher;
7
use Mattbit\Flat\Storage\DocumentStore;
8
use Mattbit\Flat\Model\DocumentInterface;
9
use Mattbit\Flat\Query\Expression\ExpressionInterface;
10
11
class Collection
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $name;
17
18
    /**
19
     * @var DocumentStore
20
     */
21
    protected $store;
22
23
    /**
24
     * @var Database
25
     */
26
    protected $database;
27
28
    /**
29
     * @var Parser
30
     */
31
    protected $parser;
32
33
    /**
34
     * Construct a new collection.
35
     *
36
     * @param Database      $database
37
     * @param DocumentStore $store
38
     * @param string        $name
39
     */
40 7
    public function __construct(Database $database, DocumentStore $store, $name)
41
    {
42 7
        $this->name = $name;
43 7
        $this->store = $store;
44 7
        $this->database = $database;
45 7
        $this->parser = $database->getParser();
46 7
    }
47
48
    /**
49
     * Drop the collection.
50
     *
51
     * @return bool
52
     */
53 1
    public function drop()
54
    {
55 1
        return $this->database->dropCollection($this->name);
56
    }
57
58
    /**
59
     * Remove all the documents from the collection.
60
     *
61
     * @return bool
62
     */
63 1
    public function truncate()
64
    {
65 1
        $this->store->truncate();
66 1
    }
67
68
    /**
69
     * Insert a new document.
70
     *
71
     * @param DocumentInterface $document
72
     *
73
     * @return bool
74
     */
75 1
    public function insert(DocumentInterface $document)
76
    {
77 1
        return $this->store->insert($document);
78
    }
79
80
    /**
81
     * Update existing documents.
82
     *
83
     * @param array        $criteria
84
     * @param DocumentInterface $updated
85
     * @param bool         $multiple
86
     *
87
     * @return int The count of the documents updated.
88
     */
89 View Code Duplication
    public function update($criteria, DocumentInterface $updated, $multiple = false)
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...
90
    {
91
        $limit = $multiple ? 1 : null;
92
        $documents = $this->onMatch($criteria, $limit);
93
94
        $count = 0;
95
        foreach ($documents as $document) {
96
            $updated->setId($document->getId());
97
            $this->store->update($updated);
98
            $count++;
99
        }
100
101
        return $count;
102
    }
103
104
    /**
105
     * Remove documents from the collection.
106
     *
107
     * @param mixed $criteria
108
     * @param bool  $multiple
109
     *
110
     * @return int The count of the document deleted.
111
     */
112 1 View Code Duplication
    public function remove($criteria, $multiple = false)
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...
113
    {
114 1
        $limit = $multiple ? 1 : null;
115
116 1
        $documents = $this->onMatch($criteria, $limit);
117
118 1
        $count = 0;
119 1
        foreach ($documents as $document) {
120 1
            $this->store->remove($document->get('_id'));
121 1
            $count++;
122 1
        }
123
124 1
        return $count;
125
    }
126
127
    /**
128
     * Find documents in the collection.
129
     *
130
     * @param array $criteria
131
     *
132
     * @return array The array of results.
133
     */
134 2
    public function find($criteria = [])
135
    {
136 2
        return $this->onMatch($criteria);
137
    }
138
139
    /**
140
     * Count documents in the collection.
141
     *
142
     * @param array $criteria
143
     * 
144
     * @return int The number of documents.
145
     */
146
    public function count($criteria = [])
147
    {
148
        if (empty($criteria)) {
149
            return $this->store->count();
150
        }
151
152
        return count($this->onMatch($criteria));
153
    }
154
155 3
    protected function onMatch($criteria, $limit = null)
156
    {
157 3
        $expression = $this->parser->parse($criteria);
158 3
        $matcher = $this->newMatcher($expression);
159
160 3
        $documents = $this->store->scan([$matcher, 'match'], $limit);
161
162 3
        return $documents;
163
    }
164
165 3
    protected function newMatcher(ExpressionInterface $expression)
166
    {
167 3
        return new Matcher($expression);
168
    }
169
}
170