From 9406fb0639cb3645104cf0d98b25efbd8280693f Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 26 Oct 2017 13:09:01 -0700 Subject: [PATCH] Reuse local copy of phpcs --- src/PHP_Compat_Command.php | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/PHP_Compat_Command.php b/src/PHP_Compat_Command.php index 8d06bd4..64f8c1e 100644 --- a/src/PHP_Compat_Command.php +++ b/src/PHP_Compat_Command.php @@ -76,12 +76,13 @@ class PHP_Compat_Command { * @when before_wp_load */ public function __invoke( $args, $assoc_args ) { + $phpcs_exec = self::get_phpcs_exec(); $descriptors = array( 0 => STDIN, 1 => array( 'pipe', 'w' ), 2 => array( 'pipe', 'w' ), ); - $r = proc_open( 'phpcs -i', $descriptors, $pipes ); + $r = proc_open( $phpcs_exec . ' -i', $descriptors, $pipes ); $stdout = stream_get_contents( $pipes[1] ); fclose( $pipes[1] ); $stderr = stream_get_contents( $pipes[2] ); @@ -230,19 +231,7 @@ private static function scan_extension( $extension, $php_version ) { } } - $phpcs_exec = false; - $base_path = dirname( dirname( __FILE__ ) ); - $local_vendor = $base_path . '/vendor/bin/phpcs'; - $package_dir_vendor = dirname( dirname( $base_path ) ) . '/bin/phpcs'; - if ( file_exists( $local_vendor ) ) { - $phpcs_exec = self::get_php_binary() . ' ' . $local_vendor; - } elseif( $package_dir_vendor ) { - $phpcs_exec = self::get_php_binary() . ' ' . $package_dir_vendor; - } - - if ( ! $phpcs_exec ) { - WP_CLI::error( "Couldn't find phpcs executable." ); - } + $phpcs_exec = self::get_phpcs_exec(); $base_check = $phpcs_exec . ' --standard=PHPCompatibility --runtime-set testVersion ' . escapeshellarg( $php_version ) . ' --extensions=php --ignore=/node_modules/,/bower_components/,/svn/ --parallel=4 --report=json'; $start_time = microtime( true ); @@ -265,6 +254,23 @@ private static function scan_extension( $extension, $php_version ) { return $result; } + private static function get_phpcs_exec() { + $phpcs_exec = false; + $base_path = dirname( dirname( __FILE__ ) ); + $local_vendor = $base_path . '/vendor/bin/phpcs'; + $package_dir_vendor = dirname( dirname( $base_path ) ) . '/bin/phpcs'; + if ( file_exists( $local_vendor ) ) { + $phpcs_exec = self::get_php_binary() . ' ' . $local_vendor; + } elseif( $package_dir_vendor ) { + $phpcs_exec = self::get_php_binary() . ' ' . $package_dir_vendor; + } + + if ( ! $phpcs_exec ) { + WP_CLI::error( "Couldn't find phpcs executable." ); + } + return $phpcs_exec; + } + private static function get_php_binary() { if ( getenv( 'WP_CLI_PHP_USED' ) ) return getenv( 'WP_CLI_PHP_USED' );