Skip to content

Commit d399adf

Browse files
author
Chris Wiegman
committed
Address coding style issues from code review
1 parent 579fb1a commit d399adf

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/DB_Command.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class DB_Command extends WP_CLI_Command {
4949
*/
5050
public function create( $_, $assoc_args ) {
5151

52-
self::run_query( self::get_create_query(), self::get_dbuser_dbpass_args( $assoc_args ) );
52+
$this->run_query( self::get_create_query(), self::get_dbuser_dbpass_args( $assoc_args ) );
5353

5454
WP_CLI::success( 'Database created.' );
5555
}
@@ -80,7 +80,7 @@ public function create( $_, $assoc_args ) {
8080
public function drop( $_, $assoc_args ) {
8181
WP_CLI::confirm( "Are you sure you want to drop the '" . DB_NAME . "' database?", $assoc_args );
8282

83-
self::run_query( sprintf( 'DROP DATABASE `%s`', DB_NAME ), self::get_dbuser_dbpass_args( $assoc_args ) );
83+
$this->run_query( sprintf( 'DROP DATABASE `%s`', DB_NAME ), self::get_dbuser_dbpass_args( $assoc_args ) );
8484

8585
WP_CLI::success( 'Database dropped.' );
8686
}
@@ -113,8 +113,8 @@ public function reset( $_, $assoc_args ) {
113113

114114
$mysql_args = self::get_dbuser_dbpass_args( $assoc_args );
115115

116-
self::run_query( sprintf( 'DROP DATABASE IF EXISTS `%s`', DB_NAME ), $mysql_args );
117-
self::run_query( self::get_create_query(), $mysql_args );
116+
$this->run_query( sprintf( 'DROP DATABASE IF EXISTS `%s`', DB_NAME ), $mysql_args );
117+
$this->run_query( self::get_create_query(), $mysql_args );
118118

119119
WP_CLI::success( 'Database reset.' );
120120
}
@@ -164,7 +164,7 @@ public function clean( $_, $assoc_args ) {
164164
);
165165

166166
foreach ( $tables as $table ) {
167-
self::run_query(
167+
$this->run_query(
168168
sprintf(
169169
'DROP TABLE IF EXISTS `%s`.`%s`',
170170
DB_NAME,
@@ -199,7 +199,7 @@ public function clean( $_, $assoc_args ) {
199199
* : Extra arguments to pass to mysqlcheck. [Refer to mysqlcheck docs](https://dev.mysql.com/doc/en/mysqlcheck.html).
200200
*
201201
* [--defaults]
202-
* : Removes the "--no-defaults" flag normally passed to MySQL allowing it to use the default my.cnf or one specified with the MYSQL_HOME environment variable.
202+
* : Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
203203
*
204204
* ## EXAMPLES
205205
*
@@ -208,7 +208,7 @@ public function clean( $_, $assoc_args ) {
208208
*/
209209
public function check( $_, $assoc_args ) {
210210

211-
$command = sprintf( '/usr/bin/env mysqlcheck%s %s', self::get_no_defaults( $assoc_args ), '%s' );
211+
$command = sprintf( '/usr/bin/env mysqlcheck%s %s', $this->get_defaults_flag_string( $assoc_args ), '%s' );
212212
WP_CLI::debug( "Running shell command: {$command}", 'db' );
213213

214214
$assoc_args['check'] = true;
@@ -242,7 +242,7 @@ public function check( $_, $assoc_args ) {
242242
* : Extra arguments to pass to mysqlcheck. [Refer to mysqlcheck docs](https://dev.mysql.com/doc/en/mysqlcheck.html).
243243
*
244244
* [--defaults]
245-
* : Removes the "--no-defaults" flag normally passed to MySQL allowing it to use the default my.cnf or one specified with the MYSQL_HOME environment variable.
245+
* : Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
246246
*
247247
* ## EXAMPLES
248248
*
@@ -251,8 +251,8 @@ public function check( $_, $assoc_args ) {
251251
*/
252252
public function optimize( $_, $assoc_args ) {
253253

254-
$command = sprintf( '/usr/bin/env mysqlcheck%s %s', self::get_no_defaults( $assoc_args ), '%s' );
255-
WP_CLI::debug( $command, 'db' );
254+
$command = sprintf( '/usr/bin/env mysqlcheck%s %s', $this->get_defaults_flag_string( $assoc_args ), '%s' );
255+
WP_CLI::debug( "Running shell command: {$command}", 'db' );
256256

257257
$assoc_args['optimize'] = true;
258258
self::run(
@@ -285,7 +285,7 @@ public function optimize( $_, $assoc_args ) {
285285
* : Extra arguments to pass to mysqlcheck. [Refer to mysqlcheck docs](https://dev.mysql.com/doc/en/mysqlcheck.html).
286286
*
287287
* [--defaults]
288-
* : Removes the "--no-defaults" flag normally passed to MySQL allowing it to use the default my.cnf or one specified with the MYSQL_HOME environment variable.
288+
* : Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
289289
*
290290
* ## EXAMPLES
291291
*
@@ -294,8 +294,8 @@ public function optimize( $_, $assoc_args ) {
294294
*/
295295
public function repair( $_, $assoc_args ) {
296296

297-
$command = sprintf( '/usr/bin/env mysqlcheck%s %s', self::get_no_defaults( $assoc_args ), '%s' );
298-
WP_CLI::debug( $command, 'db' );
297+
$command = sprintf( '/usr/bin/env mysqlcheck%s %s', $this->get_defaults_flag_string( $assoc_args ), '%s' );
298+
WP_CLI::debug( "Running shell command: {$command}", 'db' );
299299

300300
$assoc_args['repair'] = true;
301301
self::run(
@@ -327,7 +327,7 @@ public function repair( $_, $assoc_args ) {
327327
* : Extra arguments to pass to mysql. [Refer to mysql docs](https://dev.mysql.com/doc/en/mysql-command-options.html).
328328
*
329329
* [--defaults]
330-
* : Removes the "--no-defaults" flag normally passed to MySQL allowing it to use the default my.cnf or one specified with the MYSQL_HOME environment variable.
330+
* : Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
331331
*
332332
* ## EXAMPLES
333333
*
@@ -339,8 +339,8 @@ public function repair( $_, $assoc_args ) {
339339
*/
340340
public function cli( $args, $assoc_args ) {
341341

342-
$command = sprintf( '/usr/bin/env mysql%s --no-auto-rehash', self::get_no_defaults( $assoc_args ) );
343-
WP_CLI::debug( $command, 'db' );
342+
$command = sprintf( '/usr/bin/env mysql%s --no-auto-rehash', $this->get_defaults_flag_string( $assoc_args ) );
343+
WP_CLI::debug( "Running shell command: {$command}", 'db' );
344344

345345
if ( ! isset( $assoc_args['database'] ) ) {
346346
$assoc_args['database'] = DB_NAME;
@@ -370,7 +370,7 @@ public function cli( $args, $assoc_args ) {
370370
* : Extra arguments to pass to mysql. [Refer to mysql docs](https://dev.mysql.com/doc/en/mysql-command-options.html).
371371
*
372372
* [--defaults]
373-
* : Removes the "--no-defaults" flag normally passed to MySQL allowing it to use the default my.cnf or one specified with the MYSQL_HOME environment variable.
373+
* : Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
374374
*
375375
* ## EXAMPLES
376376
*
@@ -404,8 +404,8 @@ public function cli( $args, $assoc_args ) {
404404
*/
405405
public function query( $args, $assoc_args ) {
406406

407-
$command = sprintf( '/usr/bin/env mysql%s --no-auto-rehash', self::get_no_defaults( $assoc_args ) );
408-
WP_CLI::debug( $command, 'db' );
407+
$command = sprintf( '/usr/bin/env mysql%s --no-auto-rehash', $this->get_defaults_flag_string( $assoc_args ) );
408+
WP_CLI::debug( "Running shell command: {$command}", 'db' );
409409

410410
$assoc_args['database'] = DB_NAME;
411411

@@ -448,7 +448,7 @@ public function query( $args, $assoc_args ) {
448448
* : Output filename for the exported database.
449449
*
450450
* [--defaults]
451-
* : Removes the "--no-defaults" flag normally passed to MySQL allowing it to use the default my.cnf or one specified with the MYSQL_HOME environment variable.
451+
* : Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
452452
*
453453
* ## EXAMPLES
454454
*
@@ -522,8 +522,8 @@ public function export( $args, $assoc_args ) {
522522

523523
$support_column_statistics = exec( 'mysqldump --help | grep "column-statistics"' );
524524

525-
$initial_command = sprintf( '/usr/bin/env mysqldump%s ', self::get_no_defaults( $assoc_args ) );
526-
WP_CLI::debug( $initial_command, 'db' );
525+
$initial_command = sprintf( '/usr/bin/env mysqldump%s ', $this->get_defaults_flag_string( $assoc_args ) );
526+
WP_CLI::debug( "Running initial shell command: {$initial_command}", 'db' );
527527

528528
if ( $support_column_statistics ) {
529529
$command = $initial_command . '--skip-column-statistics %s';
@@ -594,7 +594,7 @@ public function export( $args, $assoc_args ) {
594594
* : When using an SQL file, do not include speed optimization such as disabling auto-commit and key checks.
595595
*
596596
* [--defaults]
597-
* : Removes the "--no-defaults" flag normally passed to MySQL allowing it to use the default my.cnf or one specified with the MYSQL_HOME environment variable.
597+
* : Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
598598
*
599599
* ## EXAMPLES
600600
*
@@ -630,8 +630,8 @@ public function import( $args, $assoc_args ) {
630630
// Check if any mysql option pass.
631631
$mysql_args = array_merge( $mysql_args, self::get_mysql_args( $assoc_args ) );
632632

633-
$command = sprintf( '/usr/bin/env mysql%s --no-auto-rehash', self::get_no_defaults( $assoc_args ) );
634-
WP_CLI::debug( $command, 'db' );
633+
$command = sprintf( '/usr/bin/env mysql%s --no-auto-rehash', $this->get_defaults_flag_string( $assoc_args ) );
634+
WP_CLI::debug( "Running shell command: {$command}", 'db' );
635635

636636
self::run( $command, $mysql_args );
637637

@@ -1417,8 +1417,8 @@ private static function get_create_query() {
14171417
return $create_query;
14181418
}
14191419

1420-
private static function run_query( $query, $assoc_args = array() ) {
1421-
self::run( sprintf( '/usr/bin/env mysql%s --no-auto-rehash', self::get_no_defaults( $assoc_args ) ), array_merge( $assoc_args, array( 'execute' => $query ) ) );
1420+
protected function run_query( $query, $assoc_args = array() ) {
1421+
self::run( sprintf( '/usr/bin/env mysql%s --no-auto-rehash', $this->get_defaults_flag_string( $assoc_args ) ), array_merge( $assoc_args, array( 'execute' => $query ) ) );
14221422
}
14231423

14241424
private static function run( $cmd, $assoc_args = array(), $descriptors = null ) {
@@ -1686,7 +1686,7 @@ private static function get_mysql_args( $assoc_args ) {
16861686
* @param array $assoc_args Associative args array.
16871687
* @return string Either the '--no-defaults' flag for use in the command or an empty string.
16881688
*/
1689-
private static function get_defaults_flag_string( &$assoc_args ) {
1689+
protected function get_defaults_flag_string( &$assoc_args ) {
16901690

16911691
if ( true === Utils\get_flag_value( $assoc_args, 'defaults' ) ) {
16921692
unset( $assoc_args['defaults'] );

0 commit comments

Comments
 (0)