├── .gitignore ├── commands ├── minify-command.php ├── phpcov-command.php ├── phpdoc-command.php ├── phpreport-command.php ├── phpcpd-command.php ├── phpdcd-command.php ├── phploc-command.php ├── phpmd-command.php ├── phpunit-command.php └── phpcs-command.php ├── phpci.yml ├── .travis.yml ├── default.php ├── composer.json └── Readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | .tm_properties 2 | composer.lock 3 | vendor 4 | -------------------------------------------------------------------------------- /commands/minify-command.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | if ( true === class_exists( 'WP_CLI_Command' ) ){ 9 | /** 10 | * Combines and minifies JavaScript and CSS files. 11 | * 12 | */ 13 | class WP_CLI_Minify_Command extends WP_CLI_Command{ 14 | 15 | public function run( $args = null, $assoc_args = null ){ 16 | } 17 | } 18 | 19 | WP_CLI::add_command( 'minify', 'WP_CLI_Minify_Command' ); 20 | } 21 | -------------------------------------------------------------------------------- /commands/phpcov-command.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | if ( true === class_exists( 'WP_CLI_Command' ) ){ 9 | /** 10 | * PHP_CodeCoverage: measure and report testing coverage. 11 | * 12 | */ 13 | class WP_CLI_Phpcov_Command extends WP_CLI_Command{ 14 | 15 | public function run( $args = null, $assoc_args = null ){ 16 | } 17 | } 18 | 19 | WP_CLI::add_command( 'phpcov', 'WP_CLI_Phpcov_Command' ); 20 | } 21 | -------------------------------------------------------------------------------- /phpci.yml: -------------------------------------------------------------------------------- 1 | build_settings: 2 | ignore: 3 | - "vendor" 4 | 5 | setup: 6 | composer: 7 | action: "install" 8 | 9 | test: 10 | php_mess_detector: 11 | allow_failures: true 12 | php_code_sniffer: 13 | standard: "WordPress" 14 | allow_failures: false 15 | php_cpd: 16 | allow_failures: false 17 | php_loc: 18 | allow_failures: true 19 | shell: 20 | command: "wp --help" 21 | 22 | success: 23 | package_build: 24 | directory: "/home/buildswer/builds/" 25 | filename: "wp-cli-devtools" 26 | format: zip 27 | 28 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.5 5 | - 5.4 6 | 7 | env: 8 | - WP_VERSION=3.7.1 WP_MULTISITE=0 9 | - WP_VERSION=3.7.1 WP_MULTISITE=1 10 | 11 | before_install: 12 | - set -ex 13 | # - composer install 14 | # set up wp-cli 15 | - export VERSION="dev-master" 16 | - export WP_CORE_DIR="/tmp/wordpress" 17 | - mkdir $WP_CORE_DIR 18 | - mysql -e 'CREATE DATABASE wordpress_test;' -uroot 19 | 20 | before_script: 21 | - cd $TRAVIS_BUILD_DIR 22 | - composer selfupdate 23 | - composer install --dev --no-interaction --prefer-source 24 | - export PATH="$TRAVIS_BUILD_DIR/vendor/bin/:$PATH" 25 | - cd $WP_CORE_DIR 26 | - wp --info 27 | - wp core download --version=$WP_VERSION 28 | - wp core config --dbname=wordpress_test --dbuser=root 29 | - wp core install --url=http://localhost --title="WP" --admin_user=admin --admin_email=test@example.org --admin_password=test 30 | - wp --info 31 | 32 | script: exit 0 33 | -------------------------------------------------------------------------------- /commands/phpdoc-command.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | if ( true === class_exists( 'WP_CLI_Command' ) ){ 9 | /** 10 | * phpDocumentor: generate project documentation. 11 | * 12 | * @since 0.1.0 13 | */ 14 | class WP_CLI_Phpdoc_Command extends WP_CLI_Command{ 15 | 16 | /** 17 | * Run PHP Documentor 18 | * 19 | * ## OPTIONS 20 | * 21 | * 22 | * : Folder to generate 23 | * 24 | * ## EXAMPLES 25 | * 26 | * wp phpdoc run folder/ 27 | * 28 | * @synopsis 29 | * 30 | * @since 0.1.0 31 | */ 32 | public function run( $args = null, $assoc_args = null ){ 33 | #print_r($assoc_args); 34 | if ( null === $args[0] ): 35 | WP_CLI::error( 'Usage: wp phpdoc run ' ); 36 | else : 37 | $cmd = 'phpdoc.php list'; 38 | WP_CLI::launch( $cmd ); 39 | endif; 40 | } 41 | } 42 | 43 | WP_CLI::add_command( 'phpdoc', 'WP_CLI_Phpdoc_Command' ); 44 | } 45 | -------------------------------------------------------------------------------- /default.php: -------------------------------------------------------------------------------- 1 | 8 | * @version 0.2.5 9 | */ 10 | 11 | // work in progress: php-minify 12 | #include( 'commands/minify-command.php' ); 13 | 14 | // work in progress: PHP Coverage 15 | #include( 'commands/phpcov-command.php' ); 16 | 17 | // PHP Copy/Paste Detector 18 | include( 'commands/phpcpd-command.php' ); 19 | 20 | // PHP CodeSniffer 21 | include( 'commands/phpcs-command.php' ); 22 | 23 | // PHP Dead Code Detector 24 | include( 'commands/phpdcd-command.php' ); 25 | 26 | // work in progress: PHP Documentor 27 | #include( 'commands/phpdoc-command.php' ); 28 | 29 | // PHP Lines of Code 30 | include( 'commands/phploc-command.php' ); 31 | 32 | // PHP Mess Detector 33 | include( 'commands/phpmd-command.php' ); 34 | 35 | // PHP Report (bundled commands) 36 | include( 'commands/phpreport-command.php' ); 37 | 38 | // PHPunit 39 | include( 'commands/phpunit-command.php' ); 40 | 41 | ?> -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pixline/wp-cli-php-devtools", 3 | "type": "command", 4 | "description": "Wrapper around common development utilities", 5 | "keywords": ["wp-cli","phpcpd","phpcs","phpdcd","phploc","phpmd","phpunit","phpreport","development"], 6 | "homepage": "https://github.com/pixline/wp-cli-php-devtools", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Paolo Tresso", 11 | "email": "plugins@swergroup.com", 12 | "homepage": "http://swergroup.com", 13 | "role": "Developer" 14 | } 15 | ], 16 | "require": { 17 | "php": ">=5.4", 18 | "wp-cli/wp-cli": ">=0.12", 19 | "phpunit/phpunit": "3.7.*", 20 | "phpunit/php-invoker": ">=1.1.0", 21 | "pixline/php_codesniffer_wp_standard": "dev-master", 22 | "phploc/phploc": "2.0.*", 23 | "sebastian/phpcpd": "2.0.*", 24 | "phpunit/phpcov": "2.0.*@dev", 25 | "sebastian/phpdcd": "1.0.*@dev", 26 | "phpmd/phpmd": "1.5.*" 27 | }, 28 | "support": { 29 | "issues": "https://github.com/pixline/wp-cli-devtools/issues", 30 | "source": "https://github.com/pixline/wp-cli-devtools" 31 | }, 32 | "autoload": { 33 | "files": [ "default.php" ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /commands/phpreport-command.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | if ( true === class_exists( 'WP_CLI_Command' ) ){ 9 | /** 10 | * Run several commands at once over a plugin/theme 11 | * 12 | * @since 0.2.2 13 | */ 14 | class WP_CLI_Phpreport_Command extends WP_CLI_Command{ 15 | 16 | public function __invoke( $args = null, $assoc_args = null ){ 17 | WP_CLI::line( 'Doing '. $args[0] ); 18 | $plugin_path = WP_PLUGIN_DIR . '/' . $args[0]; 19 | $theme_path = WP_CONTENT_DIR . '/themes/' . $args[0]; 20 | 21 | if ( is_dir( $theme_path ) && false === is_dir( $plugin_path ) ): 22 | self::_do_commands( $args[0], $theme_path ); 23 | elseif ( is_dir( $plugin_path ) && false === is_dir( $theme_path ) ) : 24 | self::_do_commands( $args[0], $plugin_path ); 25 | else : 26 | WP_CLI::error( 'Plugin/theme not found' ); 27 | endif; 28 | } 29 | 30 | private function _do_commands( $slug, $path ){ 31 | WP_CLI::success( 'PHP Copy/Paste Detector: '. $args[0] ); 32 | WP_CLI::launch( 'wp phpcpd ' . $slug ); 33 | 34 | WP_CLI::success( 'PHP CodeSniffer: '. $args[0] ); 35 | WP_CLI::launch( 'wp phpcs ' . $slug ); 36 | 37 | WP_CLI::success( 'PHP Dead Code Detector: '. $args[0] ); 38 | WP_CLI::launch( 'wp phpdcd ' . $slug ); 39 | 40 | WP_CLI::success( 'PHP Lines of Code: '. $args[0] ); 41 | WP_CLI::launch( 'wp phploc ' . $slug ); 42 | 43 | WP_CLI::success( 'PHP Mess Detector: '. $args[0] ); 44 | WP_CLI::launch( 'wp phpmd ' . $slug ); 45 | 46 | WP_CLI::success( 'PHPunit: '. $args[0] ); 47 | WP_CLI::launch( 'wp phpunit --plugin=' . $slug ); 48 | } 49 | 50 | 51 | } 52 | 53 | WP_CLI::add_command( 'phpreport', 'WP_CLI_Phpreport_Command' ); 54 | } 55 | -------------------------------------------------------------------------------- /commands/phpcpd-command.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | if ( true === class_exists( 'WP_CLI_Command' ) ){ 9 | /** 10 | * PHP Copy/Paste Detector: find duplicate PHP code. 11 | * 12 | * @since 0.1.0 13 | */ 14 | class WP_CLI_Phpcpd_Command extends WP_CLI_Command{ 15 | 16 | /** 17 | * Run PHP Copy/Paste Detector 18 | * 19 | * ## OPTIONS 20 | * 21 | * 22 | * : Plugin or theme slug to check. 23 | * 24 | * [--flags=] 25 | * : phpcpd command line options. Default: '--progress' 26 | * 27 | * ## EXAMPLES 28 | * 29 | * wp phpcpd uploadplus 30 | * wp phpcpd twentythirteen --flags='--min-lines=2 --min-tokens=30' 31 | * 32 | * @synopsis [--flags=] 33 | * 34 | * @since 0.1.0 35 | */ 36 | public function __invoke( $args = null, $assoc_args = null ){ 37 | if ( 38 | isset( $assoc_args['flags'] ) || 39 | isset( $assoc_args[$args[0]]['flags'] ) 40 | ): 41 | $custom = isset( $assoc_args[$args[0]]['flags'] ) ? $assoc_args[$args[0]]['flags'] : $assoc_args['flags']; 42 | $default_flags = $custom . ' '; 43 | else : 44 | $default_flags = '--progress '; 45 | endif; 46 | if ( null !== $args[0] ): 47 | self::_run_phpcpd( $args[0], $default_flags ); 48 | else : 49 | WP_CLI::error( 'Missing plugin/theme slug.' ); 50 | endif; 51 | } 52 | 53 | private function _run_phpcpd( $slug, $flags ){ 54 | $plugin_path = WP_PLUGIN_DIR . '/' . $slug; 55 | $theme_path = WP_CONTENT_DIR . '/themes/' . $slug; 56 | 57 | if ( is_dir( $theme_path ) && false === is_dir( $plugin_path ) ): 58 | WP_CLI::launch( 'phpcpd '.$flags . $theme_path ); 59 | elseif ( is_dir( $plugin_path ) && false === is_dir( $theme_path ) ) : 60 | WP_CLI::launch( 'phpcpd '.$flags . $plugin_path ); 61 | else : 62 | WP_CLI::error( 'Plugin/theme not found' ); 63 | endif; 64 | } 65 | 66 | } 67 | 68 | WP_CLI::add_command( 'phpcpd', 'WP_CLI_Phpcpd_Command' ); 69 | } 70 | -------------------------------------------------------------------------------- /commands/phpdcd-command.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | if ( true === class_exists( 'WP_CLI_Command' ) ){ 9 | /** 10 | * PHP Dead Code Detector: find dead/unused PHP code. 11 | * 12 | * @since 0.1.0 13 | */ 14 | class WP_CLI_Phpdcd_Command extends WP_CLI_Command{ 15 | 16 | /** 17 | * Run PHP Dead Code Detector 18 | * 19 | * ## OPTIONS 20 | * 21 | * 22 | * : Plugin or theme slug to check. 23 | * 24 | * [--flags=] 25 | * : phpdcd command line options. Default: '--suffixes php' 26 | * 27 | * ## EXAMPLES 28 | * 29 | * wp phpdcd uploadplus 30 | * wp phpdcd twentythirteen --flags="--recursive --suffixes php --exclude vendor" 31 | * 32 | * @synopsis [--flags=] 33 | * 34 | * @since 0.1.0 35 | */ 36 | public function __invoke( $args = null, $assoc_args = null ){ 37 | if ( 38 | isset( $assoc_args['flags'] ) || 39 | isset( $assoc_args[$args[0]]['flags'] ) 40 | ): 41 | $custom = isset( $assoc_args[$args[0]]['flags'] ) ? $assoc_args[$args[0]]['flags'] : $assoc_args['flags']; 42 | $default_flags = $custom . ' '; 43 | else : 44 | $default_flags = '--suffixes php '; 45 | endif; 46 | if ( null !== $args[0] ): 47 | self::_run_phpdcd( $args[0], $default_flags ); 48 | else : 49 | WP_CLI::error( 'Missing plugin/theme slug.' ); 50 | endif; 51 | } 52 | 53 | private function _run_phpdcd( $slug, $flags ){ 54 | $plugin_path = WP_PLUGIN_DIR . '/' . $slug; 55 | $theme_path = WP_CONTENT_DIR . '/themes/' . $slug; 56 | 57 | if ( is_dir( $theme_path ) && false === is_dir( $plugin_path ) ): 58 | WP_CLI::launch( 'phpdcd '.$flags . $theme_path ); 59 | elseif ( is_dir( $plugin_path ) && false === is_dir( $theme_path ) ) : 60 | WP_CLI::launch( 'phpdcd '.$flags . $plugin_path ); 61 | else : 62 | WP_CLI::error( 'Plugin/theme not found' ); 63 | endif; 64 | } 65 | 66 | } 67 | 68 | WP_CLI::add_command( 'phpdcd', 'WP_CLI_Phpdcd_Command' ); 69 | } 70 | -------------------------------------------------------------------------------- /commands/phploc-command.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | if ( true === class_exists( 'WP_CLI_Command' ) ){ 9 | /** 10 | * PHP Lines of Code: measure the size of a PHP project. 11 | * 12 | * @since 0.1.0 13 | */ 14 | class WP_CLI_Phploc_Command extends WP_CLI_Command{ 15 | 16 | /** 17 | * Run PHP Lines of Code 18 | * 19 | * ## OPTIONS 20 | * 21 | * 22 | * : Plugin or theme slug to check. 23 | * 24 | * [--flags=] 25 | * : phploc command line options. Defaults : 26 | * '--names="*.php" --count-tests --progress' 27 | * 28 | * ## EXAMPLES 29 | * 30 | * wp phploc uploadplus 31 | * wp phploc twentythirteen --flags='--names="*.php" --log-xml' 32 | * 33 | * @synopsis [--flags=] 34 | * 35 | * @since 0.2.1 36 | */ 37 | public function __invoke( $args = null, $assoc_args = null ){ 38 | if ( 39 | isset( $assoc_args['flags'] ) || 40 | isset( $assoc_args[$args[0]]['flags'] ) 41 | ): 42 | $custom = isset( $assoc_args[$args[0]]['flags'] ) ? $assoc_args[$args[0]]['flags'] : $assoc_args['flags']; 43 | $default_flags = $custom . ' '; 44 | else : 45 | $default_flags = '--names="*.php" --count-tests --progress '; 46 | endif; 47 | if ( null !== $args[0] ): 48 | self::_run_phploc( $args[0], $default_flags ); 49 | else : 50 | WP_CLI::error( 'Missing plugin/theme slug.' ); 51 | endif; 52 | } 53 | 54 | 55 | private function _run_phploc( $slug, $flags ){ 56 | $plugin_path = WP_PLUGIN_DIR . '/' . $slug; 57 | $theme_path = WP_CONTENT_DIR . '/themes/' . $slug; 58 | 59 | if ( is_dir( $theme_path ) && false === is_dir( $plugin_path ) ): 60 | WP_CLI::launch( 'phploc '.$flags . $theme_path ); 61 | elseif ( is_dir( $plugin_path ) && false === is_dir( $theme_path ) ) : 62 | WP_CLI::launch( 'phploc '.$flags . $plugin_path ); 63 | else : 64 | WP_CLI::error( 'Plugin/theme not found' ); 65 | endif; 66 | } 67 | } 68 | 69 | WP_CLI::add_command( 'phploc', 'WP_CLI_Phploc_Command' ); 70 | } 71 | -------------------------------------------------------------------------------- /commands/phpmd-command.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | if ( true === class_exists( 'WP_CLI_Command' ) ){ 9 | /** 10 | * PHP Mess Detector: analyze source code for several potential problems. 11 | * 12 | * @since 0.1.0 13 | */ 14 | class WP_CLI_Phpmd_Command extends WP_CLI_Command{ 15 | 16 | /** 17 | * Run PHP Mess Detector 18 | * 19 | * ## OPTIONS 20 | * 21 | * 22 | * : Plugin or theme slug to check. 23 | * 24 | * [--flags=] 25 | * : phpmd command line options. Defaults: 26 | * 'text codesize,controversial,design,naming,unusedcode --suffixes=php' 27 | * 28 | * ## EXAMPLES 29 | * 30 | * wp phpmd uploadplus 31 | * wp phpmd twentythirteen --flags='json codesize,naming,unusedcode --suffixes=php' 32 | * 33 | * @synopsis [--flags=] 34 | * 35 | * @since 0.1.0 36 | */ 37 | public function __invoke( $args = null, $assoc_args = null ){ 38 | if ( 39 | isset( $assoc_args['flags'] ) || 40 | isset( $assoc_args[$args[0]]['flags'] ) 41 | ): 42 | $custom = isset( $assoc_args[$args[0]]['flags'] ) ? $assoc_args[$args[0]]['flags'] : $assoc_args['flags']; 43 | $default_flags = $custom . ' '; 44 | else : 45 | $default_flags = ' text codesize,controversial,design,naming,unusedcode --suffixes=php '; 46 | endif; 47 | if ( null !== $args[0] ): 48 | self::_run_phpmd( $args[0], $default_flags ); 49 | else : 50 | WP_CLI::error( 'Missing plugin/theme slug.' ); 51 | endif; 52 | } 53 | 54 | 55 | private function _run_phpmd( $slug, $flags ){ 56 | $plugin_path = WP_PLUGIN_DIR . '/' . $slug; 57 | $theme_path = WP_CONTENT_DIR . '/themes/' . $slug; 58 | 59 | if ( is_dir( $theme_path ) && false === is_dir( $plugin_path ) ): 60 | WP_CLI::launch( 'phpmd '. $theme_path . $flags ); 61 | elseif ( is_dir( $plugin_path ) && false === is_dir( $theme_path ) ) : 62 | WP_CLI::launch( 'phpmd '. $plugin_path . $flags ); 63 | else : 64 | WP_CLI::error( 'Plugin/theme not found' ); 65 | endif; 66 | } 67 | 68 | } 69 | 70 | WP_CLI::add_command( 'phpmd', 'WP_CLI_Phpmd_Command' ); 71 | } 72 | -------------------------------------------------------------------------------- /commands/phpunit-command.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | if ( true === class_exists( 'WP_CLI_Command' ) ){ 9 | /** 10 | * Run PHPunit unit tests 11 | * 12 | * @since 0.1.0 13 | */ 14 | class WP_CLI_Phpunit_Command extends WP_CLI_Command{ 15 | 16 | 17 | private function _do_core( $unit_tests_dir ){ 18 | WP_CLI::line( 'Doing Core' ); 19 | if ( is_dir( $unit_tests_dir ) ): 20 | WP_CLI::launch( 'cd ' . $unit_tests_dir . ' && phpunit' ); 21 | else : 22 | WP_CLI::error( 'Please run `wp core install-tests` first!' ); 23 | endif; 24 | } 25 | 26 | private function _do_plugin( $slug, $tests ){ 27 | WP_CLI::line( 'Doing Plugin ' . $slug ); 28 | $plugin_dir = WP_PLUGIN_DIR . '/' . $slug; 29 | if ( is_dir( $plugin_dir ) ): 30 | WP_CLI::launch( 'export WP_TESTS_DIR='.$tests.'; cd ' . $plugin_dir . '; phpunit -c phpunit.xml ' ); 31 | else : 32 | WP_CLI::error( 'Can\'t find plugin folder: ' . $plugin_dir ); 33 | endif; 34 | } 35 | 36 | /** 37 | * Run unit tests 38 | * 39 | * ## OPTIONS 40 | * 41 | * --core 42 | * : Run WordPress core unit tests 43 | * 44 | * --plugin= 45 | * : Run selected plugin unit tests 46 | * 47 | * --tests-folder= 48 | * : Optional WordPress unit tests folder 49 | * 50 | * ## EXAMPLES 51 | * 52 | * wp phpunit run --core 53 | * wp phpunit run --plugin=plugin-slug 54 | * wp phpunit run --core --unit_tests=/home/user/src/wp-unit-tests/ 55 | * 56 | * @synopsis [--core] [--plugin=] [--tests-folder=] 57 | * 58 | * @since 0.1.0 59 | */ 60 | public function run( $args = null, $assoc_args = null ){ 61 | $unit_tests_dir = ( false === isset( $assoc_args['unit_test'] ) ) ? ABSPATH . '/unit-tests' : $assoc_args['unit_test']; 62 | 63 | if ( isset( $assoc_args['core'] ) ): 64 | self::_do_core( $unit_tests_dir ); 65 | 66 | elseif ( isset( $assoc_args['plugin'] ) && null !== $assoc_args['plugin'] ): 67 | self::_do_plugin( $assoc_args['plugin'], $unit_tests_dir ); 68 | 69 | else : 70 | WP_CLI::line( 'Usage: wp phpunit [--core] [--plugin=]' ); 71 | 72 | endif; 73 | } 74 | } 75 | 76 | WP_CLI::add_command( 'phpunit', 'WP_CLI_Phpunit_Command' ); 77 | } 78 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # wp-cli PHP developer tools 0.2.5 2 | 3 | [![Build Status](https://travis-ci.org/pixline/wp-cli-php-devtools.png?branch=master)](https://travis-ci.org/pixline/wp-cli-php-devtools) [![Support](https://www.paypalobjects.com/it_IT/IT/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CX6VQ6FVJFN4L) 4 | 5 | 6 | Useful commands/wrappers around common development and test utilities: 7 | 8 | * `phpcpd` -- Find duplicate PHP code via [PHP Copy/Paste Detector](https://github.com/sebastianbergmann/phpcpd) 9 | * `phpcs` -- Detects violations of a defined set of coding standards via [PHP Code Sniffer](https://github.com/squizlabs/php_codesniffer). 10 | * `phpdcd` -- Find dead/unused PHP code via [PHP Dead Code Detector](https://github.com/sebastianbergmann/phpdcd) 11 | * `phploc` -- Measure the size of a PHP project via [PHP Lines of Code](https://github.com/sebastianbergmann/phploc) 12 | * `phpmd` -- Analyze source code for several potential problems via [PHP Mess Detector](https://github.com/phpmd/phpmd) 13 | * `phpunit` -- Run [PHPunit](https://github.com/sebastianbergmann/phpunit) unit tests. 14 | 15 | Also in the bundle a single command to run every command at once: 16 | 17 | * `phpreport` -- Run phpcpd + phpcs + phpdcd + phploc + phpmd + phpunit over a single plugin/theme 18 | 19 | Work in progress: 20 | 21 | * `minify` -- Combines and minifies JavaScript and CSS files via YUI Compressor. 22 | * `phpdoc` -- Generate project documentation via phpDocumentor. 23 | * `phpcov` -- Measure and report code testing coverage via PHP_CodeCoverage. 24 | 25 | ## System Requirements 26 | 27 | * PHP >=5.4 28 | * Composer 29 | * wp-cli 30 | 31 | ## Setup 32 | 33 | * Install [wp-cli](https://wp-cli.org) 34 | * Install wp-cli-php-devtools: 35 | 36 | ``` 37 | cd /path/to/wp-cli/ 38 | composer config repositories.wp-cli composer http://wp-cli.org/package-index/ 39 | composer require pixline/wp-cli-php-devtools=0.2.5 40 | ``` 41 | 42 | * Add wp-cli bin/ folder to $PATH (important!!): 43 | 44 | ``` 45 | echo 'PATH="/path/to/wp-cli/bin/:$PATH" >> .bash_profile 46 | ``` 47 | 48 | ## Changelog 49 | 50 | ### 0.2.5 51 | 52 | * `wp-cli.yml` configuration support (all commands except phpunit) 53 | * Cleaner inline commands help 54 | 55 | ### Previous releases 56 | 57 | * 0.2.4 (29/11/2013) `__invoke` implementation 58 | * 0.2.3 (29/11/2013) First public release 59 | 60 | ## Credits 61 | 62 | Copyright (c) 2013+ Paolo Tresso / [SWERgroup](http://swergroup.com) 63 | 64 | Plugin released under the [MIT License](http://opensource.org/licenses/MIT) 65 | -------------------------------------------------------------------------------- /commands/phpcs-command.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | 8 | if ( true === class_exists( 'WP_CLI_Command' ) ){ 9 | /** 10 | * PHP CodeSniffer: detects violations of a defined set of coding standards. 11 | * 12 | * 13 | * @since 0.1.0 14 | */ 15 | class WP_CLI_Phpcs_Command extends WP_CLI_Command{ 16 | 17 | /** 18 | * Run PHP Code Sniffer over a theme or plugin folder. 19 | * 20 | * ## OPTIONS 21 | * 22 | * 23 | * : Plugin or theme slug to check. 24 | * 25 | * [--flags=] 26 | * : phpcs command line options. Default: '-p' 27 | * 28 | * ## USAGE 29 | * 30 | * Command looks for a plugin or theme folder and run phpcs on that: 31 | * 32 | * phpcs -p --standard=WordPress --extensions=php path/to/folder 33 | * 34 | * Optional --flags will overwrite the variable section of the commandline above 35 | * ('-p') , while --standard and --extensions are by default. Setting flags like 36 | * --flags='-s -v' equals this command: 37 | * 38 | * phpcs -s -v --standard=WordPress --extensions=php 39 | * 40 | * ## EXAMPLES 41 | * 42 | * wp phpcs uploadplus 43 | * wp phpcs twentythirteen --flags='-n -p -s -v' 44 | * 45 | * @synopsis [--flags=] 46 | * 47 | * @since 0.1.0 48 | */ 49 | public function __invoke( $args = null, $assoc_args = null ){ 50 | 51 | if ( 52 | isset( $assoc_args['flags'] ) || 53 | isset( $assoc_args[$args[0]]['flags'] ) 54 | ): 55 | $custom = isset( $assoc_args[$args[0]]['flags'] ) ? $assoc_args[$args[0]]['flags'] : $assoc_args['flags']; 56 | $default_flags = $custom . ' --standard=WordPress --extensions=php '; 57 | else : 58 | $default_flags = '-p --standard=WordPress --extensions=php '; 59 | endif; 60 | 61 | if ( null !== $args[0] ): 62 | self::_run_phpcs( $args[0], $default_flags ); 63 | else : 64 | WP_CLI::error( 'Missing plugin/theme slug.' ); 65 | endif; 66 | } 67 | 68 | /** 69 | * Verify plugin or theme path, run phpcs when found 70 | * 71 | * @since 0.2.1 72 | */ 73 | private function _run_phpcs( $slug, $flags ){ 74 | $plugin_path = WP_PLUGIN_DIR . '/' . $slug; 75 | $theme_path = WP_CONTENT_DIR . '/themes/' . $slug; 76 | 77 | if ( is_dir( $theme_path ) && false === is_dir( $plugin_path ) ): 78 | WP_CLI::launch( 'phpcs '.$flags . $theme_path ); 79 | elseif ( is_dir( $plugin_path ) && false === is_dir( $theme_path ) ) : 80 | WP_CLI::launch( 'phpcs '.$flags . $plugin_path ); 81 | else : 82 | WP_CLI::error( 'No theme or plugin with that slug.' ); 83 | endif; 84 | } 85 | 86 | } 87 | 88 | WP_CLI::add_command( 'phpcs', 'WP_CLI_Phpcs_Command' ); 89 | } 90 | --------------------------------------------------------------------------------