From 0317683155a3966830f3972fde1562087f65cf94 Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Mon, 27 Mar 2023 00:36:21 +0200 Subject: Add test and type hinting (#5087) * - Add test and type hinting - pass PhpStan Level 9 * fix dump * fix style * fix visibility * fix style * add test * add test * add test * add test * add test * Simplify * cleaning after test * remove space * fix style * use specific log file for test * Remarque's from Alkarex * A few more details --------- Co-authored-by: Luc Co-authored-by: Alexandre Alapetite --- app/Models/LogDAO.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'app/Models/LogDAO.php') diff --git a/app/Models/LogDAO.php b/app/Models/LogDAO.php index 6e5bf171b..080af54ea 100644 --- a/app/Models/LogDAO.php +++ b/app/Models/LogDAO.php @@ -1,19 +1,21 @@ */ - public static function lines(): array { - $logs = array(); - $handle = @fopen(self::logPath(), 'r'); + public static function lines(?string $logFileName = null): array { + $logs = []; + $handle = @fopen(self::logPath($logFileName), 'r'); if ($handle) { while (($line = fgets($handle)) !== false) { if (preg_match('/^\[([^\[]+)\] \[([^\[]+)\] --- (.*)$/', $line, $matches)) { - $myLog = new FreshRSS_Log (); + $myLog = new FreshRSS_Log(); $myLog->_date($matches[1]); $myLog->_level($matches[2]); $myLog->_info($matches[3]); @@ -25,8 +27,8 @@ class FreshRSS_LogDAO { return array_reverse($logs); } - public static function truncate(): void { - file_put_contents(self::logPath(), ''); + public static function truncate(?string $logFileName = null): void { + file_put_contents(self::logPath($logFileName), ''); if (FreshRSS_Auth::hasAccess('admin')) { file_put_contents(ADMIN_LOG, ''); file_put_contents(API_LOG, ''); -- cgit v1.2.3