Skip to content

Commit

Permalink
Fix static analisys errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianBustamante committed Aug 8, 2024
1 parent 41b8fbb commit 60bc877
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ public function generate_theme_install_command( string $theme_slug, bool $is_man
* @param array $expected_plugins A list of plugins that will be checked.
* @param array $expected_themes A list of themes that will be checked.
*
* @return bool|WP_Error
* @return array
*/
public function generate_verify_plugin_installation_commands( array $expected_plugins, array $expected_themes ) {
$expected_plugins = \array_filter( $expected_plugins );

if ( empty( $expected_plugins ) ) {
return true;
return array();
}

$plugin_commands = \array_map(
Expand All @@ -147,7 +147,7 @@ public function generate_verify_plugin_installation_commands( array $expected_pl
);

$theme_commands = \array_map(
fn( $plugin_slug ) => '--skip-themes --skip-plugins theme get ' . $plugin_slug . ' --field=status',
fn( $theme_slug ) => '--skip-themes --skip-plugins theme get ' . $theme_slug . ' --field=status',
$expected_themes
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function install_marketplace_software() {
return $wpcom_marketplace_software;
}

// @phan-suppress-next-line PhanTypeSuspiciousNonTraversableForeach -- $wpcom_marketplace_software is an array.
foreach ( $wpcom_marketplace_software as $software ) {
$product_software = Marketplace_Software_Factory::get_product_software( $software );
if ( is_wp_error( $product_software ) ) {
Expand All @@ -35,9 +36,9 @@ public function install_marketplace_software() {
}

$installer = Marketplace_Software_Factory::get_product_installer( $product_software );
$installation = $installer->install( $product_software );
$installation = $installer->install();
if ( is_wp_error( $installation ) ) {
WPCOMSH_Log::unsafe_direct_log( $installation->get_error_message(), $installation->get_error_data() );
WPCOMSH_Log::unsafe_direct_log( $installation->get_error_message(), $installer->get_results() );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@ class Marketplace_Plugin_Installer extends Marketplace_Product_Installer {
* @return WP_Error|bool
*/
public function install() {
// 1. Install the plugin dependencies.
$install_dependencies = $this->install_dependencies();
if ( is_wp_error( $install_dependencies ) ) {
return $install_dependencies;
}

// 2. Get the list of plugins to skip when installing the plugin.
$skip_plugins = $this->get_skip_plugins();
if ( is_wp_error( $skip_plugins ) ) {
return $skip_plugins;
}

// 3. Get the list of themes to skip when installing the plugin.
$skip_themes = $this->get_skip_themes();
if ( is_wp_error( $skip_themes ) ) {
return $skip_themes;
}

// 4. Generate and run the plugin installation command.
$plugin_install_commands = $this->command_helper->generate_plugin_install_commands(
$this->product_software->get_product_slug_or_url(),
$this->product_software->is_managed(),
Expand All @@ -46,7 +50,11 @@ public function install() {
}
}

$expected_plugins = array_filter( array( ...$this->product_software->get_plugin_dependencies(), $this->product_software->get_software_slug() ) );
// 5. Verify the plugin installation.
$expected_plugins = array_filter(
array( ...$this->product_software->get_plugin_dependencies(), $this->product_software->get_software_slug() )
);

$verify_plugin_installation_commands = $this->command_helper->generate_verify_plugin_installation_commands( $expected_plugins, $this->product_software->get_theme_dependencies() );

foreach ( $verify_plugin_installation_commands as $command ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public function __construct( Marketplace_Command_Helper $command_helper, Marketp
$this->product_software = $product_software;
}

/**
* Get the list of command results.
*
* @return array
*/
public function get_results() {
return $this->results;
}

/**
* Install the product.
*
Expand All @@ -58,7 +67,7 @@ abstract public function install();
* To make sure that there are no 3rd party plugins that might interfere in the installation process,
* this method gets the list of installed plugins and filters out the ones that are dependencies of the product.
*
* @return array
* @return array|WP_Error
*/
protected function get_skip_plugins() {
if ( empty( $this->product_software->get_plugin_dependencies() ) ) {
Expand All @@ -85,7 +94,7 @@ function ( $plugin_name ) use ( $plugin_dependencies ) {
* To make sure that there are no 3rd party themes that might interfere in the installation process,
* this method gets the list of installed themes and filters out the ones that are dependencies of the product.
*
* @return array
* @return array|WP_Error
*/
protected function get_skip_themes() {
if ( empty( $this->product_software->get_theme_dependencies() ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ public function install() {
return new WP_Error( 'invalid_product_software', 'Invalid product software.' );
}

// 1. Install the theme dependencies.
$install_dependencies = $this->install_dependencies();
if ( is_wp_error( $install_dependencies ) ) {
return $install_dependencies;
}

// 2. Get the list of plugins to skip when installing the theme.
$skip_plugins = $this->get_skip_plugins();
if ( is_wp_error( $skip_plugins ) ) {
return $skip_plugins;
}

// 3. Get the list of themes to skip when installing the theme.
$skip_themes = $this->get_skip_themes();
if ( is_wp_error( $skip_themes ) ) {
return $skip_themes;
}

// 4. Generate and run the theme installation command.
$theme_install_command = $this->command_helper->generate_theme_install_command(
$this->product_software->get_theme_slug(),
$this->product_software->is_managed(),
Expand All @@ -48,6 +52,7 @@ public function install() {
return $theme_install;
}

// 5. Verify the theme installation.
$verify_theme_installation_command = $this->command_helper->generate_verify_theme_installation_command( $this->product_software->get_theme_slug() );
$verify_theme_installation = $this->run_command( $verify_theme_installation_command );
if ( is_wp_error( $verify_theme_installation ) ) {
Expand Down

0 comments on commit 60bc877

Please sign in to comment.