From b811821ccecdf9e4029793224dcf765fd0c58fc9 Mon Sep 17 00:00:00 2001 From: Lincoln Russell Date: Sun, 11 Dec 2022 16:01:11 -0500 Subject: [PATCH] fix: Reach PHPStan level 5 by fixing param typing --- phpstan.neon.dist | 2 +- src/Controller.php | 2 +- src/ExportModel.php | 8 ++++---- src/Functions/core.php | 4 ++-- src/Functions/filter.php | 4 ++-- src/Source/AnswerHub.php | 2 +- src/Source/IpBoard3.php | 4 ++-- src/Source/VBulletin.php | 10 +++++----- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 02eaa218..0829b805 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ parameters: - level: 4 + level: 5 paths: - src - tests diff --git a/src/Controller.php b/src/Controller.php index fb169a45..fe2294d3 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -123,7 +123,7 @@ public static function run(Request $request) // End timer & report. $exportModel->comment( sprintf('ELAPSED — %s', formatElapsed(microtime(true) - $start)) . - ' (' . date('H:i:s', $start) . ' - ' . date('H:i:s') . ')' + ' (' . date('H:i:s', (int)$start) . ' - ' . date('H:i:s') . ')' ); // Write the results (web only). diff --git a/src/ExportModel.php b/src/ExportModel.php index cb79f991..b8e3331b 100644 --- a/src/ExportModel.php +++ b/src/ExportModel.php @@ -339,7 +339,7 @@ public function findDuplicates(string $table, string $column): array $duplicates = $db->table($table) ->select($column, $db->raw('count(' . $column . ') as found_count')) ->groupBy($column) - ->having('found_count', '>', 1) + ->having('found_count', '>', '1') ->get(); foreach ($duplicates as $dupe) { $results[] = $dupe->$column; @@ -376,8 +376,8 @@ public function pruneOrphanedRecords(string $table, string $column, string $fnTa protected function processQuery(string $query): string { // Check for a chunked query. - $query = str_replace('{from}', -2000000000, $query); - $query = str_replace('{to}', 2000000000, $query); + $query = str_replace('{from}', '-2000000000', $query); + $query = str_replace('{to}', '2000000000', $query); // If we are in test mode then limit the query. if ($this->testMode && $this->testLimit) { @@ -425,7 +425,7 @@ public function ignoreDuplicates(string $tableName) * Execute an sql statement and return the entire result as an associative array. * * @param string $sql - * @param bool $indexColumn + * @param bool|string $indexColumn * @return array * @deprecated */ diff --git a/src/Functions/core.php b/src/Functions/core.php index d72ee94d..4d5157fa 100644 --- a/src/Functions/core.php +++ b/src/Functions/core.php @@ -160,7 +160,7 @@ function errorHandler(int $level, string $msg, string $file, int $line, array $c if (defined('DEBUG') || ($level !== E_DEPRECATED && $level !== E_USER_DEPRECATED)) { $baseDir = realpath(__DIR__ . '/../') . '/'; - $errFile = str_replace($baseDir, null, $file); + $errFile = str_replace($baseDir, '', $file); echo "Error in $errFile line $line: ($level) $msg\n"; die(); } @@ -204,7 +204,7 @@ function getValue(string $key, array $collection = [], string $default = '') * @deprecated * @param string $name * @param array $array - * @param string $default + * @param mixed $default * @return mixed|null */ function v(string $name, array $array, $default = '') diff --git a/src/Functions/filter.php b/src/Functions/filter.php index dd0c9d10..6442aed4 100644 --- a/src/Functions/filter.php +++ b/src/Functions/filter.php @@ -98,12 +98,12 @@ function forceDate(string $value): string */ function forceIP4(string $ip): ?string { - $ip = null; + $ip = ''; if (preg_match('`(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})`', $ip, $m)) { $ip = $m[1]; } - return $ip; + return $ip ?: null; } /** diff --git a/src/Source/AnswerHub.php b/src/Source/AnswerHub.php index 126fddaf..02758dcd 100644 --- a/src/Source/AnswerHub.php +++ b/src/Source/AnswerHub.php @@ -73,7 +73,7 @@ public function generateEmail($value, $field, $row) $email = $value; if (empty($email)) { $domain = $this->param('noemaildomain'); - $slug = preg_replace('#[^a-z0-9-_.]#i', null, $row['Name']); + $slug = preg_replace('#[^a-z0-9-_.]#i', '', $row['Name']); if (!strlen($slug)) { $slug = $row['UserID']; diff --git a/src/Source/IpBoard3.php b/src/Source/IpBoard3.php index 8eda920f..fbd68ecd 100644 --- a/src/Source/IpBoard3.php +++ b/src/Source/IpBoard3.php @@ -133,8 +133,8 @@ public function doAvatars($ex) continue; } - $mainPhoto = trim(getValue('main_photo', $row, null)); - $thumbPhoto = trim(getValue('thumb_photo', $row, null)); + $mainPhoto = trim(v('main_photo', $row, null)); + $thumbPhoto = trim(v('thumb_photo', $row, null)); // Main Photo if (!$mainPhoto) { diff --git a/src/Source/VBulletin.php b/src/Source/VBulletin.php index 13edba99..c2ea8e98 100644 --- a/src/Source/VBulletin.php +++ b/src/Source/VBulletin.php @@ -246,8 +246,8 @@ public function run($ex) return; } - $minDiscussionID = false; - $minDiscussionWhere = false; + $minDiscussionID = 0; + $minDiscussionWhere = 0; // Check to see if there is a max date. $minDate = $this->param('mindate'); @@ -407,7 +407,7 @@ public function doFileExport(ExportModel $ex, $attachments = true, $customAvatar * @param string $sql * @param string $blobColumn * @param string $pathColumn - * @param bool $thumbnail + * @param bool|int $thumbnail */ public function exportBlobs(ExportModel $ex, $sql, $blobColumn, $pathColumn, $thumbnail = false) { @@ -508,10 +508,10 @@ public function attachments(ExportModel $ex, $minDiscussionID = false) // Add hash fields if they exist (from 2.x) $attachColumns = array('hash', 'filehash'); - $missing = $ex->exists('attachment', $attachColumns); + $hasColumns = $ex->exists('attachment', $attachColumns); $attachColumnsString = ''; foreach ($attachColumns as $columnName) { - if (in_array($columnName, $missing)) { + if (!$hasColumns) { $attachColumnsString .= ", null as $columnName"; } else { $attachColumnsString .= ", a.$columnName";