From 7a11a7714ea8eea29044f015d64d31e20fcedb13 Mon Sep 17 00:00:00 2001 From: Kader Ibrahim S Date: Tue, 24 Oct 2023 16:10:24 +0400 Subject: [PATCH] Uses different objects of the CompatCheck class based on plugin basename. --- packages/php/compat-checker/src/Checker.php | 7 ++++--- packages/php/compat-checker/src/Checks/CompatCheck.php | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/php/compat-checker/src/Checker.php b/packages/php/compat-checker/src/Checker.php index 68d52710..26177f27 100644 --- a/packages/php/compat-checker/src/Checker.php +++ b/packages/php/compat-checker/src/Checker.php @@ -71,14 +71,15 @@ public function get_plugin_data( $plugin_file, $file_version ) { * @return bool */ public function is_compatible( $plugin_file_path, $file_version ) { - $checks = array( + $checks = array( WPCompatibility::class, WCCompatibility::class, ); - $plugin_data = $this->get_plugin_data( $plugin_file_path, $file_version ); + $plugin_data = $this->get_plugin_data( $plugin_file_path, $file_version ); + $plugin_basename = plugin_basename( $plugin_file_path ); foreach ( $checks as $compatibility ) { - if ( ! $compatibility::instance()->is_compatible( $plugin_data ) ) { + if ( ! $compatibility::instance( $plugin_basename )->is_compatible( $plugin_data ) ) { return false; } } diff --git a/packages/php/compat-checker/src/Checks/CompatCheck.php b/packages/php/compat-checker/src/Checks/CompatCheck.php index 67d48cba..9e01f037 100644 --- a/packages/php/compat-checker/src/Checks/CompatCheck.php +++ b/packages/php/compat-checker/src/Checks/CompatCheck.php @@ -47,15 +47,17 @@ abstract protected function run_checks(); /** * Get the instance of the CompatCheck object. * + * @param string $plugin_basename The basename of the plugin. + * * @return CompatCheck */ - public static function instance() { + public static function instance( $plugin_basename ) { $class = get_called_class(); - if ( ! isset( self::$instances[ $class ] ) ) { - self::$instances[ $class ] = new $class(); + if ( ! isset( self::$instances[ $class ][ $plugin_basename ] ) ) { + self::$instances[ $class ][ $plugin_basename ] = new $class(); } - return self::$instances[ $class ]; + return self::$instances[ $class ][ $plugin_basename ]; } /**