From 54fa81ce06d0c268fbdb4d2f5b75f88f6f21a6bd Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Fri, 2 Feb 2024 15:04:18 +0530 Subject: [PATCH] remove more dead code --- includes/Classifai/Helpers.php | 46 ---------------- includes/Classifai/Providers/Provider.php | 55 ------------------- .../Classifai/Providers/Watson/Helpers.php | 2 - includes/Classifai/Services/Service.php | 1 - tests/Classifai/HelpersTest.php | 8 --- 5 files changed, 112 deletions(-) diff --git a/includes/Classifai/Helpers.php b/includes/Classifai/Helpers.php index e91ae6bb1..9e16003d3 100644 --- a/includes/Classifai/Helpers.php +++ b/includes/Classifai/Helpers.php @@ -24,52 +24,6 @@ function get_plugin() { return Plugin::get_instance(); } -/** - * Returns the ClassifAI plugin's stored settings in the WP options. - * - * @param string $service The service to get settings from, defaults to the ServiceManager class. - * @param string $provider The provider service name to get settings from, defaults to the first one found. - * @return array The array of ClassifAi settings. - */ -function get_plugin_settings( string $service = '', string $provider = '' ): array { - $services = Plugin::$instance->services; - if ( empty( $services ) || empty( $services['service_manager'] ) || ! $services['service_manager'] instanceof ServicesManager ) { - return []; - } - - /** @var ServicesManager $service_manager Instance of the services manager class. */ - $service_manager = $services['service_manager']; - if ( empty( $service ) ) { - return $service_manager->get_settings(); - } - - if ( ! isset( $service_manager->service_classes[ $service ] ) || ! $service_manager->service_classes[ $service ] instanceof Service ) { - return []; - } - - // Ensure we have at least one provider. - $providers = $service_manager->service_classes[ $service ]->provider_classes; - - if ( empty( $providers ) ) { - return []; - } - - // If we want settings for a specific provider, find the proper provider service. - if ( ! empty( $provider ) ) { - foreach ( $providers as $provider_class ) { - if ( $provider_class->provider_service_name === $provider ) { - return $provider_class->get_settings(); - } - } - - return []; - } - - /** @var Provider $provider An instance or extension of the provider abstract class. */ - $provider = $providers[0]; - return $provider->get_settings(); -} - /** * Overwrites the ClassifAI plugin's stored settings. Expected format is, * diff --git a/includes/Classifai/Providers/Provider.php b/includes/Classifai/Providers/Provider.php index 9fc732995..594a9b05a 100644 --- a/includes/Classifai/Providers/Provider.php +++ b/includes/Classifai/Providers/Provider.php @@ -14,16 +14,6 @@ abstract class Provider { */ const ID = ''; - /** - * @var string The display name for the provider, i.e. Azure - */ - public $provider_name; - - /** - * @var string $provider_service_name Formal name of the provider, i.e AI Vision, NLU, Rekongnition. - */ - public $provider_service_name; - /** * Feature instance. * @@ -31,51 +21,6 @@ abstract class Provider { */ protected $feature_instance = null; - /** - * @var array $features Array of features provided by this provider. - */ - protected $features = array(); - - - /** - * Provides the provider name. - * - * @return string - */ - public function get_provider_name(): string { - return $this->provider_name; - } - - /** - * Get provider features. - * - * @return array - */ - public function get_features(): array { - return $this->features; - } - - /** - * Default settings for Provider. - * - * @return array - */ - public function get_default_settings(): array { - return []; - } - - /** - * Common entry point for all REST endpoints for this provider. - * - * @param mixed $item The item we're processing. - * @param string $route_to_call The name of the route we're going to be processing. - * @param array $args Optional arguments to pass to the route. - * @return mixed - */ - public function rest_endpoint_callback( $item, string $route_to_call, array $args = [] ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed - return null; - } - /** * Format the result of most recent request. * diff --git a/includes/Classifai/Providers/Watson/Helpers.php b/includes/Classifai/Providers/Watson/Helpers.php index 86942787a..075f2afc6 100644 --- a/includes/Classifai/Providers/Watson/Helpers.php +++ b/includes/Classifai/Providers/Watson/Helpers.php @@ -7,8 +7,6 @@ use Classifai\Features\Classification; -use function Classifai\get_plugin_settings; - /** * Returns the currently configured Watson API URL. Lookup order is, * diff --git a/includes/Classifai/Services/Service.php b/includes/Classifai/Services/Service.php index 8738c13d3..2fe66e5a5 100644 --- a/includes/Classifai/Services/Service.php +++ b/includes/Classifai/Services/Service.php @@ -135,7 +135,6 @@ public function get_display_name(): string { * Render the start of a settings page. The rest is added by the providers */ public function render_settings_page() { - $active_tab = isset( $_GET['provider'] ) ? sanitize_text_field( wp_unslash( $_GET['provider'] ) ) : $active_tab; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $base_url = add_query_arg( array( 'page' => 'classifai', diff --git a/tests/Classifai/HelpersTest.php b/tests/Classifai/HelpersTest.php index 8b063cb9a..9e161cb77 100644 --- a/tests/Classifai/HelpersTest.php +++ b/tests/Classifai/HelpersTest.php @@ -42,14 +42,6 @@ function test_it_has_a_plugin_instance() { $this->assertInstanceOf( '\Classifai\Plugin', $actual ); } - function test_it_has_plugin_settings() { - $this->markTestSkipped(); - update_option( 'classifai_settings', [ 'post_types' => [ 'foo' ] ] ); - - $actual = get_plugin_settings(); - $this->assertEquals( [ 'foo' ], $actual['post_types'] ); - } - function test_it_has_default_supported_post_types() { $actual = get_supported_post_types(); $this->assertEquals( ['post'], $actual );