Skip to content

Commit

Permalink
Use different objects of the CompatCheck class based on plugin basena…
Browse files Browse the repository at this point in the history
…me (#87)
  • Loading branch information
ibndawood authored Oct 26, 2023
2 parents bb3d2f2 + 7a11a77 commit c1338c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions packages/php/compat-checker/src/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
10 changes: 6 additions & 4 deletions packages/php/compat-checker/src/Checks/CompatCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
}

/**
Expand Down

0 comments on commit c1338c4

Please sign in to comment.