Skip to content

Commit

Permalink
dont strolower filename, since file names on linux are case sensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmuffme committed May 25, 2022
1 parent 06178d0 commit 278e877
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
11 changes: 5 additions & 6 deletions src/Psalm/Internal/Provider/FakeFileProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use function microtime;
use function strpos;
use function strtolower;

class FakeFileProvider extends FileProvider
{
Expand All @@ -25,8 +24,8 @@ public function fileExists(string $file_path): bool

public function getContents(string $file_path, bool $go_to_source = false): string
{
if (!$go_to_source && isset($this->temp_files[strtolower($file_path)])) {
return $this->temp_files[strtolower($file_path)];
if (!$go_to_source && isset($this->temp_files[$file_path])) {
return $this->temp_files[$file_path];
}

return $this->fake_files[$file_path] ?? parent::getContents($file_path);
Expand All @@ -39,8 +38,8 @@ public function setContents(string $file_path, string $file_contents): void

public function setOpenContents(string $file_path, string $file_contents): void
{
if (isset($this->fake_files[strtolower($file_path)])) {
$this->fake_files[strtolower($file_path)] = $file_contents;
if (isset($this->fake_files[$file_path])) {
$this->fake_files[$file_path] = $file_contents;
}
}

Expand All @@ -66,7 +65,7 @@ public function getFilesInDir(string $dir_path, array $file_extensions, callable
$file_paths = parent::getFilesInDir($dir_path, $file_extensions, $filter);

foreach ($this->fake_files as $file_path => $_) {
if (strpos(strtolower($file_path), strtolower($dir_path)) === 0) {
if (strpos($file_path, $dir_path) === 0) {
$file_paths[] = $file_path;
}
}
Expand Down
42 changes: 18 additions & 24 deletions src/Psalm/Internal/Provider/FileProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,29 @@
use function filemtime;
use function in_array;
use function is_dir;
use function strtolower;

use const DIRECTORY_SEPARATOR;

class FileProvider
{
/**
* @var array<lowercase-string, string>
* @var array<string, string>
*/
protected $temp_files = [];

/**
* @var array<lowercase-string, string>
* @var array<string, string>
*/
protected static $open_files = [];

public function getContents(string $file_path, bool $go_to_source = false): string
{
$file_path_lc = strtolower($file_path);
if (!$go_to_source && isset($this->temp_files[$file_path_lc])) {
return $this->temp_files[$file_path_lc];
if (!$go_to_source && isset($this->temp_files[$file_path])) {
return $this->temp_files[$file_path];
}

if (isset(self::$open_files[$file_path_lc])) {
return self::$open_files[$file_path_lc];
if (isset(self::$open_files[$file_path])) {
return self::$open_files[$file_path];
}

if (!file_exists($file_path)) {
Expand All @@ -52,30 +50,28 @@ public function getContents(string $file_path, bool $go_to_source = false): stri

$file_contents = (string) file_get_contents($file_path);

self::$open_files[$file_path_lc] = $file_contents;
self::$open_files[$file_path] = $file_contents;

return $file_contents;
}

public function setContents(string $file_path, string $file_contents): void
{
$file_path_lc = strtolower($file_path);
if (isset(self::$open_files[$file_path_lc])) {
self::$open_files[$file_path_lc] = $file_contents;
if (isset(self::$open_files[$file_path])) {
self::$open_files[$file_path] = $file_contents;
}

if (isset($this->temp_files[$file_path_lc])) {
$this->temp_files[$file_path_lc] = $file_contents;
if (isset($this->temp_files[$file_path])) {
$this->temp_files[$file_path] = $file_contents;
}

file_put_contents($file_path, $file_contents);
}

public function setOpenContents(string $file_path, string $file_contents): void
{
$file_path_lc = strtolower($file_path);
if (isset(self::$open_files[$file_path_lc])) {
self::$open_files[$file_path_lc] = $file_contents;
if (isset(self::$open_files[$file_path])) {
self::$open_files[$file_path] = $file_contents;
}
}

Expand All @@ -90,29 +86,27 @@ public function getModifiedTime(string $file_path): int

public function addTemporaryFileChanges(string $file_path, string $new_content): void
{
$this->temp_files[strtolower($file_path)] = $new_content;
$this->temp_files[$file_path] = $new_content;
}

public function removeTemporaryFileChanges(string $file_path): void
{
unset($this->temp_files[strtolower($file_path)]);
unset($this->temp_files[$file_path]);
}

public function openFile(string $file_path): void
{
self::$open_files[strtolower($file_path)] = $this->getContents($file_path, true);
self::$open_files[$file_path] = $this->getContents($file_path, true);
}

public function isOpen(string $file_path): bool
{
$file_path_lc = strtolower($file_path);
return isset($this->temp_files[$file_path_lc]) || isset(self::$open_files[$file_path_lc]);
return isset($this->temp_files[$file_path]) || isset(self::$open_files[$file_path]);
}

public function closeFile(string $file_path): void
{
$file_path_lc = strtolower($file_path);
unset($this->temp_files[$file_path_lc], self::$open_files[$file_path_lc]);
unset($this->temp_files[$file_path], self::$open_files[$file_path]);
}

public function fileExists(string $file_path): bool
Expand Down

0 comments on commit 278e877

Please sign in to comment.