Issues (50)

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/Query/Grammar.php (7 issues)

Labels
Severity

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
declare(strict_types=1);
3
4
/**
5
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
11
 * THE SOFTWARE.
12
 */
13
14
namespace Ytake\LaravelCouchbase\Query;
15
16
use Illuminate\Database\Query\Builder;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Ytake\LaravelCouchbase\Query\Builder.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
17
use Ytake\LaravelCouchbase\Query\Builder as QueryBuilder;
18
use Illuminate\Database\Query\Grammars\Grammar as IlluminateGrammar;
19
20
/**
21
 * Class Grammar.
22
 *
23
 * @author Yuuki Takezawa<[email protected]>
24
 */
25
class Grammar extends IlluminateGrammar
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30 20
    protected function wrapValue($value)
31
    {
32 20
        if ($value === '*') {
33 10
            return $value;
34
        }
35
36 20
        return $value;
37
    }
38
39
    /**
40
     * @param mixed $value
41
     *
42
     * @return string
43
     */
44 14
    protected function wrapKey($value)
45
    {
46 14
        if (is_null($value)) {
47
            return;
48
        }
49
50 14
        return '"' . str_replace('"', '""', $value) . '"';
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     *
56
     * notice: supported set query only
57
     */
58 2
    public function compileUpdate(Builder $query, $values)
59
    {
60
        // keyspace-ref:
61 2
        $table = $this->wrapTable($query->from);
62
        // use-keys-clause:
63 2
        $keyClause = $this->wrapKey($query->key);
0 ignored issues
show
The property key does not seem to exist in Illuminate\Database\Query\Builder.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
64
        // returning-clause
65 2
        $returning = implode(', ', $query->returning);
0 ignored issues
show
The property returning does not seem to exist in Illuminate\Database\Query\Builder.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
66
67 2
        $columns = [];
68
69 2
        foreach ($values as $key => $value) {
70 2
            $columns[] = $this->wrap($key) . ' = ' . $this->parameter($value);
71
        }
72
73 2
        $columns = implode(', ', $columns);
74
75 2
        $joins = '';
76 2
        if (isset($query->joins)) {
77
            $joins = ' ' . $this->compileJoins($query, $query->joins);
78
        }
79 2
        $where = $this->compileWheres($query);
80
81 2
        return trim("update {$table} USE KEYS {$keyClause} {$joins} set $columns $where RETURNING {$returning}");
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87 10
    public function compileInsert(Builder $query, array $values)
88
    {
89
        // keyspace-ref:
90 10
        $table = $this->wrapTable($query->from);
91
        // use-keys-clause:
92 10
        $keyClause = $this->wrapKey($query->key);
0 ignored issues
show
The property key does not seem to exist in Illuminate\Database\Query\Builder.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
93
        // returning-clause
94 10
        $returning = implode(', ', $query->returning);
0 ignored issues
show
The property returning does not seem to exist in Illuminate\Database\Query\Builder.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
95
96 10
        if (!is_array(reset($values))) {
97
            $values = [$values];
98
        }
99 10
        $parameters = [];
100
101 10
        foreach ($values as $record) {
102 10
            $parameters[] = '(' . $this->parameterize($record) . ')';
103
        }
104 10
        $parameters = (!$keyClause) ? implode(', ', $parameters) : "({$keyClause}, \$parameters)";
105 10
        $keyValue = (!$keyClause) ? null : '(KEY, VALUE)';
106
107 10
        return "insert into {$table} {$keyValue} values $parameters RETURNING {$returning}";
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     *
113
     * @see http://developer.couchbase.com/documentation/server/4.1/n1ql/n1ql-language-reference/delete.html
114
     */
115 8
    public function compileDelete(Builder $query)
116
    {
117
        // keyspace-ref:
118 8
        $table = $this->wrapTable($query->from);
119
        // use-keys-clause:
120 8
        $keyClause = null;
121 8
        if ($query->key) {
122 4
            $key = $this->wrapKey($query->key);
0 ignored issues
show
The property key does not seem to exist in Illuminate\Database\Query\Builder.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
123 4
            $keyClause = "USE KEYS {$key}";
124
        }
125
        // returning-clause
126 8
        $returning = implode(', ', $query->returning);
0 ignored issues
show
The property returning does not seem to exist in Illuminate\Database\Query\Builder.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
127 8
        $where = is_array($query->wheres) ? $this->compileWheres($query) : '';
128
129 8
        return trim("delete from {$table} {$keyClause} {$where} RETURNING {$returning}");
130
    }
131
132
    /**
133
     * @param QueryBuilder $query
134
     * @param array        $values
135
     *
136
     * @return string
137
     */
138 2
    public function compileUpsert(QueryBuilder $query, array $values): string
139
    {
140
        // keyspace-ref:
141 2
        $table = $this->wrapTable($query->from);
142
        // use-keys-clause:
143 2
        $keyClause = $this->wrapKey($query->key);
144
        // returning-clause
145 2
        $returning = implode(', ', $query->returning);
146
147 2
        if (!is_array(reset($values))) {
148
            $values = [$values];
149
        }
150 2
        $parameters = [];
151
152 2
        foreach ($values as $record) {
153 2
            $parameters[] = '(' . $this->parameterize($record) . ')';
154
        }
155 2
        $parameters = (!$keyClause) ? implode(', ', $parameters) : "({$keyClause}, \$parameters)";
156 2
        $keyValue = (!$keyClause) ? null : '(KEY, VALUE)';
157
158 2
        return "UPSERT INTO {$table} {$keyValue} VALUES $parameters RETURNING {$returning}";
159
    }
160
}
161