diff --git a/src/Psalm/Config/FileFilter.php b/src/Psalm/Config/FileFilter.php
index 07e8cb1a1f4..56ca9f68e7d 100644
--- a/src/Psalm/Config/FileFilter.php
+++ b/src/Psalm/Config/FileFilter.php
@@ -111,12 +111,8 @@ public static function loadFromArray(
/** @var array $directory */
foreach ($config['directory'] as $directory) {
$directory_path = (string) ($directory['name'] ?? '');
- $ignore_type_stats = strtolower(
- isset($directory['ignoreTypeStats']) ? (string) $directory['ignoreTypeStats'] : ''
- ) === 'true';
- $declare_strict_types = strtolower(
- isset($directory['useStrictTypes']) ? (string) $directory['useStrictTypes'] : ''
- ) === 'true';
+ $ignore_type_stats = (bool) ($directory['ignoreTypeStats'] ?? false);
+ $declare_strict_types = (bool) ($directory['useStrictTypes'] ?? false);
if ($directory_path[0] === '/' && DIRECTORY_SEPARATOR === '/') {
$prospective_directory_path = $directory_path;
@@ -350,13 +346,8 @@ public static function loadFromXMLElement(
foreach ($e->directory as $directory) {
$config['directory'][] = [
'name' => (string) $directory['name'],
- 'ignoreTypeStats' => strtolower(
- isset($directory['ignoreTypeStats']) ? (string) $directory['ignoreTypeStats'] : ''
- ) === 'true',
-
- 'useStrictTypes' => strtolower(
- isset($directory['useStrictTypes']) ? (string) $directory['useStrictTypes'] : ''
- ) === 'true',
+ 'ignoreTypeStats' => strtolower((string) ($directory['ignoreTypeStats'] ?? '')) === 'true',
+ 'useStrictTypes' => strtolower((string) ($directory['useStrictTypes'] ?? '')) === 'true',
];
}
}
diff --git a/tests/Config/ConfigTest.php b/tests/Config/ConfigTest.php
index 9db727e9e3d..ed55e000f87 100644
--- a/tests/Config/ConfigTest.php
+++ b/tests/Config/ConfigTest.php
@@ -1483,4 +1483,70 @@ public function pluginRegistersScannerAndAnalyzer(int $flags, ?int $expectedExce
self::assertSame(get_class($analyzerMock), $config->getFiletypeAnalyzers()[$extension] ?? null);
self::assertNull($expectedExceptionCode, 'Expected exception code was not thrown');
}
+
+ public function testTypeStatsForFileReporting(): void
+ {
+ $this->project_analyzer = $this->getProjectAnalyzerWithConfig(
+ Config::loadFromXML(
+ (string) getcwd(),
+ '
+
+
+
+
+
+
+
+
+
+
+
+ '
+ )
+ );
+
+ $config = $this->project_analyzer->getConfig();
+
+ $this->assertFalse($config->reportTypeStatsForFile(realpath('src/Psalm/Config') . DIRECTORY_SEPARATOR));
+ $this->assertTrue($config->reportTypeStatsForFile(realpath('src/Psalm/Internal') . DIRECTORY_SEPARATOR));
+ $this->assertTrue($config->reportTypeStatsForFile(realpath('src/Psalm/Issue') . DIRECTORY_SEPARATOR));
+ $this->assertTrue($config->reportTypeStatsForFile(realpath('src/Psalm/Node') . DIRECTORY_SEPARATOR));
+ $this->assertTrue($config->reportTypeStatsForFile(realpath('src/Psalm/Plugin') . DIRECTORY_SEPARATOR));
+ $this->assertTrue($config->reportTypeStatsForFile(realpath('src/Psalm/Progress') . DIRECTORY_SEPARATOR));
+ $this->assertTrue($config->reportTypeStatsForFile(realpath('src/Psalm/Report') . DIRECTORY_SEPARATOR));
+ $this->assertTrue($config->reportTypeStatsForFile(realpath('src/Psalm/SourceControl') . DIRECTORY_SEPARATOR));
+ }
+
+ public function testStrictTypesForFileReporting(): void
+ {
+ $this->project_analyzer = $this->getProjectAnalyzerWithConfig(
+ Config::loadFromXML(
+ (string) getcwd(),
+ '
+
+
+
+
+
+
+
+
+
+
+
+ '
+ )
+ );
+
+ $config = $this->project_analyzer->getConfig();
+
+ $this->assertTrue($config->useStrictTypesForFile(realpath('src/Psalm/Config') . DIRECTORY_SEPARATOR));
+ $this->assertFalse($config->useStrictTypesForFile(realpath('src/Psalm/Internal') . DIRECTORY_SEPARATOR));
+ $this->assertFalse($config->useStrictTypesForFile(realpath('src/Psalm/Issue') . DIRECTORY_SEPARATOR));
+ $this->assertFalse($config->useStrictTypesForFile(realpath('src/Psalm/Node') . DIRECTORY_SEPARATOR));
+ $this->assertFalse($config->useStrictTypesForFile(realpath('src/Psalm/Plugin') . DIRECTORY_SEPARATOR));
+ $this->assertFalse($config->useStrictTypesForFile(realpath('src/Psalm/Progress') . DIRECTORY_SEPARATOR));
+ $this->assertFalse($config->useStrictTypesForFile(realpath('src/Psalm/Report') . DIRECTORY_SEPARATOR));
+ $this->assertFalse($config->useStrictTypesForFile(realpath('src/Psalm/SourceControl') . DIRECTORY_SEPARATOR));
+ }
}