Issues (44)

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/Dialect/AbstractDialect.php (6 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 Graze\DataDb\Dialect;
4
5
use Graze\DataDb\Formatter\SyntaxFormatter;
6
use Graze\DataDb\Formatter\SyntaxFormatterInterface;
7
use Graze\DataDb\SourceTableNodeInterface;
8
use Graze\DataDb\TableNodeInterface;
9
use Graze\DataFile\Helper\Builder\BuilderTrait;
10
11
abstract class AbstractDialect implements DialectInterface
12
{
13
    use BuilderTrait;
14
15
    /**
16
     * @var SyntaxFormatterInterface
17
     */
18
    protected $formatter;
19
20
    /**
21
     * MysqlDialect constructor.
22
     *
23
     * @param SyntaxFormatterInterface|null $formatter
24
     */
25
    public function __construct(SyntaxFormatterInterface $formatter = null)
26
    {
27
        $this->formatter = $formatter;
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    abstract public function getIdentifierQuote();
34
35
    /**
36
     * @param string $syntax
37
     * @param array  $params
38
     *
39
     * @return string
40
     */
41
    protected function format($syntax, array $params = [])
42
    {
43
        if (!$this->formatter) {
44
            $this->formatter = $this->getBuilder()->build(SyntaxFormatter::class);
45
            $this->formatter->setIdentifierQuote($this->getIdentifierQuote());
46
        }
47
48
        return $this->formatter->format($syntax, $params);
49
    }
50
51
    /**
52
     * @param TableNodeInterface $table
53
     * @param string             $column
54
     *
55
     * @return array
56
     */
57 View Code Duplication
    public function getDropColumn(TableNodeInterface $table, $column)
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...
58
    {
59
        return [
60
            $this->format(
61
                'ALTER TABLE {table:schema|q}.{table:table|q} DROP COLUMN {column|q}',
62
                ['table' => $table, 'column' => $column,]
63
            ),
64
            [],
65
        ];
66
    }
67
68
    /**
69
     * @param TableNodeInterface $table
70
     *
71
     * @return array
72
     */
73
    public function getDoesTableExist(TableNodeInterface $table)
74
    {
75
        return [
76
            'SELECT
77
                table_name
78
            FROM
79
                information_schema.tables
80
            WHERE
81
                table_schema = ?
82
                AND table_name = ?',
83
            [
84
                $table->getSchema(),
85
                $table->getTable(),
86
            ],
87
        ];
88
    }
89
90
    /**
91
     * @param TableNodeInterface $table
92
     * @param string|null        $where
93
     *
94
     * @return array
95
     */
96 View Code Duplication
    public function getDeleteFromTable(TableNodeInterface $table, $where = null)
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
        return [
99
            $this->format(
100
                'DELETE FROM {table:schema|q}.{table:table|q}
101
                {where}',
102
                [
103
                    'table' => $table,
104
                    'where' => ($where ? 'WHERE ' . $where : ''),
105
                ]
106
            ),
107
            [],
108
        ];
109
    }
110
111
    /**
112
     * @param TableNodeInterface $from
113
     * @param TableNodeInterface $to
114
     *
115
     * @return array
116
     */
117
    public function getCopyTable(TableNodeInterface $from, TableNodeInterface $to)
118
    {
119 View Code Duplication
        if ($from->getColumns()) {
0 ignored issues
show
This code seems to be duplicated across 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...
120
            $fromColumns = implode(',', array_map(function ($column) {
121
                return $this->format('{column|q}', ['column' => $column]);
122
            }, $from->getColumns()));
123
        } else {
124
            $fromColumns = '*';
125
        }
126
127 View Code Duplication
        if ($to->getColumns()) {
0 ignored issues
show
This code seems to be duplicated across 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...
128
            $toColumns = sprintf(
129
                ' (%s)',
130
                implode(',', array_map(function ($column) {
131
                    return $this->format('{column|q}', ['column' => $column]);
132
                }, $to->getColumns()))
133
            );
134
        } else {
135
            $toColumns = '';
136
        }
137
138
        return [
139
            $this->format(
140
                'INSERT INTO {to:schema|q}.{to:table|q}{toColumns}
141
                SELECT {fromColumns} FROM {from:schema|q}.{from:table|q}',
142
                [
143
                    'from'        => $from,
144
                    'to'          => $to,
145
                    'fromColumns' => $fromColumns,
146
                    'toColumns'   => $toColumns,
147
                ]
148
            ),
149
            [],
150
        ];
151
    }
152
153
    /**
154
     * @param TableNodeInterface $table
155
     *
156
     * @return array [sql, params]
157
     */
158
    public function getSelectSyntax(TableNodeInterface $table)
159
    {
160 View Code Duplication
        if ($table->getColumns()) {
0 ignored issues
show
This code seems to be duplicated across 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...
161
            $fromColumns = implode(',', array_map(function ($column) {
162
                return $this->format('{column|q}', ['column' => $column]);
163
            }, $table->getColumns()));
164
        } else {
165
            $fromColumns = '*';
166
        }
167
168
        $where = '';
169
        if ($table instanceof SourceTableNodeInterface && $table->getWhere()) {
170
            $where = ' WHERE (' . $table->getWhere() . ')';
171
        }
172
173
        return [
174
            $this->format(
175
                'SELECT {fromColumns} FROM {from:schema|q}.{from:table|q}{where}',
176
                [
177
                    'from'        => $table,
178
                    'fromColumns' => $fromColumns,
179
                    'where'       => $where,
180
                ]
181
            ),
182
            [],
183
        ];
184
    }
185
186
    /**
187
     * @param TableNodeInterface $table
188
     * @param string[]           $rows
189
     *
190
     * @return array [sql, params]
191
     */
192
    public function getInsertSyntax(TableNodeInterface $table, array $rows)
193
    {
194 View Code Duplication
        if ($table->getColumns()) {
0 ignored issues
show
This code seems to be duplicated across 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...
195
            $toColumns = sprintf(
196
                ' (%s)',
197
                implode(',', array_map(function ($column) {
198
                    return $this->format('{column|q}', ['column' => $column]);
199
                }, $table->getColumns()))
200
            );
201
        } else {
202
            $toColumns = '';
203
        }
204
205
        $bind = [];
206
        $insert = [];
207
        foreach ($rows as $row) {
208
            $insert[] = '(' . substr(str_repeat('?,', count($row)), 0, -1) . ')';
209
            $bind = array_merge($bind, array_values($row));
210
        }
211
212
        $insertSql = implode(',', $insert);
213
214
        return [
215
            $this->format(
216
                'INSERT INTO {table:schema|q}.{table:table|q}{toColumns} VALUES {insertSql}',
217
                compact('table', 'toColumns', 'insertSql')
218
            ),
219
            $bind,
220
        ];
221
    }
222
}
223