Skip to content

Create Plugin_Main class - #46

Merged
jjgrainger merged 15 commits into
trunkfrom
feature/create-plugin-main-class
Dec 21, 2022
Merged

jjgrainger merged 15 commits into
trunkfrom
feature/create-plugin-main-class

Conversation

@jjgrainger

@jjgrainger jjgrainger commented Dec 19, 2022

Copy link
Copy Markdown
Contributor

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

@felixarntz felixarntz left a comment

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.

@jjgrainger I realize this include #44, but already left a few comments on the things that are new compared to the other PR.

Comment thread includes/Plugin_Context.php Outdated
/**
* Class representing the context in which the plugin is running.
*
* @since 0.1.0

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.

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

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

define( 'WP_PLUGIN_CHECK_VERSION', '0.1.0' );

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.

See above.

Comment thread plugin-check.php
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
Copy Markdown
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 thread includes/Plugin_Main.php
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
Copy Markdown
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.

Comment thread includes/Plugin_Main.php Outdated
* @since 0.1.0
*
* @param string $main_file Absolute path of the plugin main file.
* @return void

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.

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

Comment thread includes/Plugin_Main.php Outdated
*
* @since 0.1.0
*
* @return void

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.

See above.

Comment thread tests/Plugin_Main_Tests.php
Comment thread tests/Plugin_Main_Tests.php Outdated
*
* @test
*/
public function it_can_be_instantiated() {

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.

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

@mukeshpanchal27 mukeshpanchal27 left a comment

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.

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.

Comment thread includes/Plugin_Main.php Outdated
namespace WordPress\Plugin_Check;

/**
* Main class for the plugin

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
* Main class for the plugin
* Main class for the plugin.

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

Comment thread includes/Plugin_Main.php Outdated
}

/**
* Register WordPress hooks for the plugin.

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
* Register WordPress hooks for the plugin.
* Registers WordPress hooks for the plugin.

Use third-person singular verb. See Language

Comment thread plugin-check.php
*/
function wp_plugin_check_load() {
// Check for supported PHP version.
if ( version_compare( phpversion(), WP_PLUGIN_CHECK_MINIMUM_PHP, '<' ) ) {

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.

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

Copy link
Copy Markdown
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()

Comment thread plugin-check.php Outdated
}

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

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.

Similar to Performance Lab lets define some constant that we can use in other places.

https://github.com/WordPress/performance/blob/trunk/load.php#L19-L20

@jjgrainger
jjgrainger marked this pull request as ready for review December 20, 2022 17:01

@felixarntz felixarntz left a comment

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.

@jjgrainger LGTM, just one nit-pick.

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

$this->assertIsObject( $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.

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

@mukeshpanchal27 mukeshpanchal27 left a comment

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.

@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

3 participants