Skip to content

Commit 394f223

Browse files
Remove Base, use static methods
1 parent dc1d3db commit 394f223

File tree

5 files changed

+10
-22
lines changed

5 files changed

+10
-22
lines changed

src/Export.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
use WP_CLI;
77
use WP_SQLite_Translator;
88

9-
class Export extends Base {
9+
class Export {
1010

1111
protected $translator;
1212
protected $args = array();
1313
protected $is_stdout = false;
1414

1515
public function __construct() {
16-
$this->load_dependencies();
16+
SQLiteDatabaseIntegrationLoader::load_plugin();
1717
$this->translator = new WP_SQLite_Translator();
1818
}
1919

src/Import.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
use WP_CLI;
77
use WP_SQLite_Translator;
88

9-
class Import extends Base {
9+
class Import {
1010

1111
protected $translator;
1212
protected $args;
1313

1414
public function __construct() {
15-
$this->load_dependencies();
15+
SQLiteDatabaseIntegrationLoader::load_plugin();
1616
$this->translator = new WP_SQLite_Translator();
1717
}
1818

src/Base.php renamed to src/SQLiteDatabaseIntegrationLoader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
use WP_CLI;
55

6-
class Base {
6+
final class SQLiteDatabaseIntegrationLoader {
77

88
/**
99
* Get the version of the SQLite integration plugin if it is installed
1010
* and activated.
1111
*
1212
* @return false|string The version of the SQLite integration plugin or false if not found/activated.
1313
*/
14-
public static function get_sqlite_plugin_version() {
14+
public static function get_plugin_version() {
1515
// Check if there is a db.php file in the wp-content directory.
1616
if ( ! file_exists( ABSPATH . '/wp-content/db.php' ) ) {
1717
return false;
@@ -62,13 +62,13 @@ protected static function get_plugin_directory() {
6262
* @return void
6363
* @throws WP_CLI\ExitException
6464
*/
65-
protected function load_dependencies() {
65+
public static function load_plugin() {
6666
$plugin_directory = self::get_plugin_directory();
6767
if ( ! $plugin_directory ) {
6868
WP_CLI::error( 'Could not locate the SQLite integration plugin.' );
6969
}
7070

71-
$sqlite_plugin_version = self::get_sqlite_plugin_version();
71+
$sqlite_plugin_version = self::get_plugin_version();
7272
if ( ! $sqlite_plugin_version ) {
7373
WP_CLI::error( 'Could not determine the version of the SQLite integration plugin.' );
7474
}

src/SQLite_Command.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ public function import( $args, $assoc_args ) {
2929
WP_CLI::error( 'Please provide a file to import.' );
3030
}
3131

32-
if ( ! Import::get_sqlite_plugin_version() ) {
33-
WP_CLI::error( 'The SQLite integration plugin is not installed or activated.' );
34-
}
35-
3632
$import = new Import();
3733
$import->run( $args[0], $assoc_args );
3834
}
@@ -79,10 +75,6 @@ public function import( $args, $assoc_args ) {
7975
* @when before_wp_load
8076
*/
8177
public function export( $args, $assoc_args ) {
82-
if ( ! Export::get_sqlite_plugin_version() ) {
83-
WP_CLI::error( 'The SQLite integration plugin is not installed or activated.' );
84-
}
85-
8678
$is_porcelain = isset( $assoc_args['porcelain'] );
8779

8880
if ( ! $is_porcelain ) {
@@ -139,10 +131,6 @@ public function export( $args, $assoc_args ) {
139131
* @when before_wp_load
140132
*/
141133
public function tables( $args, $assoc_args ) {
142-
if ( ! Tables::get_sqlite_plugin_version() ) {
143-
WP_CLI::error( 'The SQLite integration plugin is not installed or activated.' );
144-
}
145-
146134
$tables = new Tables();
147135
$tables->run( $assoc_args );
148136
}

src/Tables.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
use PDO;
77
use WP_SQLite_Translator;
88

9-
class Tables extends Base {
9+
class Tables {
1010

1111
protected $translator;
1212

1313
public function __construct() {
14-
$this->load_dependencies();
14+
SQLiteDatabaseIntegrationLoader::load_plugin();
1515
$this->translator = new WP_SQLite_Translator();
1616
}
1717

0 commit comments

Comments
 (0)