Skip to content

Commit

Permalink
Fix #3618 - add way to load non-analyzed files
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jun 19, 2020
1 parent eecdc43 commit 078b8b7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions config.xsd
Expand Up @@ -10,6 +10,7 @@
<xs:complexType name="PsalmType">
<xs:choice maxOccurs="unbounded">
<xs:element name="projectFiles" type="ProjectFilesType" minOccurs="1" maxOccurs="1" />
<xs:element name="extraFiles" type="ProjectFilesType" minOccurs="0" maxOccurs="1" />
<xs:element name="taintAnalysis" type="TaintAnalysisType" minOccurs="0" maxOccurs="1" />
<xs:element name="fileExtensions" type="FileExtensionsType" minOccurs="0" maxOccurs="1" />
<xs:element name="mockClasses" type="MockClassesType" minOccurs="0" maxOccurs="1" />
Expand Down
31 changes: 31 additions & 0 deletions src/Psalm/Config.php
Expand Up @@ -183,6 +183,11 @@ class Config
*/
protected $project_files;

/**
* @var ProjectFileFilter|null
*/
protected $extra_files;

/**
* The base directory of this config file
*
Expand Down Expand Up @@ -908,6 +913,10 @@ private static function fromXmlAndPaths(string $base_dir, string $file_contents,
$config->project_files = ProjectFileFilter::loadFromXMLElement($config_xml->projectFiles, $base_dir, true);
}

if (isset($config_xml->extraFiles)) {
$config->extra_files = ProjectFileFilter::loadFromXMLElement($config_xml->extraFiles, $base_dir, true);
}

if (isset($config_xml->taintAnalysis->ignoreFiles)) {
$config->taint_analysis_ignored_files = TaintAnalysisFileFilter::loadFromXMLElement(
$config_xml->taintAnalysis->ignoreFiles,
Expand Down Expand Up @@ -1361,6 +1370,16 @@ public function isInProjectDirs($file_path)
return $this->project_files && $this->project_files->allows($file_path);
}

/**
* @param string $file_path
*
* @return bool
*/
public function isInExtraDirs($file_path)
{
return $this->extra_files && $this->extra_files->allows($file_path);
}

/**
* @param string $file_path
*
Expand Down Expand Up @@ -1630,6 +1649,18 @@ public function getProjectFiles()
return $this->project_files->getFiles();
}

/**
* @return array<string>
*/
public function getExtraDirectories()
{
if (!$this->extra_files) {
return [];
}

return $this->extra_files->getDirectories();
}

/**
* @param string $file_path
*
Expand Down
24 changes: 22 additions & 2 deletions src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Expand Up @@ -177,6 +177,11 @@ class ProjectAnalyzer
*/
private $project_files = [];

/**
* @var array<string,string>
*/
private $extra_files = [];

/**
* @var array<string, string>
*/
Expand Down Expand Up @@ -267,9 +272,9 @@ public function __construct(
$this->stdout_report_options = $stdout_report_options;
$this->generated_report_options = $generated_report_options;

foreach ($this->config->getProjectDirectories() as $dir_name) {
$file_extensions = $this->config->getFileExtensions();
$file_extensions = $this->config->getFileExtensions();

foreach ($this->config->getProjectDirectories() as $dir_name) {
$file_paths = $this->file_provider->getFilesInDir($dir_name, $file_extensions);

foreach ($file_paths as $file_path) {
Expand All @@ -279,6 +284,16 @@ public function __construct(
}
}

foreach ($this->config->getExtraDirectories() as $dir_name) {
$file_paths = $this->file_provider->getFilesInDir($dir_name, $file_extensions);

foreach ($file_paths as $file_path) {
if ($this->config->isInExtraDirs($file_path)) {
$this->addExtraFile($file_path);
}
}
}

foreach ($this->config->getProjectFiles() as $file_path) {
$this->addProjectFile($file_path);
}
Expand Down Expand Up @@ -548,6 +563,7 @@ public function check($base_dir, $is_diff = false)
) {
$this->visitAutoloadFiles();

$this->codebase->scanner->addFilesToShallowScan($this->extra_files);
$this->codebase->scanner->addFilesToDeepScan($this->project_files);
$this->codebase->analyzer->addFilesToAnalyze($this->project_files);

Expand Down Expand Up @@ -1050,6 +1066,10 @@ public function addProjectFile(string $file_path)
$this->project_files[$file_path] = $file_path;
}

public function addExtraFile(string $file_path) : void
{
$this->extra_files[$file_path] = $file_path;
}

/**
* @param string $dir_name
Expand Down

0 comments on commit 078b8b7

Please sign in to comment.