Issues (14)

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/Expression.php (3 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 declare(strict_types = 1);
2
3
namespace Algatux\MongoDB\QueryBuilder;
4
5
/**
6
 * Class Expression.
7
 */
8
class Expression
9
{
10
    /** @var array */
11
    private $filters;
12
13
    /**
14
     * Expression constructor.
15
     */
16 24
    public function __construct()
17
    {
18 24
        $this->filters = [];
19 24
    }
20
21
    /**
22
     * Adds and filter
23
     *
24
     * @param array|Expression $expression
25
     *
26
     * @return $this|Expression
27
     */
28 View Code Duplication
    public function and($expression): Expression
0 ignored issues
show
The parameter $expression is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30 9
        $this->prepareFilterIndex('$and');
31
32 9
        $this->filters['$and'] = array_merge(
33 9
            $this->filters['$and'],
34 9
            $this->mapExpressions(...func_get_args())
35
        );
36
37 9
        return $this;
38
    }
39
40
    /**
41
     * @param string $operator
42
     */
43 19
    private function prepareFilterIndex(string $operator)
44
    {
45 19
        if (!isset($this->filters[$operator])) {
46 19
            $this->filters[$operator] = [];
47
        }
48 19
    }
49
50
    /**
51
     * @param  $expressions
52
     *
53
     * @return array
54
     */
55 10
    private function mapExpressions($expressions): array
0 ignored issues
show
The parameter $expressions is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
    {
57 10
        return array_map(
58
            function ($expression) {
59 10
                return $expression instanceof Expression ? $expression->getExpressionFilters() : $expression;
60 10
            },
61
            func_get_args()
62
        );
63
    }
64
65
    /**
66
     * Returns the filters generated by the expression
67
     * 
68
     * @return array
69
     */
70 24
    public function getExpressionFilters(): array
71
    {
72 24
        return $this->filters;
73
    }
74
75
    /**
76
     * Adds or filter
77
     * 
78
     * @param array|Expression $expression
79
     *
80
     * @return $this|Expression
81
     */
82 3 View Code Duplication
    public function or ($expression): Expression
0 ignored issues
show
The parameter $expression is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
83
    {
84 3
        $this->prepareFilterIndex('$or');
85
86 3
        $this->filters['$or'] = array_merge(
87 3
            $this->filters['$or'],
88 3
            $this->mapExpressions(...func_get_args())
89
        );
90
91 3
        return $this;
92
    }
93
94
    /**
95
     * Adds eq filter
96
     *
97
     * @param string $field
98
     * @param string $value
99
     *
100
     * @return $this|Expression
101
     */
102 2
    public function equal(string $field, $value): Expression
103
    {
104 2
        $this->prepareFilterIndex($field);
105
106 2
        $this->filters[$field] = $this->operationExpression('$eq', $value);
107
108 2
        return $this;
109
    }
110
111
    /**
112
     * Adds ne filter
113
     *
114
     * @param string $field
115
     * @param string $value
116
     *
117
     * @return $this|Expression
118
     */
119 4
    public function notEqual(string $field, $value): Expression
120
    {
121 4
        $this->prepareFilterIndex($field);
122
123 4
        $this->filters[$field] = $this->operationExpression('$ne', $value);
124
125 4
        return $this;
126
    }
127
128
    /**
129
     * Adds in filter
130
     *
131
     * @param string $field
132
     * @param array  $values
133
     *
134
     * @return $this|Expression
135
     */
136 2
    public function in(string $field, array $values): Expression
137
    {
138 2
        $this->prepareFilterIndex($field);
139
140 2
        $this->filters[$field] = $this->operationExpression('$in', $values);
141
142 2
        return $this;
143
    }
144
145
    /**
146
     * Adds notIn filter
147
     *
148
     * @param string $field
149
     * @param array  $values
150
     *
151
     * @return $this|Expression
152
     */
153 2
    public function notIn(string $field, array $values): Expression
154
    {
155 2
        $this->prepareFilterIndex($field);
156
157 2
        $this->filters[$field] = $this->operationExpression('$nin', $values);
158
159 2
        return $this;
160
    }
161
162
163
    /**
164
     * @param string $operation
165
     * @param mixed  $value
166
     *
167
     * @return array
168
     */
169 10
    private function operationExpression(string $operation, $value): array
170
    {
171 10
        return [$operation => $value];
172
    }
173
}
174