Skip to content

Conversation

@jjgrainger
Copy link
Contributor

Addresses acceptance criteria in #93

Closes #93

@jjgrainger jjgrainger added [Type] Enhancement A suggestion for improvement of an existing feature Infrastructure Issues for the overall plugin infrastructure Milestone 1 labels Feb 28, 2023
Copy link
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 close, there are a few things that need to be fixed though around sanitization and validation. Also a few method renaming suggestions that just came up in my review based on the logic you're using, I like your idea of using the abstract methods only to get the parameter value but not more.

Copy link
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, the code looks great. A few last naming quirks, but I'll already approve this as following the renaming it can be merged.

*
* @throws Exception Thrown if the plugin main file does not match the original request.
*/
public function set_plugin_slug( $plugin_slug ) {
Copy link
Member

@felixarntz felixarntz Mar 1, 2023

Choose a reason for hiding this comment

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

Currently the logic in this checks against the plugin parameter, which can be either a plugin slug or a plugin basename, so the name of this method, the parameter, and also the internal property name is misleading.

We should probably align with the rest of the new method names here to clarify that this is simply the plugin param. In other words, let's call this set_plugin( $plugin ), and let's clarify on both the method parameter and the $this->plugin property declaration that the value can be either a plugin slug or a plugin basename.

This effectively means wherever we use this value we need to run it through Plugin_Request_Utility::get_plugin_basename_from_input to sanitize it to a basename. I think that's okay since it only happens in one place anyway.

return $this->checks;
}

$plugin_slug = isset( $this->plugin_slug ) ? $this->plugin_slug : $this->get_plugin_param();
Copy link
Member

Choose a reason for hiding this comment

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

See above regarding naming, let's use $plugin instead of $plugin_slug to account for the ambiguity of what this value can contain (it's not necessarily a slug).

Comment on lines 61 to 69
$plugin_slug = isset( $_SERVER['argv'][3] ) ? $_SERVER['argv'][3] : '';

$this->checks = new Checks( WP_PLUGIN_DIR . '/' . $plugin_file );
if ( empty( $plugin_slug ) ) {
throw new Exception(
__( 'Invalid plugin slug: Plugin slug must not be empty.', 'plugin-check' )
);
}

return $this->checks;
return $plugin_slug;
Copy link
Member

Choose a reason for hiding this comment

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

See above regarding naming of this. Also can you similarly adjust the exception message to refer to "plugin parameter" rather than "plugin slug"?

protected function get_plugin_param() {
if ( ! isset( $_REQUEST['plugin'] ) ) {
throw new Exception(
__( 'Invalid plugin slug: Plugin slug must not be empty.', 'plugin-check' )
Copy link
Member

Choose a reason for hiding this comment

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

See other similar comment, can you adjust the exception message to refer to "plugin parameter" rather than "plugin slug"?

Copy link

@vishalkakadiya vishalkakadiya left a comment

Choose a reason for hiding this comment

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

LGTM!

@jjgrainger jjgrainger merged commit 9c59940 into trunk Mar 2, 2023
@jjgrainger jjgrainger deleted the feature/update-runner-classes-to-validate-checks branch March 2, 2023 17:21
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.

Update Runner Classes to accept and validate the checks to run and plugin file

4 participants