diff --git a/src/Config.php b/src/Config.php index 2bcc78e6ec..6a4f0d679b 100644 --- a/src/Config.php +++ b/src/Config.php @@ -52,6 +52,7 @@ * @property string $generator The documentation generator to use. * @property string $filter The filter to use for the run. * @property string[] $bootstrap One of more files to include before the run begins. + * @property string $localFile The LocalFile object to use in FileList. * @property int|string $reportWidth The maximum number of columns that reports should use for output. * Set to "auto" for have this value changed to the width of the terminal. * @property int $errorSeverity The minimum severity an error must have to be displayed. @@ -138,6 +139,7 @@ class Config 'generator' => null, 'filter' => null, 'bootstrap' => null, + 'localFile' => null, 'reports' => null, 'basepath' => null, 'reportWidth' => null, @@ -540,6 +542,7 @@ public function restoreDefaults() $this->generator = null; $this->filter = null; $this->bootstrap = []; + $this->localFile = null; $this->basepath = null; $this->reports = ['full' => null]; $this->reportWidth = 'auto'; diff --git a/src/Files/FileList.php b/src/Files/FileList.php index ab52e33888..70156fdcc4 100644 --- a/src/Files/FileList.php +++ b/src/Files/FileList.php @@ -17,6 +17,7 @@ use PHP_CodeSniffer\Autoload; use PHP_CodeSniffer\Config; use PHP_CodeSniffer\Exceptions\DeepExitException; +use PHP_CodeSniffer\Exceptions\RuntimeException; use PHP_CodeSniffer\Ruleset; use PHP_CodeSniffer\Util\Common; use RecursiveArrayIterator; @@ -194,7 +195,16 @@ public function current() { $path = key($this->files); if (isset($this->files[$path]) === false) { - $this->files[$path] = new LocalFile($path, $this->ruleset, $this->config); + if ($this->config->localFile === null) { + $this->files[$path] = new LocalFile($path, $this->ruleset, $this->config); + } else { + $localFileClass = $this->config->localFile; + if (is_a($localFileClass, '\PHP_CodeSniffer\Files\LocalFile', true) === false) { + throw new RuntimeException('Custom LocalFile class '.$localFileClass.' is not a subtype of PHP_CodeSniffer\Files\LocalFile.'); + } + + $this->files[$path] = new $localFileClass($path, $this->ruleset, $this->config); + } } return $this->files[$path];