Skip to content

Commit

Permalink
fix: Reach PHPStan level 5 by fixing param typing
Browse files Browse the repository at this point in the history
  • Loading branch information
linc committed Dec 11, 2022
1 parent 198ae72 commit b811821
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 4
level: 5
paths:
- src
- tests
Expand Down
2 changes: 1 addition & 1 deletion src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
8 changes: 4 additions & 4 deletions src/ExportModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Functions/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 = '')
Expand Down
4 changes: 2 additions & 2 deletions src/Functions/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Source/AnswerHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
4 changes: 2 additions & 2 deletions src/Source/IpBoard3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions src/Source/VBulletin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit b811821

Please sign in to comment.