Skip to content

Commit 0da671a

Browse files
author
Gabriel Simmer
committed
Fix up coding standards.
Fix up coding standards. Fix up coding standards.
1 parent 11c22e5 commit 0da671a

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

src/DatabaseJanitor.php

+24-12
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class DatabaseJanitor {
2929
* DatabaseJanitor constructor.
3030
*/
3131
public function __construct($database, $user, $host, $password, $dumpOptions) {
32-
$this->database = $database;
33-
$this->user = $user;
34-
$this->host = $host;
35-
$this->password = $password;
32+
$this->database = $database;
33+
$this->user = $user;
34+
$this->host = $host;
35+
$this->password = $password;
3636
$this->dumpOptions = $dumpOptions;
3737
try {
3838
$this->connection = new \PDO('mysql:host=' . $this->host . ';dbname=' . $this->database, $this->user, $this->password, [
@@ -57,22 +57,22 @@ public function dump($host = FALSE, $output = FALSE, $trim = FALSE) {
5757

5858
if ($host) {
5959
$this->database = $host->database;
60-
$this->user = $host->user;
61-
$this->host = $host->host;
60+
$this->user = $host->user;
61+
$this->host = $host->host;
6262
$this->password = $host->password;
6363
}
6464

6565
$dumpSettings = [
66-
'add-locks' => FALSE,
66+
'add-locks' => FALSE,
6767
'exclude-tables' => $this->dumpOptions['excluded_tables'] ?? [],
6868
'no-data' => $this->dumpOptions['no-data'] ?? [],
6969
];
7070
try {
7171
$dump = new Mysqldump('mysql:host=' . $this->host . ';dbname=' . $this->database, $this->user, $this->password, $dumpSettings);
7272
if ($trim) {
73-
$dump->setTransformTableNameHook(function ($table_name, $reset) {
74-
return $this->rename_table($table_name, $reset);
75-
});
73+
$dump->setTransformTableNameHook(function ($table_name, $reset) {
74+
return $this->renameTable($table_name, $reset);
75+
});
7676
}
7777
$dump->setTransformColumnValueHook(function ($table_name, $col_name, $col_value) {
7878
return $this->sanitize($table_name, $col_name, $col_value, $this->dumpOptions);
@@ -101,7 +101,7 @@ public function dump($host = FALSE, $output = FALSE, $trim = FALSE) {
101101
* @return string
102102
* New col value.
103103
*/
104-
public function sanitize($table_name, $col_name, $col_value, $options) {
104+
public function sanitize($table_name, $col_name, $col_value, array $options) {
105105
if (isset($options['sanitize_tables'])) {
106106
foreach ($options['sanitize_tables'] as $table => $val) {
107107
if ($table == $table_name) {
@@ -201,7 +201,18 @@ private function getPrimaryKey($table) {
201201
return $primary_key;
202202
}
203203

204-
public function rename_table($table_name, $reset) {
204+
/**
205+
* Rename table function hook to manipulate during dump.
206+
*
207+
* @param string $table_name
208+
* Current table name.
209+
* @param bool $reset
210+
* Whether to reset table name back to original (if altered was passed).
211+
*
212+
* @return string
213+
* Returns the altered table name.
214+
*/
215+
public function renameTable($table_name, $reset) {
205216
if (in_array($table_name, $this->dumpOptions['trim_tables'])) {
206217
return 'janitor_' . $table_name;
207218
}
@@ -210,4 +221,5 @@ public function rename_table($table_name, $reset) {
210221
}
211222
return $table_name;
212223
}
224+
213225
}

src/DatabaseJanitorCommand.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
require __DIR__ . '/../vendor/autoload.php';
1313
require 'DatabaseJanitor.php';
14+
1415
/**
1516
* Class DatabaseJanitorCommand.
1617
*
@@ -19,9 +20,13 @@
1920
class DatabaseJanitorCommand extends Command {
2021

2122
private $host;
23+
2224
private $username;
25+
2326
private $password;
27+
2428
private $database;
29+
2530
private $configuration;
2631

2732
private $janitor;
@@ -73,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
7378
// "default" until I hear otherwise.
7479
require_once $input->getOption('drupal');
7580
if ($databases['default'] && is_array($databases['default'])) {
76-
fwrite(STDERR, "Loading Drupal configuration. \n");
81+
fwrite(STDERR, "Loading Drupal configuration. \n");
7782
$db_array = $databases['default']['default'];
7883
$this->host = $db_array['host'];
7984
$this->username = $db_array['username'];
@@ -87,7 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
8792

8893
if (!$input->getOption('trim')) {
8994
fwrite(STDERR, "Dumping database. \n");
90-
$dumpresult = $this->janitor->dump(null, null, FALSE);
95+
$dumpresult = $this->janitor->dump(NULL, NULL, FALSE);
9196
if (!$dumpresult) {
9297
$output->writeln("Something went horribly wrong.");
9398
}
@@ -106,7 +111,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
106111
$this->database, $this->username, $this->host, $this->password, $this->configuration
107112
);
108113
fwrite(STDERR, "Dumping database.\n");
109-
$dumpresult = $this->janitor->dump(null, null, TRUE);
114+
$dumpresult = $this->janitor->dump(NULL, NULL, TRUE);
110115
if (!$dumpresult) {
111116
printf("Something went horribly wrong.");
112117
}

0 commit comments

Comments
 (0)