-
Notifications
You must be signed in to change notification settings - Fork 83
Create Plugin_Main class #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
felixarntz
left a comment
There was a problem hiding this 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.
includes/Plugin_Context.php
Outdated
| /** | ||
| * Class representing the context in which the plugin is running. | ||
| * | ||
| * @since 0.1.0 |
There was a problem hiding this comment.
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' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
| 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; | ||
| } |
There was a problem hiding this comment.
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.
| * | ||
| * @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 ); |
There was a problem hiding this comment.
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.
includes/Plugin_Main.php
Outdated
| * @since 0.1.0 | ||
| * | ||
| * @param string $main_file Absolute path of the plugin main file. | ||
| * @return void |
There was a problem hiding this comment.
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.
includes/Plugin_Main.php
Outdated
| * | ||
| * @since 0.1.0 | ||
| * | ||
| * @return void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
tests/Plugin_Main_Tests.php
Outdated
| * | ||
| * @test | ||
| */ | ||
| public function it_can_be_instantiated() { |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this 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.
includes/Plugin_Main.php
Outdated
| namespace WordPress\Plugin_Check; | ||
|
|
||
| /** | ||
| * Main class for the plugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * Main class for the plugin | |
| * Main class for the plugin. |
As per Inline document CS, Use a period at the end.
includes/Plugin_Main.php
Outdated
| } | ||
|
|
||
| /** | ||
| * Register WordPress hooks for the plugin. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * 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, '<' ) ) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
felixarntz
left a comment
There was a problem hiding this 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 ); |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jjgrainger looks great.
Adds the
Plugin_Mainclass.Plugin_Mainclass accepts the plugin main file in the constructorPlugin_Mainclass creates aPlugin_Contextobject passing the main file parameterPlugin_Contextclass is a basic scaffold and will be addressed as part of Create Plugin_Context class #5Plugin_Mainclass has an emptyadd_hooksmethod that will be addressed as part of Create the WP-CLI subcommand wp plugin check #30Closes #4