Skip to content

Commit 58a7341

Browse files
committed
Config: can use custom LocalFile object
1 parent aebd84b commit 58a7341

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Config.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
* @property string $generator The documentation generator to use.
5353
* @property string $filter The filter to use for the run.
5454
* @property string[] $bootstrap One of more files to include before the run begins.
55+
* @property string $localFile The LocalFile object to use in FileList.
5556
* @property int|string $reportWidth The maximum number of columns that reports should use for output.
5657
* Set to "auto" for have this value changed to the width of the terminal.
5758
* @property int $errorSeverity The minimum severity an error must have to be displayed.
@@ -138,6 +139,7 @@ class Config
138139
'generator' => null,
139140
'filter' => null,
140141
'bootstrap' => null,
142+
'localFile' => null,
141143
'reports' => null,
142144
'basepath' => null,
143145
'reportWidth' => null,
@@ -540,6 +542,7 @@ public function restoreDefaults()
540542
$this->generator = null;
541543
$this->filter = null;
542544
$this->bootstrap = [];
545+
$this->localFile = null;
543546
$this->basepath = null;
544547
$this->reports = ['full' => null];
545548
$this->reportWidth = 'auto';

src/Files/FileList.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use PHP_CodeSniffer\Autoload;
1818
use PHP_CodeSniffer\Config;
1919
use PHP_CodeSniffer\Exceptions\DeepExitException;
20+
use PHP_CodeSniffer\Exceptions\RuntimeException;
2021
use PHP_CodeSniffer\Ruleset;
2122
use PHP_CodeSniffer\Util\Common;
2223
use RecursiveArrayIterator;
@@ -194,7 +195,16 @@ public function current()
194195
{
195196
$path = key($this->files);
196197
if (isset($this->files[$path]) === false) {
197-
$this->files[$path] = new LocalFile($path, $this->ruleset, $this->config);
198+
if ($this->config->localFile === null) {
199+
$this->files[$path] = new LocalFile($path, $this->ruleset, $this->config);
200+
} else {
201+
$localFileClass = $this->config->localFile;
202+
if (is_a($localFileClass, '\PHP_CodeSniffer\Files\LocalFile', true) === false) {
203+
throw new RuntimeException('Custom LocalFile class '.$localFileClass.' is not a subtype of PHP_CodeSniffer\Files\LocalFile.');
204+
}
205+
206+
$this->files[$path] = new $localFileClass($path, $this->ruleset, $this->config);
207+
}
198208
}
199209

200210
return $this->files[$path];

0 commit comments

Comments
 (0)