Skip to content

Config: can use custom LocalFile object #785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -138,6 +139,7 @@ class Config
'generator' => null,
'filter' => null,
'bootstrap' => null,
'localFile' => null,
'reports' => null,
'basepath' => null,
'reportWidth' => null,
Expand Down Expand Up @@ -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';
Expand Down
12 changes: 11 additions & 1 deletion src/Files/FileList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
Loading