From 2b6d92e786d59336ce0927d1694786657662412c Mon Sep 17 00:00:00 2001 From: Justin Palmer <228780+layoutd@users.noreply.github.com> Date: Mon, 13 Nov 2023 15:53:12 +0100 Subject: [PATCH] Remove leftover VersionUtil class --- .../FeaturesServiceProvider.php | 4 - .../woocommerce/src/Utilities/VersionUtil.php | 75 ------------------- .../php/src/Utilities/VersionUtilTest.php | 49 ------------ 3 files changed, 128 deletions(-) delete mode 100644 plugins/woocommerce/src/Utilities/VersionUtil.php delete mode 100644 plugins/woocommerce/tests/php/src/Utilities/VersionUtilTest.php diff --git a/plugins/woocommerce/src/Internal/DependencyManagement/ServiceProviders/FeaturesServiceProvider.php b/plugins/woocommerce/src/Internal/DependencyManagement/ServiceProviders/FeaturesServiceProvider.php index 2a7f8ac80a4..c860081270a 100644 --- a/plugins/woocommerce/src/Internal/DependencyManagement/ServiceProviders/FeaturesServiceProvider.php +++ b/plugins/woocommerce/src/Internal/DependencyManagement/ServiceProviders/FeaturesServiceProvider.php @@ -6,7 +6,6 @@ use Automattic\WooCommerce\Internal\DependencyManagement\AbstractServiceProvider use Automattic\WooCommerce\Internal\Features\FeaturesController; use Automattic\WooCommerce\Proxies\LegacyProxy; use Automattic\WooCommerce\Utilities\PluginUtil; -use Automattic\WooCommerce\Utilities\VersionUtil; /** * Service provider for the features enabling/disabling/compatibility engine. @@ -20,7 +19,6 @@ class FeaturesServiceProvider extends AbstractServiceProvider { */ protected $provides = array( FeaturesController::class, - VersionUtil::class, ); /** @@ -29,7 +27,5 @@ class FeaturesServiceProvider extends AbstractServiceProvider { public function register() { $this->share( FeaturesController::class ) ->addArguments( array( LegacyProxy::class, PluginUtil::class ) ); - $this->share( VersionUtil::class ) - ->addArguments( array( LegacyProxy::class ) ); } } diff --git a/plugins/woocommerce/src/Utilities/VersionUtil.php b/plugins/woocommerce/src/Utilities/VersionUtil.php deleted file mode 100644 index 0a793304918..00000000000 --- a/plugins/woocommerce/src/Utilities/VersionUtil.php +++ /dev/null @@ -1,75 +0,0 @@ -proxy = $proxy; - } - - /** - * Check if the current WordPress version is at least the given version. - * - * @since x.x.x - * - * @param string $version The version to check against. - * @param bool $use_unmodified_version Whether to use the unmodified WordPress version from - * the wp-includes/version.php file. - * - * @return bool - */ - public function wp_version_at_least( string $version, bool $use_unmodified_version = false ): bool { - if ( $use_unmodified_version ) { - $wp_version = $this->get_unmodified_wp_version(); - } else { - $wp_version = $this->proxy->get_global( 'wp_version' ); - } - - return version_compare( $wp_version, $version, '>=' ); - } - - /** - * Get the unmodified WordPress version from the wp-includes/version.php file. - * - * @since x.x.x - * @return string - */ - private function get_unmodified_wp_version() { - $abspath = Constants::get_constant( 'ABSPATH' ); - $wpinc = Constants::get_constant( 'WPINC' ); - - include "{$abspath}{$wpinc}/version.php"; - - // Possibly strip the hyphen and any text after it from the version. - $hyphen_position = strpos( $wp_version, '-' ); - if ( false !== $hyphen_position ) { - $wp_version = substr( $wp_version, 0, $hyphen_position ); - } - - return $wp_version; - } -} diff --git a/plugins/woocommerce/tests/php/src/Utilities/VersionUtilTest.php b/plugins/woocommerce/tests/php/src/Utilities/VersionUtilTest.php deleted file mode 100644 index 1a9477c94db..00000000000 --- a/plugins/woocommerce/tests/php/src/Utilities/VersionUtilTest.php +++ /dev/null @@ -1,49 +0,0 @@ -reset_container_resolutions(); - $this->reset_legacy_proxy_mocks(); - - $this->sut = $this->get_instance_of( VersionUtil::class ); - } - - public function test_wp_version_at_least() { - // Store the current wp_version. - $original_wp_version = $GLOBALS['wp_version']; - - // Set a fake wp_version to test. - $GLOBALS['wp_version'] = '5.6.0'; - - $this->assertFalse( $this->sut->wp_version_at_least( '5.6.1' ) ); - $this->assertFalse( $this->sut->wp_version_at_least( '6.3' ) ); - $this->assertTrue( $this->sut->wp_version_at_least( '5.6' ) ); - $this->assertTrue( $this->sut->wp_version_at_least( '5.5' ) ); - - // Restore the original wp_version. - $GLOBALS['wp_version'] = $original_wp_version; - } -}