1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00

Replace remaining POSIX only absolute path detection

These were missed in #10441. Fixes "Could not resolve config path" error on Windows (#10418).
This commit is contained in:
Theodore Brown 2023-12-06 11:20:18 -06:00
parent c620f6e80d
commit b5ee6e0d8b
4 changed files with 7 additions and 24 deletions

View File

@ -1315,7 +1315,7 @@ class Config
} }
// we need an absolute path for checks // we need an absolute path for checks
if ($path[0] !== '/' && DIRECTORY_SEPARATOR === '/') { if (Path::isRelative($path)) {
$prospective_path = $base_dir . DIRECTORY_SEPARATOR . $path; $prospective_path = $base_dir . DIRECTORY_SEPARATOR . $path;
} else { } else {
$prospective_path = $path; $prospective_path = $path;

View File

@ -247,7 +247,7 @@ class FileFilter
foreach ($config['file'] as $file) { foreach ($config['file'] as $file) {
$file_path = (string) ($file['name'] ?? ''); $file_path = (string) ($file['name'] ?? '');
if ($file_path[0] === '/' && DIRECTORY_SEPARATOR === '/') { if (Path::isAbsolute($file_path)) {
/** @var non-empty-string */ /** @var non-empty-string */
$prospective_file_path = $file_path; $prospective_file_path = $file_path;
} else { } else {

View File

@ -20,6 +20,7 @@ use Psalm\Issue\UnresolvableInclude;
use Psalm\IssueBuffer; use Psalm\IssueBuffer;
use Psalm\Plugin\EventHandler\Event\AddRemoveTaintsEvent; use Psalm\Plugin\EventHandler\Event\AddRemoveTaintsEvent;
use Psalm\Type\TaintKind; use Psalm\Type\TaintKind;
use Symfony\Component\Filesystem\Path;
use function constant; use function constant;
use function defined; use function defined;
@ -93,13 +94,7 @@ final class IncludeAnalyzer
$include_path = self::resolveIncludePath($path_to_file, dirname($statements_analyzer->getFilePath())); $include_path = self::resolveIncludePath($path_to_file, dirname($statements_analyzer->getFilePath()));
$path_to_file = $include_path ?: $path_to_file; $path_to_file = $include_path ?: $path_to_file;
if (DIRECTORY_SEPARATOR === '/') { if (Path::isRelative($path_to_file)) {
$is_path_relative = $path_to_file[0] !== DIRECTORY_SEPARATOR;
} else {
$is_path_relative = !preg_match('~^[A-Z]:\\\\~i', $path_to_file);
}
if ($is_path_relative) {
$path_to_file = $config->base_dir . DIRECTORY_SEPARATOR . $path_to_file; $path_to_file = $config->base_dir . DIRECTORY_SEPARATOR . $path_to_file;
} }
} else { } else {
@ -285,13 +280,7 @@ final class IncludeAnalyzer
string $file_name, string $file_name,
Config $config Config $config
): ?string { ): ?string {
if (DIRECTORY_SEPARATOR === '/') { if (Path::isRelative($file_name)) {
$is_path_relative = $file_name[0] !== DIRECTORY_SEPARATOR;
} else {
$is_path_relative = !preg_match('~^[A-Z]:\\\\~i', $file_name);
}
if ($is_path_relative) {
$file_name = $config->base_dir . DIRECTORY_SEPARATOR . $file_name; $file_name = $config->base_dir . DIRECTORY_SEPARATOR . $file_name;
} }

View File

@ -20,13 +20,13 @@ use Psalm\Internal\Scanner\FileScanner;
use Psalm\Storage\FileStorage; use Psalm\Storage\FileStorage;
use Psalm\Storage\FunctionLikeStorage; use Psalm\Storage\FunctionLikeStorage;
use Psalm\Type; use Psalm\Type;
use Symfony\Component\Filesystem\Path;
use function assert; use function assert;
use function defined; use function defined;
use function dirname; use function dirname;
use function explode; use function explode;
use function in_array; use function in_array;
use function preg_match;
use function strpos; use function strpos;
use function strtolower; use function strtolower;
use function substr; use function substr;
@ -316,13 +316,7 @@ final class ExpressionScanner
$include_path = IncludeAnalyzer::resolveIncludePath($path_to_file, dirname($file_storage->file_path)); $include_path = IncludeAnalyzer::resolveIncludePath($path_to_file, dirname($file_storage->file_path));
$path_to_file = $include_path ?: $path_to_file; $path_to_file = $include_path ?: $path_to_file;
if (DIRECTORY_SEPARATOR === '/') { if (Path::isRelative($path_to_file)) {
$is_path_relative = $path_to_file[0] !== DIRECTORY_SEPARATOR;
} else {
$is_path_relative = !preg_match('~^[A-Z]:\\\\~i', $path_to_file);
}
if ($is_path_relative) {
$path_to_file = $config->base_dir . DIRECTORY_SEPARATOR . $path_to_file; $path_to_file = $config->base_dir . DIRECTORY_SEPARATOR . $path_to_file;
} }
} else { } else {