Skip to content

Commit

Permalink
Merge pull request #106 from thrijith/feature/use-phpcs
Browse files Browse the repository at this point in the history
Implement CS checking based on the `WP_CLI_CS` ruleset
  • Loading branch information
schlessera authored Apr 19, 2019
2 parents cb4eaa1 + ff6ce68 commit 885b5e6
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 128 deletions.
2 changes: 2 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
.travis.yml
behat.yml
circle.yml
phpcs.xml.dist
phpunit.xml.dist
bin/
features/
utils/
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ vendor/
*.tar.gz
composer.lock
*.log
phpunit.xml
phpcs.xml
.phpcs.xml
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"require-dev": {
"wp-cli/entity-command": "^1.3 || ^2",
"wp-cli/wp-cli-tests": "^2.0.7"
"wp-cli/wp-cli-tests": "^2.1"
},
"config": {
"process-timeout": 7200,
Expand Down
31 changes: 21 additions & 10 deletions media-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@
return;
}

$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $autoload ) ) {
require_once $autoload;
$wpcli_media_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $wpcli_media_autoloader ) ) {
require_once $wpcli_media_autoloader;
}

WP_CLI::add_command( 'media', 'Media_Command', array(
'before_invoke' => function () {
if ( !wp_image_editor_supports() ) {
WP_CLI::error( 'No support for generating images found. ' .
'Please install the Imagick or GD PHP extensions.' );
}
/**
* 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 ]
);
59 changes: 59 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0"?>
<ruleset name="WP-CLI-media">
<description>Custom ruleset for WP-CLI media-command</description>

<!--
#############################################################################
COMMAND LINE ARGUMENTS
For help understanding this file: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
For help using PHPCS: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage
#############################################################################
-->

<!-- What to scan. -->
<file>.</file>

<!-- Show progress. -->
<arg value="p"/>

<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./"/>

<!-- Check up to 8 files simultaneously. -->
<arg name="parallel" value="8"/>

<!--
#############################################################################
USE THE WP_CLI_CS RULESET
#############################################################################
-->

<rule ref="WP_CLI_CS"/>

<!--
#############################################################################
PROJECT SPECIFIC CONFIGURATION FOR SNIFFS
#############################################################################
-->

<!-- For help understanding the `testVersion` configuration setting:
https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
<config name="testVersion" value="5.4-"/>

<!-- Verify that everything in the global namespace is either namespaced or prefixed.
See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#naming-conventions-prefix-everything-in-the-global-namespace -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<property name="prefixes" type="array">
<element value="WP_CLI\Media"/><!-- Namespaces. -->
<element value="wpcli_media"/><!-- Global variables and such. -->
</property>
</properties>
</rule>

<!-- Exclude existing classes from the prefix rule as it would break BC to prefix them now. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound">
<exclude-pattern>*/src/Media_Command\.php$</exclude-pattern>
</rule>

</ruleset>
Loading

0 comments on commit 885b5e6

Please sign in to comment.