Skip to content

Commit 55140d8

Browse files
committed
Do not hardcode the version control backend in the constructor of the PHPCS_Diff class.
1 parent 5027c26 commit 55140d8

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

class-phpcs-diff.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class PHPCS_Diff {
66
private $phpcs_command = 'phpcs'; // You might need to provde a path to phpcs.phar file.
77
private $standards_location = '~/PHP_CodeSniffer/Standards'; // @todo: adjust the path to standards
88

9-
private $diff_parser;
9+
private $version_control;
1010

1111
public $allowed_extensions;
1212

@@ -20,11 +20,9 @@ class PHPCS_Diff {
2020

2121
private $no_diff_to_big = false;
2222

23-
public function __construct() {
23+
public function __construct( $version_control ) {
2424

25-
require_once( __DIR__ . 'class-phpcs-diff-svn.php' );
26-
27-
$this->diff_parser = new PHPCS_Diff_SVN( 'hello-dolly' );
25+
$this->version_control = $version_control;
2826

2927
$this->allowed_extensions = array( 'php', 'js' );
3028
}
@@ -66,7 +64,7 @@ public function run( $repo, $oldest_rev, $newest_rev ) {
6664
}
6765
}
6866

69-
$diff = trim( $this->diff_parser->get_diff( $repo, $newest_rev, $oldest_rev, array( 'ignore-space-change' => true ) ) );
67+
$diff = trim( $this->version_control->get_diff( $repo, $newest_rev, $oldest_rev, array( 'ignore-space-change' => true ) ) );
7068

7169
$this->stop_the_insanity();
7270

@@ -80,7 +78,7 @@ public function run( $repo, $oldest_rev, $newest_rev ) {
8078
return $error;
8179
}
8280

83-
$diff_info = $this->diff_parser->parse_diff_for_info( $diff );
81+
$diff_info = $this->version_control->parse_diff_for_info( $diff );
8482
$file_diffs = $diff_info['file_diffs'];
8583

8684
$found_issues = array();
@@ -156,7 +154,7 @@ private function run_phpcs_for_file_revision( $filename, $revision ) {
156154

157155
if ( false === $result ) {
158156

159-
$result = $this->diff_parser->run_phpcs_for_file_at_revision( $filename, $revision, $this->phpcs_command, $this->standards_location, $this->phpcs_standard );
157+
$result = $this->version_control->run_phpcs_for_file_at_revision( $filename, $revision, $this->phpcs_command, $this->standards_location, $this->phpcs_standard );
160158

161159
if ( true !== $this->nocache ) {
162160
wp_cache_set( $cache_key, $result, $cache_group, 6*HOUR_IN_SECONDS );

wp-cli-command.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ public function __invoke( $args, $assoc_args ) {
5959
$excluded_exts = array_map( 'sanitize_text_field', explode( ',', $assoc_args['excluded-exts'] ) );
6060
}
6161

62-
$phpcs = new PHPCS_Diff();
62+
// @todo: replace SVN version control backend with any other parser you might want to use - eg.: git
63+
require_once( __DIR__ . 'class-phpcs-diff-svn.php' );
64+
$phpcs = new PHPCS_Diff( new PHPCS_Diff_SVN( 'hello-dolly' ) );
65+
6366
if ( true === array_key_exists( 'ignore-diff-too-big', $assoc_args ) ) {
6467
$phpcs->set_no_diff_too_big( true );
6568
}

0 commit comments

Comments
 (0)