Skip to content

Conversation

@jjgrainger
Copy link
Contributor

@jjgrainger jjgrainger commented Dec 19, 2022

Adds the Plugin_Main class.

Closes #4

@jjgrainger jjgrainger added [Type] Enhancement A suggestion for improvement of an existing feature Infrastructure Issues for the overall plugin infrastructure Milestone 1 labels Dec 19, 2022
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 I realize this include #44, but already left a few comments on the things that are new compared to the other PR.

/**
* Class representing the context in which the plugin is running.
*
* @since 0.1.0
Copy link
Member

Choose a reason for hiding this comment

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

Maybe use n.e.x.t throughout, like we do in Performance Lab? Since we don't know what the first version will be.

plugin-check.php Outdated
* @package plugin-check
*/

define( 'WP_PLUGIN_CHECK_VERSION', '0.1.0' );
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.

Comment on lines 28 to 35
if ( version_compare( phpversion(), WP_PLUGIN_CHECK_MINIMUM_PHP, '<' ) ) {
return;
}

// Check Composer autoloader exists.
if ( ! file_exists( plugin_dir_path( __FILE__ ) . 'vendor/autoload.php' ) ) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Instead of silently cancelling here, maybe add an action to trigger an admin notice, to indicate to the end user what went wrong? See the POC https://github.com/felixarntz/plugin-check/blob/main/plugin-check.php#L26 for reference.

Comment on lines 28 to 35
*
* @since 0.1.0
*
* @param string $main_file Absolute path of the plugin main file.
* @return void
*/
public function __construct( $main_file ) {
$this->context = new Plugin_Context( $main_file );
Copy link
Member

Choose a reason for hiding this comment

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

Should we maybe add a public method context() or get_context() to be able to access this instance in a read-only way? That would also give us something a bit more appropriate (yet still simple) to unit test.

* @since 0.1.0
*
* @param string $main_file Absolute path of the plugin main file.
* @return void
Copy link
Member

Choose a reason for hiding this comment

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

@return void should be omitted, per WP doc standards.

*
* @since 0.1.0
*
* @return void
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.

*
* @test
*/
public function it_can_be_instantiated() {
Copy link
Member

Choose a reason for hiding this comment

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

See my comment on #44 for using the test_ method prefix and avoiding doc-blocks (or more specifically the @test annotation) where not necessary.

Copy link
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 Left some feedback.

Question: Is there any reason to use the first capital in the class file name? If not, then we can use lowercase.

namespace WordPress\Plugin_Check;

/**
* Main class for the plugin
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Main class for the plugin
* Main class for the plugin.

As per Inline document CS, Use a period at the end.

}

/**
* Register WordPress hooks for the plugin.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Register WordPress hooks for the plugin.
* Registers WordPress hooks for the plugin.

Use third-person singular verb. See Language

*/
function wp_plugin_check_load() {
// Check for supported PHP version.
if ( version_compare( phpversion(), WP_PLUGIN_CHECK_MINIMUM_PHP, '<' ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

Why phpversion()? Is there any specific reason? The constant PHP_VERSION is used by WordPress.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mukeshpanchal27 I think they both work the same, so I have left it as using phpversion()

plugin-check.php Outdated
}

// Load the Composer autoloader.
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
Copy link
Member

Choose a reason for hiding this comment

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

@jjgrainger jjgrainger marked this pull request as ready for review December 20, 2022 17:01
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 LGTM, just one nit-pick.

public function test_context() {
$context = $this->plugin_main->context();

$this->assertIsObject( $context );
Copy link
Member

Choose a reason for hiding this comment

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

Nit-pick, this is unnecessary since the assertion below by definition covers that already.

Copy link
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.

@jjgrainger looks great.

@jjgrainger jjgrainger merged commit f5e87b6 into trunk Dec 21, 2022
@jjgrainger jjgrainger deleted the feature/create-plugin-main-class branch December 21, 2022 07:45
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 Plugin_Main class

4 participants