From af23619653c9791e4c5c2f75098c51f8966c1504 Mon Sep 17 00:00:00 2001 From: Tomasz Mlynski Date: Mon, 6 Dec 2021 17:49:40 +0100 Subject: [PATCH 1/6] Fix `ParserCacheProvider::deleteOldParserCaches()` --- src/Psalm/Internal/Provider/ParserCacheProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Provider/ParserCacheProvider.php b/src/Psalm/Internal/Provider/ParserCacheProvider.php index 09543d00af5..df753a08821 100644 --- a/src/Psalm/Internal/Provider/ParserCacheProvider.php +++ b/src/Psalm/Internal/Provider/ParserCacheProvider.php @@ -321,7 +321,7 @@ public function deleteOldParserCaches(float $time_before): int { $cache_directory = Config::getInstance()->getCacheDirectory(); - if ($cache_directory) { + if (!$cache_directory) { return 0; } From 0fcad43581477e276b72b1f77f2bb1e9014b23ea Mon Sep 17 00:00:00 2001 From: Tomasz Mlynski Date: Mon, 6 Dec 2021 17:55:53 +0100 Subject: [PATCH 2/6] Simplify parser cache files maintenance Delete files that were not modified during a no-diff run --- src/Psalm/Internal/Analyzer/ProjectAnalyzer.php | 10 ++-------- src/Psalm/IssueBuffer.php | 4 ---- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index 5844cedb9ae..bce31106c9c 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -684,18 +684,12 @@ public function check(string $base_dir, bool $is_diff = false): void true ); - if ($this->project_cache_provider && $this->parser_cache_provider) { - $removed_parser_files = $this->parser_cache_provider->deleteOldParserCaches( - $is_diff ? $this->project_cache_provider->getLastRun(PSALM_VERSION) : $start_checks - ); + if ($this->project_cache_provider && $this->parser_cache_provider && !$is_diff) { + $removed_parser_files = $this->parser_cache_provider->deleteOldParserCaches($start_checks); if ($removed_parser_files) { $this->progress->debug('Removed ' . $removed_parser_files . ' old parser caches' . "\n"); } - - if ($is_diff) { - $this->parser_cache_provider->touchParserCaches($this->getAllFiles($this->config), $start_checks); - } } } diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index 9d3837e32da..b4857dfccea 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -746,10 +746,6 @@ function (IssueData $d1, IssueData $d2): int { if ($project_analyzer->project_cache_provider) { $project_analyzer->project_cache_provider->processSuccessfulRun($start_time, PSALM_VERSION); } - - if ($codebase->statements_provider->parser_cache_provider) { - $codebase->statements_provider->parser_cache_provider->processSuccessfulRun(); - } } if ($error_count From 7e54c5172dbcbb025c11bb54a7a6d8d18c6ef4b3 Mon Sep 17 00:00:00 2001 From: Tomasz Mlynski Date: Mon, 6 Dec 2021 17:59:43 +0100 Subject: [PATCH 3/6] Deprecate unused methods --- psalm.xml.dist | 8 ++++++++ src/Psalm/Internal/Analyzer/ProjectAnalyzer.php | 1 + src/Psalm/Internal/Provider/ParserCacheProvider.php | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/psalm.xml.dist b/psalm.xml.dist index bcf32dfb392..a29522a717b 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -111,6 +111,12 @@ + + + + + + @@ -128,6 +134,8 @@ + + diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index bce31106c9c..ef023268c09 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -1068,6 +1068,7 @@ private function checkDirWithConfig(string $dir_name, Config $config, bool $allo /** * @return list + * @deprecated going to be removed in Psalm 5 */ private function getAllFiles(Config $config): array { diff --git a/src/Psalm/Internal/Provider/ParserCacheProvider.php b/src/Psalm/Internal/Provider/ParserCacheProvider.php index df753a08821..9706cc6d884 100644 --- a/src/Psalm/Internal/Provider/ParserCacheProvider.php +++ b/src/Psalm/Internal/Provider/ParserCacheProvider.php @@ -349,6 +349,9 @@ public function deleteOldParserCaches(float $time_before): int return $removed_count; } + /** + * @deprecated going to be removed in Psalm 5 + */ public function processSuccessfulRun(): void { $cache_directory = Config::getInstance()->getCacheDirectory(); @@ -376,6 +379,7 @@ public function processSuccessfulRun(): void /** * @param array $file_names + * @deprecated going to be removed in Psalm 5 */ public function touchParserCaches(array $file_names, int $min_time): void { From 5c73d77f28e8d4b6b74e3657a8418bf182462d1c Mon Sep 17 00:00:00 2001 From: Tomasz Mlynski Date: Mon, 6 Dec 2021 18:16:07 +0100 Subject: [PATCH 4/6] Remove unused methods --- psalm.xml.dist | 8 --- .../Internal/Analyzer/ProjectAnalyzer.php | 19 ------- .../Internal/Provider/ParserCacheProvider.php | 55 ------------------- 3 files changed, 82 deletions(-) diff --git a/psalm.xml.dist b/psalm.xml.dist index a29522a717b..bcf32dfb392 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -111,12 +111,6 @@ - - - - - - @@ -134,8 +128,6 @@ - - diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index ef023268c09..c279965cd90 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -1066,25 +1066,6 @@ private function checkDirWithConfig(string $dir_name, Config $config, bool $allo $this->codebase->addFilesToAnalyze($files_to_scan); } - /** - * @return list - * @deprecated going to be removed in Psalm 5 - */ - private function getAllFiles(Config $config): array - { - $file_extensions = $config->getFileExtensions(); - $file_paths = []; - - foreach ($config->getProjectDirectories() as $dir_name) { - $file_paths = array_merge( - $file_paths, - $this->file_provider->getFilesInDir($dir_name, $file_extensions) - ); - } - - return $file_paths; - } - public function addProjectFile(string $file_path): void { $this->project_files[$file_path] = $file_path; diff --git a/src/Psalm/Internal/Provider/ParserCacheProvider.php b/src/Psalm/Internal/Provider/ParserCacheProvider.php index 9706cc6d884..3567bc2fa0f 100644 --- a/src/Psalm/Internal/Provider/ParserCacheProvider.php +++ b/src/Psalm/Internal/Provider/ParserCacheProvider.php @@ -349,61 +349,6 @@ public function deleteOldParserCaches(float $time_before): int return $removed_count; } - /** - * @deprecated going to be removed in Psalm 5 - */ - public function processSuccessfulRun(): void - { - $cache_directory = Config::getInstance()->getCacheDirectory(); - - if (!$cache_directory) { - return; - } - - $cache_directory .= DIRECTORY_SEPARATOR . self::PARSER_CACHE_DIRECTORY; - - if (is_dir($cache_directory)) { - $directory_files = scandir($cache_directory, SCANDIR_SORT_NONE); - - foreach ($directory_files as $directory_file) { - $full_path = $cache_directory . DIRECTORY_SEPARATOR . $directory_file; - - if ($directory_file[0] === '.') { - continue; - } - - touch($full_path); - } - } - } - - /** - * @param array $file_names - * @deprecated going to be removed in Psalm 5 - */ - public function touchParserCaches(array $file_names, int $min_time): void - { - $cache_directory = Config::getInstance()->getCacheDirectory(); - - if (!$cache_directory) { - return; - } - - $cache_directory .= DIRECTORY_SEPARATOR . self::PARSER_CACHE_DIRECTORY; - - if (is_dir($cache_directory)) { - foreach ($file_names as $file_name) { - $hash_file_name = $cache_directory . DIRECTORY_SEPARATOR . $this->getParserCacheKey($file_name); - - if (file_exists($hash_file_name)) { - if (filemtime($hash_file_name) < $min_time) { - touch($hash_file_name, $min_time); - } - } - } - } - } - private function getParserCacheKey(string $file_name): string { return md5($file_name) . ($this->use_igbinary ? '-igbinary' : '') . '-r'; From e4b0b9b3053774c7437df6ed378f94a17191df69 Mon Sep 17 00:00:00 2001 From: Tomasz Mlynski Date: Mon, 6 Dec 2021 18:17:52 +0100 Subject: [PATCH 5/6] Remove redundant condition --- src/Psalm/Internal/Analyzer/ProjectAnalyzer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index c279965cd90..a32260a7573 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -684,7 +684,7 @@ public function check(string $base_dir, bool $is_diff = false): void true ); - if ($this->project_cache_provider && $this->parser_cache_provider && !$is_diff) { + if ($this->parser_cache_provider && !$is_diff) { $removed_parser_files = $this->parser_cache_provider->deleteOldParserCaches($start_checks); if ($removed_parser_files) { From 348c62db94c03dc669b66283509136bbfc5e5fe5 Mon Sep 17 00:00:00 2001 From: Tomasz Mlynski Date: Mon, 6 Dec 2021 18:25:04 +0100 Subject: [PATCH 6/6] Remove unused function reference --- src/Psalm/Internal/Provider/ParserCacheProvider.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Psalm/Internal/Provider/ParserCacheProvider.php b/src/Psalm/Internal/Provider/ParserCacheProvider.php index 3567bc2fa0f..c4b4b9a4050 100644 --- a/src/Psalm/Internal/Provider/ParserCacheProvider.php +++ b/src/Psalm/Internal/Provider/ParserCacheProvider.php @@ -7,7 +7,6 @@ use RuntimeException; use function error_log; -use function file_exists; use function file_get_contents; use function file_put_contents; use function filemtime;