Issues (10)

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/DbDumper.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
2
3
namespace Spatie\DbDumper;
4
5
use Spatie\DbDumper\Compressors\Compressor;
6
use Spatie\DbDumper\Compressors\GzipCompressor;
7
use Spatie\DbDumper\Exceptions\CannotSetParameter;
8
use Spatie\DbDumper\Exceptions\DumpFailed;
9
use Symfony\Component\Process\Process;
10
11
abstract class DbDumper
12
{
13
    /** @var string */
14
    protected $dbName;
15
16
    /** @var string */
17
    protected $userName;
18
19
    /** @var string */
20
    protected $password;
21
22
    /** @var string */
23
    protected $host = 'localhost';
24
25
    /** @var int */
26
    protected $port = 5432;
27
28
    /** @var string */
29
    protected $socket = '';
30
31
    /** @var int */
32
    protected $timeout = 0;
33
34
    /** @var string */
35
    protected $dumpBinaryPath = '';
36
37
    /** @var array */
38
    protected $includeTables = [];
39
40
    /** @var array */
41
    protected $excludeTables = [];
42
43
    /** @var array */
44
    protected $extraOptions = [];
45
46
    /** @var array */
47
    protected $extraOptionsAfterDbName = [];
48
49
    /** @var object */
50
    protected $compressor = null;
51
52
    public static function create()
53
    {
54
        return new static();
55
    }
56
57
    public function getDbName(): string
58
    {
59
        return $this->dbName;
60
    }
61
62
    /**
63
     * @param string $dbName
64
     *
65
     * @return $this
66
     */
67
    public function setDbName(string $dbName)
68
    {
69
        $this->dbName = $dbName;
70
71
        return $this;
72
    }
73
74
    /**
75
     * @param string $userName
76
     *
77
     * @return $this
78
     */
79
    public function setUserName(string $userName)
80
    {
81
        $this->userName = $userName;
82
83
        return $this;
84
    }
85
86
    /**
87
     * @param string $password
88
     *
89
     * @return $this
90
     */
91
    public function setPassword(string $password)
92
    {
93
        $this->password = $password;
94
95
        return $this;
96
    }
97
98
    /**
99
     * @param string $host
100
     *
101
     * @return $this
102
     */
103
    public function setHost(string $host)
104
    {
105
        $this->host = $host;
106
107
        return $this;
108
    }
109
110
    public function getHost(): string
111
    {
112
        return $this->host;
113
    }
114
115
    /**
116
     * @param int $port
117
     *
118
     * @return $this
119
     */
120
    public function setPort(int $port)
121
    {
122
        $this->port = $port;
123
124
        return $this;
125
    }
126
127
    /**
128
     * @param string $socket
129
     *
130
     * @return $this
131
     */
132
    public function setSocket(string $socket)
133
    {
134
        $this->socket = $socket;
135
136
        return $this;
137
    }
138
139
    /**
140
     * @param int $timeout
141
     *
142
     * @return $this
143
     */
144
    public function setTimeout(int $timeout)
145
    {
146
        $this->timeout = $timeout;
147
148
        return $this;
149
    }
150
151
    public function setDumpBinaryPath(string $dumpBinaryPath)
152
    {
153
        if ($dumpBinaryPath !== '' && substr($dumpBinaryPath, -1) !== '/') {
154
            $dumpBinaryPath .= '/';
155
        }
156
157
        $this->dumpBinaryPath = $dumpBinaryPath;
158
159
        return $this;
160
    }
161
162
    /**
163
     * @deprecated
164
     *
165
     * @return $this
166
     */
167
    public function enableCompression()
168
    {
169
        $this->compressor = new GzipCompressor();
170
171
        return $this;
172
    }
173
174
    public function getCompressorExtension(): string
175
    {
176
        return $this->compressor->useExtension();
177
    }
178
179
    public function useCompressor(Compressor $compressor)
180
    {
181
        $this->compressor = $compressor;
182
183
        return $this;
184
    }
185
186
    /**
187
     * @param string|array $includeTables
188
     *
189
     * @return $this
190
     *
191
     * @throws \Spatie\DbDumper\Exceptions\CannotSetParameter
192
     */
193 View Code Duplication
    public function includeTables($includeTables)
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...
194
    {
195
        if (! empty($this->excludeTables)) {
196
            throw CannotSetParameter::conflictingParameters('includeTables', 'excludeTables');
197
        }
198
199
        if (! is_array($includeTables)) {
200
            $includeTables = explode(', ', $includeTables);
201
        }
202
203
        $this->includeTables = $includeTables;
204
205
        return $this;
206
    }
207
208
    /**
209
     * @param string|array $excludeTables
210
     *
211
     * @return $this
212
     *
213
     * @throws \Spatie\DbDumper\Exceptions\CannotSetParameter
214
     */
215 View Code Duplication
    public function excludeTables($excludeTables)
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...
216
    {
217
        if (! empty($this->includeTables)) {
218
            throw CannotSetParameter::conflictingParameters('excludeTables', 'includeTables');
219
        }
220
221
        if (! is_array($excludeTables)) {
222
            $excludeTables = explode(', ', $excludeTables);
223
        }
224
225
        $this->excludeTables = $excludeTables;
226
227
        return $this;
228
    }
229
230
    /**
231
     * @param string $extraOption
232
     *
233
     * @return $this
234
     */
235
    public function addExtraOption(string $extraOption)
236
    {
237
        if (! empty($extraOption)) {
238
            $this->extraOptions[] = $extraOption;
239
        }
240
241
        return $this;
242
    }
243
244
    /**
245
     * @param string $extraOptionAtEnd
0 ignored issues
show
There is no parameter named $extraOptionAtEnd. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
246
     *
247
     * @return $this
248
     */
249
    public function addExtraOptionAfterDbName(string $extraOptionAfterDbName)
250
    {
251
        if (! empty($extraOptionAfterDbName)) {
252
            $this->extraOptionsAfterDbName[] = $extraOptionAfterDbName;
253
        }
254
255
        return $this;
256
    }
257
258
    abstract public function dumpToFile(string $dumpFile);
259
260
    protected function checkIfDumpWasSuccessFul(Process $process, string $outputFile)
261
    {
262
        if (! $process->isSuccessful()) {
263
            throw DumpFailed::processDidNotEndSuccessfully($process);
264
        }
265
266
        if (! file_exists($outputFile)) {
267
            throw DumpFailed::dumpfileWasNotCreated();
268
        }
269
270
        if (filesize($outputFile) === 0) {
271
            throw DumpFailed::dumpfileWasEmpty();
272
        }
273
    }
274
275
    protected function getCompressCommand(string $command, string $dumpFile): string
276
    {
277
        $compressCommand = $this->compressor->useCommand();
278
279
        if ($this->isWindows()) {
280
            return "{$command} | {$compressCommand} > {$dumpFile}";
281
        }
282
283
        return "(((({$command}; echo \$? >&3) | {$compressCommand} > {$dumpFile}) 3>&1) | (read x; exit \$x))";
284
    }
285
286
    protected function echoToFile(string $command, string $dumpFile): string
287
    {
288
        $dumpFile = '"'.addcslashes($dumpFile, '\\"').'"';
289
290
        if ($this->compressor) {
291
            return $this->getCompressCommand($command, $dumpFile);
292
        }
293
294
        return $command.' > '.$dumpFile;
295
    }
296
297
    protected function determineQuote(): string
298
    {
299
        return $this->isWindows() ? '"' : "'";
300
    }
301
302
    protected function isWindows(): bool
303
    {
304
        return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
305
    }
306
}
307