Skip to content

Create Abstract Check Runner & CLI_Runner classes#73

Merged
mukeshpanchal27 merged 20 commits into
trunkfrom
feature/create-abstract-check-runner
Feb 14, 2023
Merged

Create Abstract Check Runner & CLI_Runner classes#73
mukeshpanchal27 merged 20 commits into
trunkfrom
feature/create-abstract-check-runner

Conversation

@jjgrainger
Copy link
Copy Markdown
Contributor

@jjgrainger jjgrainger commented Feb 8, 2023

Add Abstract_Check_Runner class

Closes #63, closes #14

@jjgrainger jjgrainger added [Type] Enhancement A suggestion for improvement of an existing feature Infrastructure Issues for the overall plugin infrastructure Milestone 1 labels Feb 8, 2023
Copy link
Copy Markdown
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjgrainger I left a number of comments here for a few things that I think are worth iterating on. Most importantly, using declarative methods to return specific parts make for a more intuitive API than relying on one method that has to set multiple specific class properties. It is like that in the ACs, but looking at the code it makes for a rather clunky experience.

One higher level thing that we have not considered so far, but I think it may be relevant here is that runtime checks as a whole should only ever be eligible to run if the plugin to check is in fact active. We may want to add a clause somewhere here that early on throws an exception if the plugin is not active and any of the provided checks to run is a runtime check.

Most comments not related to the above are nit-picks, e.g. about more closely following WP docs standards.

Comment thread includes/Checker/Abstract_Check_Runner.php Outdated
Comment thread includes/Checker/Abstract_Check_Runner.php Outdated
Comment thread includes/Checker/Abstract_Check_Runner.php
Comment thread includes/Checker/Abstract_Check_Runner.php Outdated
Comment thread includes/Checker/Abstract_Check_Runner.php Outdated
Comment thread includes/Checker/Abstract_Check_Runner.php Outdated
Comment thread includes/Checker/Abstract_Check_Runner.php Outdated
Comment thread includes/Checker/Abstract_Check_Runner.php Outdated
Comment thread includes/Checker/Abstract_Check_Runner.php Outdated
Comment thread includes/Checker/Abstract_Check_Runner.php Outdated
@jjgrainger jjgrainger requested a review from felixarntz February 9, 2023 18:47
@jjgrainger
Copy link
Copy Markdown
Contributor Author

@felixarntz I've updated the PR based on your feedback, this is ready for you to review. Thanks

@jjgrainger
Copy link
Copy Markdown
Contributor Author

@felixarntz I've updated this PR to include the work for #14 in order to test the approach we discussed. This is ready for review.

Comment thread includes/Checker/Checks.php Outdated
@jjgrainger jjgrainger changed the title Create Abstract Check Runner class Create Abstract Check Runner & CLI_Runner classes Feb 10, 2023
Copy link
Copy Markdown
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjgrainger Thanks for the changes, this looks much better. I left some follow up feedback.

Comment thread includes/Checker/Abstract_Check_Runner.php Outdated
Comment thread includes/Checker/Abstract_Check_Runner.php Outdated
Comment thread includes/Checker/Abstract_Check_Runner.php Outdated
Comment thread includes/Checker/Abstract_Check_Runner.php Outdated
Comment thread includes/Checker/Abstract_Check_Runner.php Outdated
Comment thread includes/Checker/CLI_Runner.php
Comment thread includes/Checker/CLI_Runner.php Outdated
Comment thread includes/Checker/CLI_Runner.php
Comment thread includes/Checker/CLI_Runner.php Outdated
Comment thread includes/Checker/Checks.php Outdated
Copy link
Copy Markdown
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjgrainger This looks great. Only a few nit-picks, but nothing blocking.

Comment thread includes/Checker/Checks.php Outdated
*
* @since n.e.x.t
*
* @return Check_Context
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a description.

Comment thread includes/Checker/Checks.php Outdated
if ( ! isset( $this->checks ) ) {
// TODO: Add checks once implemented.
$checks = array(
'i18n-usage' => new Checks\I18n_Usage_Check(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using underscores is a bit of a better convention than using hyphens. For example, underscores are allowed in variable names and in JS object properties, while hyphens are not.

*
* @since n.e.x.t
*
* @return array An array of Check instances.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be changed to describe the same map that is now returned by the Checks::get_checks() method.

Comment on lines +116 to +121
* @return array {
* An array of Preparations to run where each item is an array with the class name and args.
*
* @type string $class The full class name of the Preparation.
* @type array $args An array of parameters to pass to the class constructor.
* }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is correct as a human-readable description, technically speaking in terms of PHPDoc this is not correct, as the current shape would suggest the return value is an associative array that includes class and args keys. However, the return value is an indexed array where each entry is that above array.

I think for simplicity sake we should therefore stick with just a precise description, otherwise the correct return type annotation would become somewhat complex.

Suggested change
* @return array {
* An array of Preparations to run where each item is an array with the class name and args.
*
* @type string $class The full class name of the Preparation.
* @type array $args An array of parameters to pass to the class constructor.
* }
* @return array An array of Preparations to run where each item is an array with keys `class` and `args`.

require_once ABSPATH . 'wp-admin/includes/plugin.php';

if ( empty( $plugin_slug ) ) {
throw new Exception( 'Missing positional argument. Please provide the plugin slug as first positional argument.' );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the message here to be context-independent. This message worked well when it was directly scoped to the CLI command, but now referring to a "positional argument" no longer makes sense.

Same applies to the other messages below.

Suggested change
throw new Exception( 'Missing positional argument. Please provide the plugin slug as first positional argument.' );
throw new Exception( 'Invalid plugin slug: Plugin slug must not be empty.' );

if ( strpos( $plugin_slug, '/' ) ) {
throw new Exception(
sprintf(
'Invalid positional argument. Plugin with basename %s is not installed.',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'Invalid positional argument. Plugin with basename %s is not installed.',
'Invalid plugin basename: Plugin with basename %s is not installed.',


throw new Exception(
sprintf(
'Invalid positional argument. Plugin with slug %s is not installed.',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'Invalid positional argument. Plugin with slug %s is not installed.',
'Invalid plugin slug: Plugin with slug %s is not installed.',

Copy link
Copy Markdown
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jjgrainger, LGTM!

@mukeshpanchal27 mukeshpanchal27 merged commit 960756b into trunk Feb 14, 2023
@mukeshpanchal27 mukeshpanchal27 deleted the feature/create-abstract-check-runner branch February 14, 2023 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Infrastructure Issues for the overall plugin infrastructure [Type] Enhancement A suggestion for improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Abstract_Check_Runner class Create CLI_Runner class

3 participants