From ca103c27780edaaf9bcc97d1d588e5bfe6b7a193 Mon Sep 17 00:00:00 2001 From: Fabien Salathe Date: Mon, 28 Aug 2023 12:29:02 +0900 Subject: [PATCH] Inject the Config in the constructor --- src/Runner.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Runner.php b/src/Runner.php index 2f21edf482..d4318c70d6 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -45,6 +45,20 @@ class Runner */ public $reporter = null; + /** + * @param \PHP_CodeSniffer\Config|null $config Config object + */ + public function __construct($config = null) + { + // Creating the Config object populates it with all required settings + // based on the CLI arguments provided to the script and any config + // values the user has set. + if ($config === null) { + $config = new Config(); + } + $this->config = $config; + }//end __construct() + /** * Run the PHPCS script. @@ -63,11 +77,6 @@ public function runPHPCS() define('PHP_CODESNIFFER_CBF', false); } - // Creating the Config object populates it with all required settings - // based on the CLI arguments provided to the script and any config - // values the user has set. - $this->config = new Config(); - // Init the run and load the rulesets to set additional config vars. $this->init(); @@ -165,11 +174,6 @@ public function runPHPCBF() Util\Timing::startTiming(); Runner::checkRequirements(); - // Creating the Config object populates it with all required settings - // based on the CLI arguments provided to the script and any config - // values the user has set. - $this->config = new Config(); - // When processing STDIN, we can't output anything to the screen // or it will end up mixed in with the file output. if ($this->config->stdin === true) {