Create Plugin_Main class - #46
Conversation
felixarntz
left a comment
There was a problem hiding this comment.
@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 |
There was a problem hiding this comment.
Maybe use n.e.x.t throughout, like we do in Performance Lab? Since we don't know what the first version will be.
| * @package plugin-check | ||
| */ | ||
|
|
||
| define( 'WP_PLUGIN_CHECK_VERSION', '0.1.0' ); |
| 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.
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.
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 |
There was a problem hiding this comment.
@return void should be omitted, per WP doc standards.
| * | ||
| * @since 0.1.0 | ||
| * | ||
| * @return void |
| * | ||
| * @test | ||
| */ | ||
| public function it_can_be_instantiated() { |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
| * 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. |
There was a problem hiding this comment.
| * 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.
Why phpversion()? Is there any specific reason? The constant PHP_VERSION is used by WordPress.
There was a problem hiding this comment.
@mukeshpanchal27 I think they both work the same, so I have left it as using phpversion()
| } | ||
|
|
||
| // Load the Composer autoloader. | ||
| require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
There was a problem hiding this comment.
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
felixarntz
left a comment
There was a problem hiding this comment.
@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.
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.
@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