Skip to content

Commit 3401f1f

Browse files
author
HugoFara
committed
chore(psalm): fixing genuing psalm warnings that were ignored.
1 parent 9e65151 commit 3401f1f

24 files changed

+80
-77
lines changed

psalm.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,6 @@
103103
</errorLevel>
104104
</RedundantCondition>
105105

106-
<TypeDoesNotContainNull>
107-
<errorLevel type="suppress">
108-
<directory name="src/backend/Views" />
109-
</errorLevel>
110-
</TypeDoesNotContainNull>
111-
112106
<TypeDoesNotContainType>
113107
<errorLevel type="suppress">
114108
<directory name="src/backend/Views" />
@@ -138,12 +132,6 @@
138132
</errorLevel>
139133
</InvalidReturnType>
140134

141-
<InvalidReturnStatement>
142-
<errorLevel type="suppress">
143-
<directory name="src/backend/Services" />
144-
</errorLevel>
145-
</InvalidReturnStatement>
146-
147135
<!-- Foreach values used for iteration control only -->
148136
<UnusedForeachValue>
149137
<errorLevel type="suppress">

src/backend/Services/FeedService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function countFeeds(?int $langId = null, ?string $queryPattern = null): i
159159
*/
160160
public function createFeed(array $data): int
161161
{
162-
return QueryBuilder::table('newsfeeds')
162+
return (int) QueryBuilder::table('newsfeeds')
163163
->insertPrepared([
164164
'NfLgID' => $data['NfLgID'],
165165
'NfName' => $data['NfName'],
@@ -527,7 +527,7 @@ public function createTextFromFeed(array $textData, string $tagName): int
527527
. UserScopedQuery::forTablePrepared('tags2', $bindings);
528528
Connection::preparedExecute($sql, $bindings);
529529

530-
return $textId;
530+
return (int) $textId;
531531
}
532532

533533
/**

src/backend/Services/TextService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public function unarchiveText(int $archivedId): array
291291

292292
$message = "{$deleted} / {$insertedMsg} / Sentences added: {$sentenceCount} / Text items added: {$itemCount}";
293293

294-
return ['message' => $message, 'textId' => $textId];
294+
return ['message' => $message, 'textId' => (int) $textId];
295295
}
296296

297297
/**
@@ -1405,7 +1405,7 @@ private function removeSoftHyphens(string $text): string
14051405
/**
14061406
* Get language data for Google Translate URIs.
14071407
*
1408-
* @return array Mapping of language ID to language code
1408+
* @return array<int, string> Mapping of language ID to language code
14091409
*/
14101410
public function getLanguageTranslateUris(): array
14111411
{
@@ -1415,7 +1415,7 @@ public function getLanguageTranslateUris(): array
14151415
$res = Connection::query($sql);
14161416
$result = [];
14171417
while ($record = mysqli_fetch_assoc($res)) {
1418-
$result[$record['LgID']] = $record['LgGoogleTranslateURI'];
1418+
$result[(int) $record['LgID']] = (string) $record['LgGoogleTranslateURI'];
14191419
}
14201420
mysqli_free_result($res);
14211421
return $result;
@@ -1752,7 +1752,7 @@ public function getLanguageDataForForm(): array
17521752
$res = Connection::query($sql);
17531753
$result = [];
17541754
while ($record = mysqli_fetch_assoc($res)) {
1755-
$result[$record['LgID']] = UrlUtilities::langFromDict($record['LgGoogleTranslateURI']);
1755+
$result[(int) $record['LgID']] = UrlUtilities::langFromDict((string) $record['LgGoogleTranslateURI']);
17561756
}
17571757
mysqli_free_result($res);
17581758
return $result;

src/backend/Services/TextStatisticsService.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class TextStatisticsService
4343
*
4444
* @param string $textsId Texts ID separated by comma
4545
*
46-
* @return array{total: array, expr: array, stat: array, totalu: array, expru: array, statu: array}
46+
* @return array{total: array<int, int>, expr: array<int, int>, stat: array<int, array<int, int>>, totalu: array<int, int>, expru: array<int, int>, statu: array<int, array<int, int>>}
4747
* Total number of words, number of expressions, statistics, total unique,
4848
* number of unique expressions, unique statistics
4949
*/
@@ -70,8 +70,9 @@ public function getTextWordCount(string $textsId): array
7070
GROUP BY Ti2TxID";
7171
$res = Connection::query($sql);
7272
while ($record = mysqli_fetch_assoc($res)) {
73-
$r["total"][$record['text']] = $record['total'];
74-
$r["totalu"][$record['text']] = $record['unique_cnt'];
73+
$textId = (int) $record['text'];
74+
$r["total"][$textId] = (int) $record['total'];
75+
$r["totalu"][$textId] = (int) $record['unique_cnt'];
7576
}
7677
mysqli_free_result($res);
7778

@@ -84,8 +85,9 @@ public function getTextWordCount(string $textsId): array
8485
GROUP BY Ti2TxID";
8586
$res = Connection::query($sql);
8687
while ($record = mysqli_fetch_assoc($res)) {
87-
$r["expr"][$record['text']] = $record['total'];
88-
$r["expru"][$record['text']] = $record['unique_cnt'];
88+
$textId = (int) $record['text'];
89+
$r["expr"][$textId] = (int) $record['total'];
90+
$r["expru"][$textId] = (int) $record['unique_cnt'];
8991
}
9092
mysqli_free_result($res);
9193

@@ -101,8 +103,10 @@ public function getTextWordCount(string $textsId): array
101103
" GROUP BY Ti2TxID, WoStatus";
102104
$res = Connection::query($sql);
103105
while ($record = mysqli_fetch_assoc($res)) {
104-
$r["stat"][$record['text']][$record['status']] = $record['total'];
105-
$r["statu"][$record['text']][$record['status']] = $record['unique_cnt'];
106+
$textId = (int) $record['text'];
107+
$status = (int) $record['status'];
108+
$r["stat"][$textId][$status] = (int) $record['total'];
109+
$r["statu"][$textId][$status] = (int) $record['unique_cnt'];
106110
}
107111
mysqli_free_result($res);
108112

src/backend/Services/ThemeService.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ private function loadThemeMetadata(string $themePath): array
110110
return $defaults;
111111
}
112112

113-
return array_merge($defaults, $metadata);
113+
return [
114+
'name' => isset($metadata['name']) && is_string($metadata['name'])
115+
? $metadata['name'] : $defaults['name'],
116+
'description' => isset($metadata['description']) && is_string($metadata['description'])
117+
? $metadata['description'] : $defaults['description'],
118+
'mode' => isset($metadata['mode']) && is_string($metadata['mode'])
119+
? $metadata['mode'] : $defaults['mode'],
120+
'highlighting' => isset($metadata['highlighting']) && is_string($metadata['highlighting'])
121+
? $metadata['highlighting'] : $defaults['highlighting'],
122+
'wordBreaking' => isset($metadata['wordBreaking']) && is_string($metadata['wordBreaking'])
123+
? $metadata['wordBreaking'] : $defaults['wordBreaking'],
124+
];
114125
}
115126
}

src/backend/Services/WordListService.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public function deleteByIdList(string $idList): string
434434

435435
Maintenance::adjustAutoIncrement('words', 'WoID');
436436

437-
return $message;
437+
return (string) $message;
438438
}
439439

440440
/**
@@ -453,15 +453,15 @@ public function updateStatusByIdList(string $idList, int $newStatus, bool $relat
453453

454454
if ($relative && $newStatus > 0) {
455455
// Status +1
456-
return Connection::execute(
456+
return (string) Connection::execute(
457457
'update words
458458
set WoStatus=WoStatus+1, WoStatusChanged = NOW(),' . $scoreUpdate . '
459459
where WoStatus in (1,2,3,4) and WoID in ' . $idList,
460460
"Updated Status (+1)"
461461
);
462462
} elseif ($relative && $newStatus < 0) {
463463
// Status -1
464-
return Connection::execute(
464+
return (string) Connection::execute(
465465
'update words
466466
set WoStatus=WoStatus-1, WoStatusChanged = NOW(),' . $scoreUpdate . '
467467
where WoStatus in (2,3,4,5) and WoID in ' . $idList,
@@ -470,7 +470,7 @@ public function updateStatusByIdList(string $idList, int $newStatus, bool $relat
470470
}
471471

472472
// Absolute status
473-
return Connection::execute(
473+
return (string) Connection::execute(
474474
'update words
475475
set WoStatus=' . $newStatus . ', WoStatusChanged = NOW(),' . $scoreUpdate . '
476476
where WoID in ' . $idList,
@@ -487,7 +487,7 @@ public function updateStatusByIdList(string $idList, int $newStatus, bool $relat
487487
*/
488488
public function updateStatusDateByIdList(string $idList): string
489489
{
490-
return Connection::execute(
490+
return (string) Connection::execute(
491491
'update words
492492
set WoStatusChanged = NOW(),' . WordStatusService::makeScoreRandomInsertUpdate('u') . '
493493
where WoID in ' . $idList,
@@ -504,7 +504,7 @@ public function updateStatusDateByIdList(string $idList): string
504504
*/
505505
public function deleteSentencesByIdList(string $idList): string
506506
{
507-
return Connection::execute(
507+
return (string) Connection::execute(
508508
'update words
509509
set WoSentence = NULL
510510
where WoID in ' . $idList,
@@ -521,7 +521,7 @@ public function deleteSentencesByIdList(string $idList): string
521521
*/
522522
public function toLowercaseByIdList(string $idList): string
523523
{
524-
return Connection::execute(
524+
return (string) Connection::execute(
525525
'update words
526526
set WoText = WoTextLC
527527
where WoID in ' . $idList,
@@ -538,7 +538,7 @@ public function toLowercaseByIdList(string $idList): string
538538
*/
539539
public function capitalizeByIdList(string $idList): string
540540
{
541-
return Connection::execute(
541+
return (string) Connection::execute(
542542
'update words
543543
set WoText = CONCAT(
544544
UPPER(LEFT(WoTextLC,1)),SUBSTRING(WoTextLC,2)

src/backend/Views/Admin/backup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use Lwt\View\Helper\IconHelper;
2525

2626
$escapedDbName = htmlspecialchars(Globals::getDatabaseName(), ENT_QUOTES, 'UTF-8');
27-
$escapedIniFile = htmlspecialchars(php_ini_loaded_file() ?? '', ENT_QUOTES, 'UTF-8');
27+
$escapedIniFile = htmlspecialchars(php_ini_loaded_file() ?: '', ENT_QUOTES, 'UTF-8');
2828
$postMaxSize = ini_get('post_max_size');
2929
$uploadMaxFilesize = ini_get('upload_max_filesize');
3030
?>

src/backend/Views/Feed/browse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<input type="text"
5555
name="query"
5656
class="input"
57-
value="<?php echo htmlspecialchars($currentQuery ?? '', ENT_QUOTES, 'UTF-8'); ?>"
57+
value="<?php echo htmlspecialchars($currentQuery, ENT_QUOTES, 'UTF-8'); ?>"
5858
placeholder="Search articles... (e.g., lang:Spanish feed:news title)"
5959
disabled />
6060
<span class="icon is-left">

src/backend/Views/Feed/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<input type="text"
4646
name="query"
4747
class="input"
48-
value="<?php echo htmlspecialchars($currentQuery ?? '', ENT_QUOTES, 'UTF-8'); ?>"
48+
value="<?php echo htmlspecialchars($currentQuery, ENT_QUOTES, 'UTF-8'); ?>"
4949
placeholder="Search feeds... (e.g., lang:Spanish news)"
5050
disabled />
5151
<span class="icon is-left">

src/backend/Views/Language/form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
'sourceLg' => $sourceLg,
3131
'targetLg' => $targetLg,
3232
'languageDefs' => \Lwt\Services\LanguageDefinitions::getAll(),
33-
'allLanguages' => $allLanguages ?? []
33+
'allLanguages' => $allLanguages
3434
]); ?>
3535
</script>
3636

0 commit comments

Comments
 (0)