Create Abstract Check Runner & CLI_Runner classes#73
Conversation
There was a problem hiding this comment.
@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.
|
@felixarntz I've updated the PR based on your feedback, this is ready for you to review. Thanks |
|
@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. |
felixarntz
left a comment
There was a problem hiding this comment.
@jjgrainger Thanks for the changes, this looks much better. I left some follow up feedback.
felixarntz
left a comment
There was a problem hiding this comment.
@jjgrainger This looks great. Only a few nit-picks, but nothing blocking.
| * | ||
| * @since n.e.x.t | ||
| * | ||
| * @return Check_Context |
| if ( ! isset( $this->checks ) ) { | ||
| // TODO: Add checks once implemented. | ||
| $checks = array( | ||
| 'i18n-usage' => new Checks\I18n_Usage_Check(), |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
This should probably be changed to describe the same map that is now returned by the Checks::get_checks() method.
| * @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. | ||
| * } |
There was a problem hiding this comment.
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.
| * @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.' ); |
There was a problem hiding this comment.
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.
| 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.', |
There was a problem hiding this comment.
| '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.', |
There was a problem hiding this comment.
| 'Invalid positional argument. Plugin with slug %s is not installed.', | |
| 'Invalid plugin slug: Plugin with slug %s is not installed.', |
mukeshpanchal27
left a comment
There was a problem hiding this comment.
Thanks @jjgrainger, LGTM!
Add Abstract_Check_Runner class
Closes #63, closes #14