Skip to content
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

Fix additional places where base_dir was broken due to missing separator #10630

Merged
merged 9 commits into from
Feb 5, 2024
26 changes: 13 additions & 13 deletions dictionaries/CallMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@
'DirectoryIterator::getPathInfo' => ['?SplFileInfo', 'class='=>'?class-string'],
'DirectoryIterator::getPathname' => ['string'],
'DirectoryIterator::getPerms' => ['int'],
'DirectoryIterator::getRealPath' => ['string'],
'DirectoryIterator::getRealPath' => ['non-falsy-string'],
'DirectoryIterator::getSize' => ['int'],
'DirectoryIterator::getType' => ['string'],
'DirectoryIterator::isDir' => ['bool'],
Expand Down Expand Up @@ -2792,7 +2792,7 @@
'file' => ['list<string>|false', 'filename'=>'string', 'flags='=>'int', 'context='=>'resource'],
'file_exists' => ['bool', 'filename'=>'string'],
'file_get_contents' => ['string|false', 'filename'=>'string', 'use_include_path='=>'bool', 'context='=>'?resource', 'offset='=>'int', 'length='=>'?int'],
'file_put_contents' => ['int|false', 'filename'=>'string', 'data'=>'string|resource|array<string>', 'flags='=>'int', 'context='=>'resource'],
'file_put_contents' => ['int<0, max>|false', 'filename'=>'string', 'data'=>'string|resource|array<string>', 'flags='=>'int', 'context='=>'resource'],
'fileatime' => ['int|false', 'filename'=>'string'],
'filectime' => ['int|false', 'filename'=>'string'],
'filegroup' => ['int|false', 'filename'=>'string'],
Expand Down Expand Up @@ -2827,7 +2827,7 @@
'FilesystemIterator::getPathInfo' => ['?SplFileInfo', 'class='=>'?class-string'],
'FilesystemIterator::getPathname' => ['string'],
'FilesystemIterator::getPerms' => ['int'],
'FilesystemIterator::getRealPath' => ['string'],
'FilesystemIterator::getRealPath' => ['non-falsy-string'],
'FilesystemIterator::getSize' => ['int'],
'FilesystemIterator::getType' => ['string'],
'FilesystemIterator::isDir' => ['bool'],
Expand Down Expand Up @@ -3296,7 +3296,7 @@
'get_resource_type' => ['string', 'resource'=>'resource'],
'get_resources' => ['array<int,resource>', 'type='=>'?string'],
'getallheaders' => ['array|false'],
'getcwd' => ['string|false'],
'getcwd' => ['non-falsy-string|false'],
'getdate' => ['array{seconds: int<0, 59>, minutes: int<0, 59>, hours: int<0, 23>, mday: int<1, 31>, wday: int<0, 6>, mon: int<1, 12>, year: int, yday: int<0, 365>, weekday: "Monday"|"Tuesday"|"Wednesday"|"Thursday"|"Friday"|"Saturday"|"Sunday", month: "January"|"February"|"March"|"April"|"May"|"June"|"July"|"August"|"September"|"October"|"November"|"December", 0: int}', 'timestamp='=>'?int'],
'getenv' => ['string|false', 'name'=>'string', 'local_only='=>'bool'],
'getenv\'1' => ['array<string,string>'],
Expand Down Expand Up @@ -3343,7 +3343,7 @@
'GlobIterator::getPathInfo' => ['?SplFileInfo', 'class='=>'?class-string'],
'GlobIterator::getPathname' => ['string'],
'GlobIterator::getPerms' => ['int'],
'GlobIterator::getRealPath' => ['string|false'],
'GlobIterator::getRealPath' => ['non-falsy-string|false'],
'GlobIterator::getSize' => ['int'],
'GlobIterator::getType' => ['string|false'],
'GlobIterator::isDir' => ['bool'],
Expand Down Expand Up @@ -9722,8 +9722,8 @@
'readline_read_history' => ['bool', 'filename='=>'?string'],
'readline_redisplay' => ['void'],
'readline_write_history' => ['bool', 'filename='=>'?string'],
'readlink' => ['string|false', 'path'=>'string'],
'realpath' => ['string|false', 'path'=>'string'],
'readlink' => ['non-falsy-string|false', 'path'=>'string'],
'realpath' => ['non-falsy-string|false', 'path'=>'string'],
'realpath_cache_get' => ['array'],
'realpath_cache_size' => ['int'],
'recode' => ['string', 'request'=>'string', 'string'=>'string'],
Expand Down Expand Up @@ -9811,7 +9811,7 @@
'RecursiveDirectoryIterator::getPathInfo' => ['?SplFileInfo', 'class='=>'?class-string'],
'RecursiveDirectoryIterator::getPathname' => ['string'],
'RecursiveDirectoryIterator::getPerms' => ['int'],
'RecursiveDirectoryIterator::getRealPath' => ['string'],
'RecursiveDirectoryIterator::getRealPath' => ['non-falsy-string'],
'RecursiveDirectoryIterator::getSize' => ['int'],
'RecursiveDirectoryIterator::getSubPath' => ['string'],
'RecursiveDirectoryIterator::getSubPathname' => ['string'],
Expand Down Expand Up @@ -12238,7 +12238,7 @@
'SplFileInfo::getPathInfo' => ['SplFileInfo|null', 'class='=>'?class-string'],
'SplFileInfo::getPathname' => ['string'],
'SplFileInfo::getPerms' => ['int|false'],
'SplFileInfo::getRealPath' => ['string|false'],
'SplFileInfo::getRealPath' => ['non-falsy-string|false'],
'SplFileInfo::getSize' => ['int|false'],
'SplFileInfo::getType' => ['string|false'],
'SplFileInfo::isDir' => ['bool'],
Expand Down Expand Up @@ -12288,7 +12288,7 @@
'SplFileObject::getPathInfo' => ['SplFileInfo|null', 'class='=>'?class-string'],
'SplFileObject::getPathname' => ['string'],
'SplFileObject::getPerms' => ['int|false'],
'SplFileObject::getRealPath' => ['false|string'],
'SplFileObject::getRealPath' => ['false|non-falsy-string'],
'SplFileObject::getSize' => ['int|false'],
'SplFileObject::getType' => ['string|false'],
'SplFileObject::hasChildren' => ['false'],
Expand Down Expand Up @@ -12475,7 +12475,7 @@
'SplTempFileObject::getPathInfo' => ['SplFileInfo|null', 'class='=>'?class-string'],
'SplTempFileObject::getPathname' => ['string'],
'SplTempFileObject::getPerms' => ['int|false'],
'SplTempFileObject::getRealPath' => ['false|string'],
'SplTempFileObject::getRealPath' => ['false|non-falsy-string'],
'SplTempFileObject::getSize' => ['int|false'],
'SplTempFileObject::getType' => ['string|false'],
'SplTempFileObject::hasChildren' => ['false'],
Expand Down Expand Up @@ -12690,8 +12690,8 @@
'ssh2_sftp_chmod' => ['bool', 'sftp'=>'resource', 'filename'=>'string', 'mode'=>'int'],
'ssh2_sftp_lstat' => ['array{0: int, 1: int, 2: int, 3: int, 4: int, 5: int, 6: int, 7: int, 8: int, 9: int, 10: int, 11: int, 12: int, dev: int, ino: int, mode: int, nlink: int, uid: int, gid: int, rdev: int, size: int, atime: int, mtime: int, ctime: int, blksize: int, blocks: int}|false', 'sftp'=>'resource', 'path'=>'string'],
'ssh2_sftp_mkdir' => ['bool', 'sftp'=>'resource', 'dirname'=>'string', 'mode='=>'int', 'recursive='=>'bool'],
'ssh2_sftp_readlink' => ['string|false', 'sftp'=>'resource', 'link'=>'string'],
'ssh2_sftp_realpath' => ['string|false', 'sftp'=>'resource', 'filename'=>'string'],
'ssh2_sftp_readlink' => ['non-falsy-string|false', 'sftp'=>'resource', 'link'=>'string'],
'ssh2_sftp_realpath' => ['non-falsy-string|false', 'sftp'=>'resource', 'filename'=>'string'],
'ssh2_sftp_rename' => ['bool', 'sftp'=>'resource', 'from'=>'string', 'to'=>'string'],
'ssh2_sftp_rmdir' => ['bool', 'sftp'=>'resource', 'dirname'=>'string'],
'ssh2_sftp_stat' => ['array{0: int, 1: int, 2: int, 3: int, 4: int, 5: int, 6: int, 7: int, 8: int, 9: int, 10: int, 11: int, 12: int, dev: int, ino: int, mode: int, nlink: int, uid: int, gid: int, rdev: int, size: int, atime: int, mtime: int, ctime: int, blksize: int, blocks: int}|false', 'sftp'=>'resource', 'path'=>'string'],
Expand Down
26 changes: 13 additions & 13 deletions dictionaries/CallMap_historical.php
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@
'DirectoryIterator::getPathInfo' => ['?SplFileInfo', 'class='=>'class-string'],
'DirectoryIterator::getPathname' => ['string'],
'DirectoryIterator::getPerms' => ['int'],
'DirectoryIterator::getRealPath' => ['string'],
'DirectoryIterator::getRealPath' => ['non-falsy-string'],
'DirectoryIterator::getSize' => ['int'],
'DirectoryIterator::getType' => ['string'],
'DirectoryIterator::isDir' => ['bool'],
Expand Down Expand Up @@ -1507,7 +1507,7 @@
'FilesystemIterator::getPathInfo' => ['?SplFileInfo', 'class='=>'class-string'],
'FilesystemIterator::getPathname' => ['string'],
'FilesystemIterator::getPerms' => ['int'],
'FilesystemIterator::getRealPath' => ['string'],
'FilesystemIterator::getRealPath' => ['non-falsy-string'],
'FilesystemIterator::getSize' => ['int'],
'FilesystemIterator::getType' => ['string'],
'FilesystemIterator::isDir' => ['bool'],
Expand Down Expand Up @@ -1762,7 +1762,7 @@
'GlobIterator::getPathInfo' => ['?SplFileInfo', 'class='=>'class-string'],
'GlobIterator::getPathname' => ['string'],
'GlobIterator::getPerms' => ['int'],
'GlobIterator::getRealPath' => ['string|false'],
'GlobIterator::getRealPath' => ['non-falsy-string|false'],
'GlobIterator::getSize' => ['int'],
'GlobIterator::getType' => ['string|false'],
'GlobIterator::isDir' => ['bool'],
Expand Down Expand Up @@ -5155,7 +5155,7 @@
'RecursiveDirectoryIterator::getPathInfo' => ['?SplFileInfo', 'class='=>'class-string'],
'RecursiveDirectoryIterator::getPathname' => ['string'],
'RecursiveDirectoryIterator::getPerms' => ['int'],
'RecursiveDirectoryIterator::getRealPath' => ['string'],
'RecursiveDirectoryIterator::getRealPath' => ['non-falsy-string'],
'RecursiveDirectoryIterator::getSize' => ['int'],
'RecursiveDirectoryIterator::getSubPath' => ['string'],
'RecursiveDirectoryIterator::getSubPathname' => ['string'],
Expand Down Expand Up @@ -7481,7 +7481,7 @@
'SplFileInfo::getPathInfo' => ['SplFileInfo|null', 'class='=>'class-string'],
'SplFileInfo::getPathname' => ['string'],
'SplFileInfo::getPerms' => ['int|false'],
'SplFileInfo::getRealPath' => ['string|false'],
'SplFileInfo::getRealPath' => ['non-falsy-string|false'],
'SplFileInfo::getSize' => ['int|false'],
'SplFileInfo::getType' => ['string|false'],
'SplFileInfo::isDir' => ['bool'],
Expand Down Expand Up @@ -7532,7 +7532,7 @@
'SplFileObject::getPathInfo' => ['SplFileInfo|null', 'class='=>'class-string'],
'SplFileObject::getPathname' => ['string'],
'SplFileObject::getPerms' => ['int|false'],
'SplFileObject::getRealPath' => ['false|string'],
'SplFileObject::getRealPath' => ['false|non-falsy-string'],
'SplFileObject::getSize' => ['int|false'],
'SplFileObject::getType' => ['string|false'],
'SplFileObject::hasChildren' => ['false'],
Expand Down Expand Up @@ -7723,7 +7723,7 @@
'SplTempFileObject::getPathInfo' => ['SplFileInfo|null', 'class='=>'class-string'],
'SplTempFileObject::getPathname' => ['string'],
'SplTempFileObject::getPerms' => ['int|false'],
'SplTempFileObject::getRealPath' => ['false|string'],
'SplTempFileObject::getRealPath' => ['false|non-falsy-string'],
'SplTempFileObject::getSize' => ['int|false'],
'SplTempFileObject::getType' => ['string|false'],
'SplTempFileObject::hasChildren' => ['false'],
Expand Down Expand Up @@ -10417,7 +10417,7 @@
'file' => ['list<string>|false', 'filename'=>'string', 'flags='=>'int', 'context='=>'resource'],
'file_exists' => ['bool', 'filename'=>'string'],
'file_get_contents' => ['string|false', 'filename'=>'string', 'use_include_path='=>'bool', 'context='=>'?resource', 'offset='=>'int', 'length='=>'int'],
'file_put_contents' => ['int|false', 'filename'=>'string', 'data'=>'string|resource|array<string>', 'flags='=>'int', 'context='=>'resource'],
'file_put_contents' => ['int<0, max>|false', 'filename'=>'string', 'data'=>'string|resource|array<string>', 'flags='=>'int', 'context='=>'resource'],
'fileatime' => ['int|false', 'filename'=>'string'],
'filectime' => ['int|false', 'filename'=>'string'],
'filegroup' => ['int|false', 'filename'=>'string'],
Expand Down Expand Up @@ -10661,7 +10661,7 @@
'get_resource_type' => ['string', 'resource'=>'resource'],
'get_resources' => ['array<int,resource>', 'type='=>'string'],
'getallheaders' => ['array|false'],
'getcwd' => ['string|false'],
'getcwd' => ['non-falsy-string|false'],
'getdate' => ['array{seconds: int<0, 59>, minutes: int<0, 59>, hours: int<0, 23>, mday: int<1, 31>, wday: int<0, 6>, mon: int<1, 12>, year: int, yday: int<0, 365>, weekday: "Monday"|"Tuesday"|"Wednesday"|"Thursday"|"Friday"|"Saturday"|"Sunday", month: "January"|"February"|"March"|"April"|"May"|"June"|"July"|"August"|"September"|"October"|"November"|"December", 0: int}', 'timestamp='=>'int'],
'getenv' => ['string|false', 'name'=>'string', 'local_only='=>'bool'],
'gethostbyaddr' => ['string|false', 'ip'=>'string'],
Expand Down Expand Up @@ -13718,8 +13718,8 @@
'readline_read_history' => ['bool', 'filename='=>'string'],
'readline_redisplay' => ['void'],
'readline_write_history' => ['bool', 'filename='=>'string'],
'readlink' => ['string|false', 'path'=>'string'],
'realpath' => ['string|false', 'path'=>'string'],
'readlink' => ['non-falsy-string|false', 'path'=>'string'],
'realpath' => ['non-falsy-string|false', 'path'=>'string'],
'realpath_cache_get' => ['array'],
'realpath_cache_size' => ['int'],
'recode' => ['string', 'request'=>'string', 'string'=>'string'],
Expand Down Expand Up @@ -14120,8 +14120,8 @@
'ssh2_sftp_chmod' => ['bool', 'sftp'=>'resource', 'filename'=>'string', 'mode'=>'int'],
'ssh2_sftp_lstat' => ['array{0: int, 1: int, 2: int, 3: int, 4: int, 5: int, 6: int, 7: int, 8: int, 9: int, 10: int, 11: int, 12: int, dev: int, ino: int, mode: int, nlink: int, uid: int, gid: int, rdev: int, size: int, atime: int, mtime: int, ctime: int, blksize: int, blocks: int}|false', 'sftp'=>'resource', 'path'=>'string'],
'ssh2_sftp_mkdir' => ['bool', 'sftp'=>'resource', 'dirname'=>'string', 'mode='=>'int', 'recursive='=>'bool'],
'ssh2_sftp_readlink' => ['string|false', 'sftp'=>'resource', 'link'=>'string'],
'ssh2_sftp_realpath' => ['string|false', 'sftp'=>'resource', 'filename'=>'string'],
'ssh2_sftp_readlink' => ['non-falsy-string|false', 'sftp'=>'resource', 'link'=>'string'],
'ssh2_sftp_realpath' => ['non-falsy-string|false', 'sftp'=>'resource', 'filename'=>'string'],
'ssh2_sftp_rename' => ['bool', 'sftp'=>'resource', 'from'=>'string', 'to'=>'string'],
'ssh2_sftp_rmdir' => ['bool', 'sftp'=>'resource', 'dirname'=>'string'],
'ssh2_sftp_stat' => ['array{0: int, 1: int, 2: int, 3: int, 4: int, 5: int, 6: int, 7: int, 8: int, 9: int, 10: int, 11: int, 12: int, dev: int, ino: int, mode: int, nlink: int, uid: int, gid: int, rdev: int, size: int, atime: int, mtime: int, ctime: int, blksize: int, blocks: int}|false', 'sftp'=>'resource', 'path'=>'string'],
Expand Down
12 changes: 6 additions & 6 deletions src/Psalm/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class Config
protected $extra_files;

/**
* The base directory of this config file
* The base directory of this config file without trailing slash
*
* @var string
*/
Expand Down Expand Up @@ -1445,7 +1445,7 @@ private static function fromXmlAndPaths(
if (!$file_path) {
throw new ConfigException(
'Cannot resolve stubfile path '
. rtrim($config->base_dir, DIRECTORY_SEPARATOR)
. $config->base_dir
. DIRECTORY_SEPARATOR
. $stub_file['name'],
);
Expand Down Expand Up @@ -1582,11 +1582,11 @@ public function safeSetCustomErrorLevel(string $issue_key, string $error_level):
private function loadFileExtensions(SimpleXMLElement $extensions): void
{
foreach ($extensions as $extension) {
$extension_name = preg_replace('/^\.?/', '', (string)$extension['name'], 1);
$extension_name = preg_replace('/^\.?/', '', (string) $extension['name'], 1);
$this->file_extensions[] = $extension_name;

if (isset($extension['scanner'])) {
$path = $this->base_dir . (string)$extension['scanner'];
$path = $this->base_dir . DIRECTORY_SEPARATOR . (string) $extension['scanner'];

if (!file_exists($path)) {
throw new ConfigException('Error parsing config: cannot find file ' . $path);
Expand All @@ -1596,7 +1596,7 @@ private function loadFileExtensions(SimpleXMLElement $extensions): void
}

if (isset($extension['checker'])) {
$path = $this->base_dir . (string)$extension['checker'];
$path = $this->base_dir . DIRECTORY_SEPARATOR . (string) $extension['checker'];

if (!file_exists($path)) {
throw new ConfigException('Error parsing config: cannot find file ' . $path);
Expand Down Expand Up @@ -1817,7 +1817,7 @@ private function getPluginClassForPath(Codebase $codebase, string $path, string
public function shortenFileName(string $to): string
{
if (!is_file($to)) {
return preg_replace('/^' . preg_quote($this->base_dir, '/') . '/', '', $to, 1);
return preg_replace('/^' . preg_quote($this->base_dir . DIRECTORY_SEPARATOR, '/') . '?/', '', $to, 1);
kkmuffme marked this conversation as resolved.
Show resolved Hide resolved
}

$from = $this->base_dir;
Expand Down
6 changes: 3 additions & 3 deletions src/Psalm/Internal/Cli/LanguageServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,20 @@ static function (string $arg) use ($valid_long_options): void {
$options['r'] = $options['root'];
}

$current_dir = (string)getcwd() . DIRECTORY_SEPARATOR;
$current_dir = (string) getcwd();

if (isset($options['r']) && is_string($options['r'])) {
$root_path = realpath($options['r']);

if (!$root_path) {
if ($root_path === false) {
fwrite(
STDERR,
'Could not locate root directory ' . $current_dir . DIRECTORY_SEPARATOR . $options['r'] . PHP_EOL,
);
exit(1);
}

$current_dir = $root_path . DIRECTORY_SEPARATOR;
$current_dir = $root_path;
}

$vendor_dir = CliUtils::getVendorDir($current_dir);
Expand Down
6 changes: 2 additions & 4 deletions src/Psalm/Internal/Cli/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
use function dirname;
use function getcwd;

use const DIRECTORY_SEPARATOR;

// phpcs:disable PSR1.Files.SideEffects

require_once __DIR__ . '/../CliUtils.php';
Expand All @@ -27,13 +25,13 @@ final class Plugin
public static function run(): void
{
CliUtils::checkRuntimeRequirements();
$current_dir = (string)getcwd() . DIRECTORY_SEPARATOR;
$current_dir = (string) getcwd();
$vendor_dir = CliUtils::getVendorDir($current_dir);
CliUtils::requireAutoloaders($current_dir, false, $vendor_dir);

$app = new Application('psalm-plugin', PSALM_VERSION);

$psalm_root = dirname(__DIR__, 4) . DIRECTORY_SEPARATOR;
$psalm_root = dirname(__DIR__, 4);

$plugin_list_factory = new PluginListFactory($current_dir, $psalm_root);

Expand Down
Loading
Loading