Skip to content

Commit

Permalink
Update commands name
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Dec 22, 2023
1 parent 33d5e39 commit ae12a78
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 189 deletions.
6 changes: 3 additions & 3 deletions cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use WordPress\Plugin_Check\Checker\CLI_Runner;
use WordPress\Plugin_Check\Plugin_Context;
use WordPress\Plugin_Check\CLI\Plugin_Check_Command;
use WordPress\Plugin_Check\CLI\Plugin_Check_Categories_Command;
use WordPress\Plugin_Check\CLI\Plugin_List_Check_Categories_Command;
use WordPress\Plugin_Check\CLI\Plugin_Check_Checks_Command;

if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) {
Expand All @@ -37,8 +37,8 @@
// Create the CLI command instance and add to WP CLI.
$plugin_command = new Plugin_Check_Command( $context );
WP_CLI::add_command( 'plugin', $plugin_command );
$plugin_categories_command = new Plugin_Check_Categories_Command( $context );
WP_CLI::add_command( 'plugin', $plugin_categories_command );
$plugin_list_check_categories_command = new Plugin_List_Check_Categories_Command( $context );
WP_CLI::add_command( 'plugin', $plugin_list_check_categories_command );
$plugin_checks_command = new Plugin_Check_Checks_Command( $context );
WP_CLI::add_command( 'plugin', $plugin_checks_command );

Expand Down
23 changes: 5 additions & 18 deletions includes/CLI/Plugin_Check_Checks_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace WordPress\Plugin_Check\CLI;

use WordPress\Plugin_Check\Checker\CLI_Checks_Runner;
use WordPress\Plugin_Check\Checker\Default_Check_Repository;
use WordPress\Plugin_Check\Plugin_Context;
use WordPress\Plugin_Check\Utilities\Plugin_Request_Utility;
use WP_CLI;
Expand Down Expand Up @@ -79,27 +79,14 @@ public function __construct( Plugin_Context $plugin_context ) {
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function check_checks( $args, $assoc_args ) {
// Get the Runner.
$runner = Plugin_Request_Utility::get_runner();

// Create the runner if not already initialized.
if ( is_null( $runner ) ) {
$runner = new CLI_Checks_Runner();
}

// Make sure we are using the correct runner instance.
if ( ! ( $runner instanceof CLI_Checks_Runner ) ) {
WP_CLI::error(
__( 'CLI Checks Runner was not initialized correctly.', 'plugin-check' )
);
}
$check_repo = new Default_Check_Repository();

Check warning on line 82 in includes/CLI/Plugin_Check_Checks_Command.php

View check run for this annotation

Codecov / codecov/patch

includes/CLI/Plugin_Check_Checks_Command.php#L81-L82

Added lines #L81 - L82 were not covered by tests

$all_checks = array();

Check warning on line 84 in includes/CLI/Plugin_Check_Checks_Command.php

View check run for this annotation

Codecov / codecov/patch

includes/CLI/Plugin_Check_Checks_Command.php#L84

Added line #L84 was not covered by tests

$checks_to_run = $runner->get_checks_to_run();
$checks_items = $check_repo->get_checks()->to_map();

Check warning on line 86 in includes/CLI/Plugin_Check_Checks_Command.php

View check run for this annotation

Codecov / codecov/patch

includes/CLI/Plugin_Check_Checks_Command.php#L86

Added line #L86 was not covered by tests

if ( is_array( $checks_to_run ) && count( $checks_to_run ) > 0 ) {
foreach ( $checks_to_run as $key => $check ) {
if ( is_array( $checks_items ) && count( $checks_items ) > 0 ) {
foreach ( $checks_items as $key => $check ) {
$item = array();

Check warning on line 90 in includes/CLI/Plugin_Check_Checks_Command.php

View check run for this annotation

Codecov / codecov/patch

includes/CLI/Plugin_Check_Checks_Command.php#L88-L90

Added lines #L88 - L90 were not covered by tests

$item['slug'] = $key;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Class WordPress\Plugin_Check\CLI\Plugin_Check_Categories_Command
* Class WordPress\Plugin_Check\CLI\Plugin_List_Check_Categories_Command
*
* @package plugin-check
*/
Expand All @@ -14,7 +14,7 @@
/**
* Plugin check categories command.
*/
final class Plugin_Check_Categories_Command {
final class Plugin_List_Check_Categories_Command {

/**
* Plugin context.
Expand Down Expand Up @@ -48,7 +48,7 @@ public function __construct( Plugin_Context $plugin_context ) {
}

/**
* Runs plugin check-categories.
* Runs plugin list-check-categories.
*
* ## OPTIONS
*
Expand All @@ -67,10 +67,10 @@ public function __construct( Plugin_Context $plugin_context ) {
*
* ## EXAMPLES
*
* wp plugin check-categories
* wp plugin check-categories --format=json
* wp plugin list-check-categories
* wp plugin list-check-categories --format=json
*
* @subcommand check-categories
* @subcommand list-check-categories
*
* @since n.e.x.t
*
Expand All @@ -80,19 +80,7 @@ public function __construct( Plugin_Context $plugin_context ) {
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function check_categories( $args, $assoc_args ) {
/*
* Bail early if the Plugin Checker is not activated.
*
* If the Plugin Checker is not activated, it will throw an error and
* CLI commands won't be usable.
*/
if ( is_plugin_inactive( $this->plugin_context->basename() ) ) {
WP_CLI::error(
__( 'Plugin Checker is not active.', 'plugin-check' )
);
}

public function list_check_categories( $args, $assoc_args ) {

Check warning on line 83 in includes/CLI/Plugin_List_Check_Categories_Command.php

View check run for this annotation

Codecov / codecov/patch

includes/CLI/Plugin_List_Check_Categories_Command.php#L83

Added line #L83 was not covered by tests
// Get options based on the CLI arguments.
$options = $this->get_options( $assoc_args );

Check warning on line 85 in includes/CLI/Plugin_List_Check_Categories_Command.php

View check run for this annotation

Codecov / codecov/patch

includes/CLI/Plugin_List_Check_Categories_Command.php#L85

Added line #L85 was not covered by tests

Expand Down
45 changes: 2 additions & 43 deletions includes/Checker/Abstract_Check_Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ abstract protected function get_categories_param();
* @since n.e.x.t
*/
final public function __construct() {
$this->initialized_early = ! did_action( 'muplugins_loaded' );
$this->register_checks();
$this->initialized_early = ! did_action( 'muplugins_loaded' );
$this->check_repository = new Default_Check_Repository();
$this->runtime_environment = new Runtime_Environment_Setup();
}

Expand Down Expand Up @@ -529,47 +529,6 @@ private function get_check_context() {
return new Check_Context( WP_PLUGIN_DIR . '/' . $this->get_plugin_basename() );
}

/**
* Registers Checks to the Check_Repository.
*
* @since n.e.x.t
*/
private function register_checks() {
$this->check_repository = new Default_Check_Repository();

/**
* Filters the available plugin check classes.
*
* @since n.e.x.t
*
* @param array $checks An array map of check slugs to Check instances.
*/
$checks = apply_filters(
'wp_plugin_check_checks',
array(
'i18n_usage' => new Checks\I18n_Usage_Check(),
'enqueued_scripts_size' => new Checks\Enqueued_Scripts_Size_Check(),
'code_obfuscation' => new Checks\Code_Obfuscation_Check(),
'file_type' => new Checks\File_Type_Check(),
'plugin_header_text_domain' => new Checks\Plugin_Header_Text_Domain_Check(),
'late_escaping' => new Checks\Late_Escaping_Check(),
'plugin_updater' => new Checks\Plugin_Updater_Check(),
'plugin_review_phpcs' => new Checks\Plugin_Review_PHPCS_Check(),
'performant_wp_query_params' => new Checks\Performant_WP_Query_Params_Check(),
'enqueued_scripts_in_footer' => new Checks\Enqueued_Scripts_In_Footer_Check(),
'plugin_readme' => new Checks\Plugin_Readme_Check(),
'enqueued_styles_scope' => new Checks\Enqueued_Styles_Scope_Check(),
'localhost' => new Checks\Localhost_Check(),
'no_unfiltered_uploads' => new Checks\No_Unfiltered_Uploads_Check(),
'trademarks' => new Checks\Trademarks_Check(),
)
);

foreach ( $checks as $slug => $check ) {
$this->check_repository->register_check( $slug, $check );
}
}

/**
* Sets the runtime environment setup.
*
Expand Down
106 changes: 0 additions & 106 deletions includes/Checker/CLI_Checks_Runner.php

This file was deleted.

48 changes: 48 additions & 0 deletions includes/Checker/Default_Check_Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ class Default_Check_Repository implements Check_Repository {
*/
protected $static_checks = array();

/**
* Initializes checks.
*
* @since n.e.x.t
*/
public function __construct() {
$this->register_default_checks();
}

/**
* Registers a check to the repository.
*
Expand Down Expand Up @@ -108,4 +117,43 @@ static function ( Check $check ) {
}
);
}

/**
* Registers Checks.
*
* @since n.e.x.t
*/
private function register_default_checks() {
/**
* Filters the available plugin check classes.
*
* @since n.e.x.t
*
* @param array $checks An array map of check slugs to Check instances.
*/
$checks = apply_filters(
'wp_plugin_check_checks',
array(
'i18n_usage' => new Checks\I18n_Usage_Check(),
'enqueued_scripts_size' => new Checks\Enqueued_Scripts_Size_Check(),
'code_obfuscation' => new Checks\Code_Obfuscation_Check(),
'file_type' => new Checks\File_Type_Check(),
'plugin_header_text_domain' => new Checks\Plugin_Header_Text_Domain_Check(),
'late_escaping' => new Checks\Late_Escaping_Check(),
'plugin_updater' => new Checks\Plugin_Updater_Check(),
'plugin_review_phpcs' => new Checks\Plugin_Review_PHPCS_Check(),
'performant_wp_query_params' => new Checks\Performant_WP_Query_Params_Check(),
'enqueued_scripts_in_footer' => new Checks\Enqueued_Scripts_In_Footer_Check(),
'plugin_readme' => new Checks\Plugin_Readme_Check(),
'enqueued_styles_scope' => new Checks\Enqueued_Styles_Scope_Check(),
'localhost' => new Checks\Localhost_Check(),
'no_unfiltered_uploads' => new Checks\No_Unfiltered_Uploads_Check(),
'trademarks' => new Checks\Trademarks_Check(),
)
);

foreach ( $checks as $slug => $check ) {
$this->register_check( $slug, $check );
}
}
}

0 comments on commit ae12a78

Please sign in to comment.