Skip to content

Commit 9a64d20

Browse files
committed
use modern php features
1 parent da26b03 commit 9a64d20

File tree

4 files changed

+17
-40
lines changed

4 files changed

+17
-40
lines changed

src/Sql/MySQL.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@ public function dump(): string
2020
throw new BinaryNotFoundException($this->command . ' was not found');
2121
}
2222

23-
$config = $this->getConfig();
24-
2523
$command = [
2624
$this->command,
27-
'--user="' . ($config['username'] ?? '') . '"',
28-
'--password="' . ($config['password'] ?? '') . '"',
29-
'--default-character-set=' . ($config['encoding'] ?? 'utf8mb4'),
30-
'--host=' . ($config['host'] ?? 'localhost'),
25+
'--user="' . ($this->config['username'] ?? '') . '"',
26+
'--password="' . ($this->config['password'] ?? '') . '"',
27+
'--default-character-set=' . ($this->config['encoding'] ?? 'utf8mb4'),
28+
'--host=' . ($this->config['host'] ?? 'localhost'),
3129
'--databases',
32-
$config['database'],
30+
$this->config['database'],
3331
'--no-create-db',
3432
];
3533
if ($this->isDataOnly()) {

src/Sql/PostgreSQL.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ public function dump(): string
2222
throw new BinaryNotFoundException($this->command . ' was not found');
2323
}
2424

25-
$config = $this->getConfig();
2625
$passFile = $this->writePassFile();
2726

2827
$command = [
2928
'PGPASSFILE=' . $passFile,
3029
$this->command,
31-
'--host=' . ($config['host'] ?? 'localhost'),
32-
'--username=' . ($config['username'] ?? ''),
33-
'--dbname="' . ($config['database'] ?? '') . '"',
30+
'--host=' . ($this->config['host'] ?? 'localhost'),
31+
'--username=' . ($this->config['username'] ?? ''),
32+
'--dbname="' . ($this->config['database'] ?? '') . '"',
3433
];
3534
if ($this->isDataOnly()) {
3635
$command[] = '--data-only';
@@ -42,7 +41,7 @@ public function dump(): string
4241
$output = $process->getOutput();
4342
$error = $process->getErrorOutput();
4443

45-
if (strpos($error, 'server version mismatch') !== false) {
44+
if (str_contains($error, 'server version mismatch')) {
4645
throw new VersionMismatchException();
4746
}
4847

@@ -60,15 +59,13 @@ public function dump(): string
6059
*/
6160
private function writePassFile(): string
6261
{
63-
$config = $this->getConfig();
64-
6562
$passwordParts = [
66-
empty($config['host']) ? 'localhost' : $config['host'],
67-
empty($config['port']) ? '5432' : $config['port'],
63+
empty($this->config['host']) ? 'localhost' : $this->config['host'],
64+
empty($this->config['port']) ? '5432' : $this->config['port'],
6865
// Database
6966
'*',
70-
$config['username'],
71-
$config['password'],
67+
$this->config['username'],
68+
$this->config['password'],
7269
];
7370

7471
// Escape colon and backslash characters in entries.

src/Sql/SqlBase.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ abstract class SqlBase
1212
*/
1313
protected string $command;
1414

15-
/**
16-
* @var array The config array from the connection object
17-
*/
18-
protected array $config;
19-
2015
/**
2116
* @var bool Indicated if only data should be exported or not
2217
*/
@@ -30,17 +25,8 @@ abstract class SqlBase
3025
/**
3126
* @param array $config The config array from the connection object
3227
*/
33-
public function __construct(array $config)
34-
{
35-
$this->config = $config;
36-
}
37-
38-
/**
39-
* @return array
40-
*/
41-
public function getConfig(): array
28+
public function __construct(public readonly array $config)
4229
{
43-
return $this->config;
4430
}
4531

4632
/**
@@ -77,7 +63,7 @@ public function setIo(ConsoleIo $io): void
7763
*/
7864
protected function checkBinary(string $command): bool
7965
{
80-
$windows = strpos(PHP_OS, 'WIN') === 0;
66+
$windows = str_starts_with(PHP_OS, 'WIN');
8167
$test = $windows ? 'where' : 'command -v';
8268

8369
return is_executable(trim(shell_exec("$test $command")));

src/Sql/Sqlite.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ public function dump(): string
5454
*/
5555
private function getSchema(): string
5656
{
57-
$config = $this->getConfig();
58-
5957
$schemaCommand = [
6058
$this->command,
61-
$config['database'],
59+
$this->config['database'],
6260
'.schema',
6361
];
6462

@@ -79,11 +77,9 @@ private function getSchema(): string
7977
*/
8078
private function getDump(): string
8179
{
82-
$config = $this->getConfig();
83-
8480
$schemaCommand = [
8581
$this->command,
86-
$config['database'],
82+
$this->config['database'],
8783
'.dump',
8884
];
8985

0 commit comments

Comments
 (0)