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 741c32e
Showing 1 changed file with 18 additions and 24 deletions.
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 741c32e

Please sign in to comment.