1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Allow some folders to be excluded from type stats collection

This commit is contained in:
Matt Brown 2018-08-24 17:46:13 -04:00
parent caf65ca8a9
commit 2599d8bd62
5 changed files with 64 additions and 1 deletions

View File

@ -46,7 +46,7 @@
<xs:complexType name="ProjectFilesType">
<xs:choice maxOccurs="unbounded">
<xs:element name="directory" minOccurs="0" maxOccurs="unbounded" type="NameAttributeType" />
<xs:element name="directory" minOccurs="0" maxOccurs="unbounded" type="ProjectDirectoryAttributeType" />
<xs:element name="file" minOccurs="0" maxOccurs="unbounded" type="NameAttributeType" />
<xs:element name="ignoreFiles" minOccurs="0" maxOccurs="1">
<xs:complexType>
@ -63,6 +63,11 @@
<xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>
<xs:complexType name="ProjectDirectoryAttributeType">
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="ignoreTypeStats" type="xs:string" />
</xs:complexType>
<xs:complexType name="FileExtensionsType">
<xs:sequence>
<xs:element name="extension" maxOccurs="unbounded">

View File

@ -306,6 +306,10 @@ class Analyzer
}
foreach ($all_deep_scanned_files as $file_path => $_) {
if (!$this->config->reportTypeStatsForFile($file_path)) {
continue;
}
if (isset($this->mixed_counts[$file_path])) {
list($path_mixed_count, $path_nonmixed_count) = $this->mixed_counts[$file_path];
$mixed_count += $path_mixed_count;
@ -342,6 +346,10 @@ class Analyzer
foreach ($this->files_to_analyze as $file_path => $_) {
$all_deep_scanned_files[$file_path] = true;
if (!$this->config->reportTypeStatsForFile($file_path)) {
continue;
}
foreach ($this->file_storage_provider->get($file_path)->required_file_paths as $required_file_path) {
$all_deep_scanned_files[$required_file_path] = true;
}

View File

@ -983,6 +983,16 @@ class Config
return $this->project_files->getFiles();
}
/**
* @param string $file_path
*
* @return bool
*/
public function reportTypeStatsForFile($file_path)
{
return $this->project_files && $this->project_files->reportTypeStats($file_path);
}
/**
* @return array<string>
*/

View File

@ -40,6 +40,11 @@ class FileFilter
*/
protected $inclusive;
/**
* @var array<string, bool>
*/
protected $ignore_type_stats = [];
/**
* @param bool $inclusive
*
@ -72,6 +77,9 @@ class FileFilter
/** @var \SimpleXMLElement $directory */
foreach ($e->directory as $directory) {
$directory_path = (string) $directory['name'];
$ignore_type_stats = strtolower(
isset($directory['ignoreTypeStats']) ? (string) $directory['ignoreTypeStats'] : ''
) === 'true';
if ($directory_path[0] === '/' && DIRECTORY_SEPARATOR === '/') {
$prospective_directory_path = $directory_path;
@ -100,6 +108,11 @@ class FileFilter
(string)$directory['name'] . ':' . $glob_index . PHP_EOL;
exit(1);
}
if ($ignore_type_stats && $filter instanceof ProjectFileFilter) {
$filter->ignore_type_stats[$directory_path] = true;
}
$filter->addDirectory($directory_path);
}
continue;
@ -113,6 +126,10 @@ class FileFilter
exit(1);
}
if ($ignore_type_stats && $filter instanceof ProjectFileFilter) {
$filter->ignore_type_stats[$directory_path] = true;
}
$filter->addDirectory($directory_path);
}
}

View File

@ -69,4 +69,27 @@ class ProjectFileFilter extends FileFilter
return false;
}
/**
* @param string $file_name
* @param bool $case_sensitive
*
* @return bool
*/
public function reportTypeStats($file_name, $case_sensitive = false)
{
foreach ($this->ignore_type_stats as $exclude_dir => $_) {
if ($case_sensitive) {
if (strpos($file_name, $exclude_dir) === 0) {
return false;
}
} else {
if (stripos($file_name, $exclude_dir) === 0) {
return false;
}
}
}
return true;
}
}