-
Notifications
You must be signed in to change notification settings - Fork 39
Implement CS checking based on the WP_CLI_CS ruleset
#106
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
Update .distignore and .gitignore with phpcs/phpunit config files Update wp-cli-tests to 2.1
WP_CLI_CS ruleset
schlessera
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.
If possible, put the PHPCS in the preceding line instead of after the statement. Horizontal scrolling is not something a lot of people enjoy... ;)
Update namespace function calls and array syntax
|
Ok, the file is now being loaded twice, so you need to wrap a Silly, but there's no easy way I can think of to avoid that. |
|
Hmm, maybe it is worth investigating why it is being loaded twice after all... |
|
So wrapping the function in This is of course just the case when doing development on the command itself, but nevertheless, this bothers me. Two solutions I can think of:
|
|
Here's what I came up with so far. This solves two problems:
<?php
if ( defined( 'WP_CLI_MEDIA_COMMAND_LOADED' ) || ! class_exists( 'WP_CLI' ) ) {
return;
}
define( 'WP_CLI_MEDIA_COMMAND_LOADED', true );
$wpcli_media_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $wpcli_media_autoloader ) ) {
require_once $wpcli_media_autoloader;
}
/**
* Check for Imagick and GD extensions availability.
*
* @throws \WP_CLI\ExitException
*/
$wpcli_media_assert_image_editor_support = function () {
if ( ! wp_image_editor_supports() ) {
WP_CLI::error(
'No support for generating images found. '
. 'Please install the Imagick or GD PHP extensions.'
);
}
};
WP_CLI::add_command(
'media',
'Media_Command',
[ 'before_invoke' => $wpcli_media_assert_image_editor_support ]
);How do you feel about that? |
|
I can't really make up my mind just yet on a new pattern, so let's ignore the double-loading for this release. To fix the broken tests, just turn the regular function into a closure: /**
* Check for Imagick and GD extensions availability.
*
* @throws \WP_CLI\ExitException
*/
$wpcli_media_assert_image_editor_support = function () {
if ( ! wp_image_editor_supports() ) {
WP_CLI::error(
'No support for generating images found. '
. 'Please install the Imagick or GD PHP extensions.'
);
}
};
WP_CLI::add_command(
'media',
'Media_Command',
[ 'before_invoke' => $wpcli_media_assert_image_editor_support ]
); |
|
I was away so couldn't reply faster, this seems fine #106 (comment).
Didn't get this part. So, let's go with the last option then? The invoking function was a closure already, we now have better readability. |
Implement CS checking based on the `WP_CLI_CS` ruleset

Add a PHPCS ruleset using the new
WPCliCSstandard.Fixes #104
Related wp-cli/wp-cli#5179