Skip to content

Commit c291656

Browse files
committed
Enforces stricter types thanks to psalm.
Fixed: some error notices are now displayed fully.
1 parent 983ea3b commit c291656

23 files changed

Lines changed: 156 additions & 133 deletions

‎all_words_wellknown.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ function all_words_wellknown_count_terms($status, $count)
187187
/**
188188
* Execute JavaScript to change the display of all words.
189189
*
190-
* @param int $txid Text ID
191-
* @param int $javascript JavaScript-formatted string.
190+
* @param int $txid Text ID
191+
* @param string $javascript JavaScript-formatted string.
192192
*
193193
* @return void
194194
*/

‎database_wizard.php‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,25 @@
3131
*/
3232
class Database_Connection
3333
{
34+
/**
35+
* @var string Server name
36+
*/
3437
public string $server;
38+
/**
39+
* @var string $userid User ID
40+
*/
3541
public string $userid;
42+
/**
43+
* @var string $passwd Password for this user
44+
*/
3645
public string $passwd;
46+
/**
47+
* @var string $dbname Database name
48+
*/
3749
public string $dbname;
50+
/**
51+
* @var string $socket Socket to use
52+
*/
3853
public string $socket;
3954

4055
/**
@@ -193,7 +208,7 @@ function doOperation($op)
193208
*/
194209
function displayForm($conn, $error_message=null)
195210
{
196-
pagestart_kernel_nobody("Database Connection Wizard", true);
211+
pagestart_kernel_nobody("Database Connection Wizard");
197212
if ($error_message != null) {
198213
echo $error_message;
199214
}

‎display_impr_text_header.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function do_diplay_impr_text_header_data($textid)
3939

4040

4141
if (isset($record['TxAudioURI'])) {
42-
$audio = trim($record['TxAudioURI']);
42+
$audio = trim((string) $record['TxAudioURI']);
4343
} else {
4444
$audio = '';
4545
}

‎display_impr_text_text.php‎

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,20 @@ function get_annotated_text($textid)
4040
*
4141
* @param int $textid Text ID
4242
*
43-
* @return array{0: string, 1: string} Text size, and if this text
43+
* @return array{0: string, 1: bool} Text size, and if this text
4444
* is rigth-to-left.
4545
*/
4646
function get_display_impr_text_text_data($textid)
4747
{
4848
global $tbpref;
49-
50-
/*$sql = 'SELECT TxLgID, TxTitle
51-
FROM ' . $tbpref . 'texts
52-
WHERE TxID = ' . $textid;
53-
$res = do_mysqli_query($sql);
54-
$record = mysqli_fetch_assoc($res);
55-
$langid = $record['TxLgID'];
56-
mysqli_free_result($res);
57-
58-
$sql = 'SELECT LgTextSize, LgRemoveSpaces, LgRightToLeft
59-
FROM ' . $tbpref . 'languages WHERE LgID = ' . $langid;*/
60-
61-
$sql = 'SELECT LgTextSize, LgRightToLeft
62-
FROM ' . $tbpref . 'texts
63-
JOIN ' . $tbpref . 'languages ON LgID = TxLgID
64-
WHERE TxID = ' . $textid;
49+
$sql = "SELECT LgTextSize, LgRightToLeft
50+
FROM {$tbpref}texts
51+
JOIN {$tbpref}languages ON LgID = TxLgID
52+
WHERE TxID = $textid";
6553
$res = do_mysqli_query($sql);
6654
$record = mysqli_fetch_assoc($res);
67-
$textsize = $record['LgTextSize'];
68-
$rtlScript = $record['LgRightToLeft'];
55+
$textsize = (int) $record['LgTextSize'];
56+
$rtlScript = (bool) $record['LgRightToLeft'];
6957
mysqli_free_result($res);
7058

7159
return array($textsize, $rtlScript);

‎do_feeds.php‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ function dummy_function_1(): array
4949
'audio' => $row['FlAudio'],
5050
'text' => $row['FlText']
5151
);
52-
$NfName = $row['NfName'];
53-
$nf_id=$row['NfID'];
54-
$nf_options=$row['NfOptions'];
55-
if (!$nf_tag_name=get_nf_option($nf_options, 'tag')) {
52+
$NfName = (string) $row['NfName'];
53+
$nf_id = (int) $row['NfID'];
54+
$nf_options = $row['NfOptions'];
55+
if (!$nf_tag_name = get_nf_option($nf_options, 'tag')) {
5656
$nf_tag_name = mb_substr($NfName, 0, 20, "utf-8");
5757
}
58-
if (!$nf_max_texts=(int)get_nf_option($nf_options, 'max_texts')) {
59-
$nf_max_texts=(int)getSettingWithDefault('set-max-texts-per-feed');
58+
if (!$nf_max_texts = (int)get_nf_option($nf_options, 'max_texts')) {
59+
$nf_max_texts = (int)getSettingWithDefault('set-max-texts-per-feed');
6060
}
6161
$texts = get_text_from_rsslink(
6262
$doc, $row['NfArticleSectionTags'], $row['NfFilterTags'],
@@ -578,24 +578,35 @@ function dummy_function_2($currentlang, $currentfeed): void
578578
while ($row = mysqli_fetch_assoc($result)) {
579579
echo '<tr>';
580580
if ($row['TxID']) {
581-
echo '<td class="td1 center"><a href="do_text.php?start=' . $row['TxID'] . '" ><img src="icn/book-open-bookmark.png" title="Read" alt="-" /></a>';
581+
echo '<td class="td1 center"><a href="do_text.php?start=' .
582+
$row['TxID'] . '" >
583+
<img src="icn/book-open-bookmark.png" title="Read" alt="-" /></a>';
582584
} elseif ($row['AtID']) {
583585
echo '<td class="td1 center"><span title="archived"><img src="icn/status-busy.png" alt="-" /></span>';
584586
} elseif (!empty($row['FlLink']) && str_starts_with($row['FlLink'], ' ')) {
585-
echo '<td class="td1 center"><img class="not_found" name="' . $row['FlID'] . '" title="download error" src="icn/exclamation-button.png" alt="-" />';
587+
echo '<td class="td1 center">
588+
<img class="not_found" name="' .
589+
$row['FlID'] .
590+
'" title="download error" src="icn/exclamation-button.png" alt="-" />';
586591
} else {
587-
echo '<td class="td1 center"><input type="checkbox" class="markcheck" name="marked_items[]" value="' . $row['FlID'] . '" />';
592+
echo '<td class="td1 center"><input type="checkbox" class="markcheck" name="marked_items[]" value="' .
593+
$row['FlID'] . '" />';
588594
}
589595
echo '</td>
590596
<td class="td1 center">
591-
<span title="' . htmlentities($row['FlDescription'], ENT_QUOTES, 'UTF-8', false) . '"><b>' . $row['FlTitle'] . '</b></span>';
597+
<span title="' . htmlentities($row['FlDescription'], ENT_QUOTES, 'UTF-8', false) . '"><b>' .
598+
$row['FlTitle'] . '</b></span>';
592599
if ($row['FlAudio']) {
593-
echo '<a href="' . $row['FlAudio'] . '" onclick="window.open(this.href, \'child\', \'scrollbars,width=650,height=600\'); return false;"> <img src="'; print_file_path('icn/speaker-volume.png'); echo '" alt="-" /></a>';
600+
echo '<a href="' . $row['FlAudio'] .
601+
'" onclick="window.open(this.href, \'child\', \'scrollbars,width=650,height=600\'); return false;">
602+
<img src="'; print_file_path('icn/speaker-volume.png'); echo '" alt="-" /></a>';
594603
}
595604
echo '</td>
596605
<td class="td1 center" style="vertical-align: middle">';
597606
if (!empty($row['FlLink']) && !str_starts_with(trim($row['FlLink']), '#')) {
598-
echo '<a href="' . trim($row['FlLink']) . '" title="' . trim($row['FlLink']) . '" onclick="window.open(\'' . $row['FlLink'] . '\');return false;"><img src="icn/external.png" alt="-" /></a>';
607+
echo '<a href="' . trim((string) $row['FlLink']) . '" title="' .
608+
trim($row['FlLink']) . '" onclick="window.open(\'' . $row['FlLink'] . '\');return false;">
609+
<img src="icn/external.png" alt="-" /></a>';
599610
}
600611
echo '</td><td class="td1 center">' . $row['FlDate'] . '</td></tr>';
601612
}

‎do_test_header.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function get_test_counts($testsql)
132132
/**
133133
* Make the header row for tests.
134134
*
135-
* @param string $_p URL property to use
135+
* @param mixed $_p URL property to use (unnused), will be removed in LWT 3.0.0
136136
*
137137
* @return void
138138
*/

‎do_test_test.php‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* Get the SQL string to perform tests.
2626
*
27-
* @param bool|null $selection Test is of type selection
27+
* @param int|null $selection Test is of type selection
2828
* @param string|null $sess_testsql SQL string for test
2929
* @param int|null $lang Test is of type language, for the language $lang ID
3030
* @param int|null $text Testing text with ID $text
@@ -211,7 +211,7 @@ function do_test_test_finished($testsql, $totaltests, $ajax=false)
211211
* The sentence should contain at least 70% of known words.
212212
*
213213
* @param int $wid The word to test.
214-
* @param string $lang ID of the language
214+
* @param mixed $lang ID of the language, will be removed in PHP 3.0.0
215215
* @param string $wordlc Word in lowercase
216216
*
217217
* @global string $tbpref Table prefix
@@ -273,11 +273,11 @@ function do_test_test_sentence($wid, $lang, $wordlc): array
273273
/**
274274
* Return the test relative to a word.
275275
*
276-
* @param array $wo_record Query from the database regarding a word.
277-
* @param string $sent Sentence containing the word.
278-
* @param int $testtype Type of test
279-
* @param int $nosent 1 if you want to hide sentences.
280-
* @param string $regexword Regex to select the desired word.
276+
* @param array $wo_record Query from the database regarding a word.
277+
* @param string $sent Sentence containing the word.
278+
* @param int $testtype Type of test
279+
* @param bool|int $nosent 1 or true if you want to hide sentences.
280+
* @param string $regexword Regex to select the desired word.
281281
*
282282
* @return string[] HTML-escaped and raw text sentences (or word)
283283
*

‎do_text_header.php‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,18 +285,19 @@ function saveTextStatus() {
285285
/**
286286
* Main function for displaying header. It will print HTML content.
287287
*
288-
* @param string $textid ID of the requiered text
289-
* @param bool $only_body If true, only show the inner body. If false, create a
288+
* @param string|int $textid ID of the requiered text
289+
* @param bool $only_body If true, only show the inner body. If false, create a
290290
* complete HTML document.
291291
*
292292
* @since 2.0.3-fork
293293
*/
294294
function do_text_header_content($textid, $only_body=true): void
295295
{
296296
$record = getData($textid);
297-
$title = $record['TxTitle'];
298-
$media = $record['TxAudioURI'];
299-
if (!isset($media)) {
297+
$title = (string) $record['TxTitle'];
298+
if (isset($record['TxAudioURI'])) {
299+
$media = (string) $record['TxAudioURI'];
300+
} else {
300301
$media = '';
301302
}
302303
$media = trim($media);
@@ -318,8 +319,4 @@ function do_text_header_content($textid, $only_body=true): void
318319
}
319320
}
320321

321-
// Show the content automatically if text is in the request
322-
if (false && getreq('text')) {
323-
do_text_header_content(getreq('text'), false);
324-
}
325322
?>

‎do_text_text.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* Get the record for this text in the database.
2222
*
23-
* @param string $textid ID of the text
23+
* @param string|int $textid ID of the text
2424
*
2525
* @return array{TxLgID: int, TxTitle: string, TxAnnotatedText: string,
2626
* TxPosition: int}|false|null Record corresponding to this text.
@@ -270,7 +270,7 @@ function wordProcessor($record, $showAll, $currcharcount): int
270270
$cnt = 1;
271271
$sid = 0;
272272

273-
if ($sid != $record['Ti2SeID']) {
273+
if ($sid != (int) $record['Ti2SeID']) {
274274
$sid = $record['Ti2SeID'];
275275
echo '<span id="sent_', $sid, '">';
276276
}
@@ -699,8 +699,8 @@ function do_text_javascript($var_array): void
699699
/**
700700
* Main function for displaying sentences. It will print HTML content.
701701
*
702-
* @param string $textid ID of the requiered text
703-
* @param bool $only_body If true, only show the inner body. If false, create a complete HTML document.
702+
* @param string|int $textid ID of the requiered text
703+
* @param bool $only_body If true, only show the inner body. If false, create a complete HTML document.
704704
*/
705705
function do_text_text_content($textid, $only_body=true): void
706706
{

‎docs/info.php‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ function topicJump (qm) {
213213
</select>
214214
</p>
215215

216-
<?php echo markdown_integration(__DIR__ . "/preface.md"); ?>
216+
<?php markdown_integration(__DIR__ . "/preface.md"); ?>
217217

218218
<h2 name="current" id="current">
219219
▶ Current Version - <a href="#">[↑]</a>
@@ -226,15 +226,15 @@ function topicJump (qm) {
226226
</p>
227227

228228

229-
<?php echo markdown_integration(__DIR__ . "/abstract.md"); ?>
229+
<?php markdown_integration(__DIR__ . "/abstract.md"); ?>
230230

231-
<?php echo markdown_integration(__DIR__ . "/install.md"); ?>
231+
<?php markdown_integration(__DIR__ . "/install.md"); ?>
232232

233-
<?php echo markdown_integration(__DIR__ . "/postinstall.md"); ?>
233+
<?php markdown_integration(__DIR__ . "/postinstall.md"); ?>
234234

235-
<?php echo markdown_integration(__DIR__ . "/features.md"); ?>
235+
<?php markdown_integration(__DIR__ . "/features.md"); ?>
236236

237-
<?php echo markdown_integration(__DIR__ . "/newfeatures.md"); ?>
237+
<?php markdown_integration(__DIR__ . "/newfeatures.md"); ?>
238238

239239
<h2 name="screencasts" id="screencasts">
240240
▶ Screencasts/Videos - <a href="#">[↑]</a>
@@ -258,39 +258,39 @@ function topicJump (qm) {
258258
<a href="http://www.fluentin3months.com/learning-with-texts/" In 3 Months: Introducing LWT</a>, with <a href="http://lwtfi3m.co/">Benny's own (free) version of LWT</a>.<br />
259259
</p>
260260

261-
<?php echo markdown_integration(__DIR__ . "/links.md"); ?>
261+
<?php markdown_integration(__DIR__ . "/links.md"); ?>
262262

263-
<?php echo markdown_integration(__DIR__ . "/restrictions.md"); ?>
263+
<?php markdown_integration(__DIR__ . "/restrictions.md"); ?>
264264

265-
<?php echo markdown_integration(__DIR__ . "/../UNLICENSE.md" ) ?>
265+
<?php markdown_integration(__DIR__ . "/../UNLICENSE.md" ) ?>
266266

267-
<?php echo markdown_integration(__DIR__ . "/thirdpartylicenses.md" ) ?>
267+
<?php markdown_integration(__DIR__ . "/thirdpartylicenses.md" ) ?>
268268

269-
<?php echo markdown_integration(__DIR__ . "/learn.md"); ?>
269+
<?php markdown_integration(__DIR__ . "/learn.md"); ?>
270270

271-
<?php echo markdown_integration(__DIR__ . "/howto.md"); ?>
271+
<?php markdown_integration(__DIR__ . "/howto.md"); ?>
272272

273-
<?php echo markdown_integration(__DIR__ . "/faq.md"); ?>
273+
<?php markdown_integration(__DIR__ . "/faq.md"); ?>
274274

275-
<?php echo markdown_integration(__DIR__ . "/ipad.md"); ?>
275+
<?php markdown_integration(__DIR__ . "/ipad.md"); ?>
276276

277-
<?php echo markdown_integration(__DIR__ . '/langsetup.md'); ?>
277+
<?php markdown_integration(__DIR__ . '/langsetup.md'); ?>
278278

279-
<?php echo markdown_integration(__DIR__ . "/termscores.md"); ?>
279+
<?php markdown_integration(__DIR__ . "/termscores.md"); ?>
280280

281-
<?php echo markdown_integration(__DIR__ . "/keybind.md"); ?>
281+
<?php markdown_integration(__DIR__ . "/keybind.md"); ?>
282282

283-
<?php echo markdown_integration(__DIR__ . "/export.md"); ?>
283+
<?php markdown_integration(__DIR__ . "/export.md"); ?>
284284

285-
<?php echo markdown_integration(__DIR__ . "/contribute.md"); ?>
285+
<?php markdown_integration(__DIR__ . "/contribute.md"); ?>
286286

287-
<?php echo markdown_integration(__DIR__ . "/wordpress.md"); ?>
287+
<?php markdown_integration(__DIR__ . "/wordpress.md"); ?>
288288

289-
<?php echo markdown_integration(__DIR__ . "/api.md"); ?>
289+
<?php markdown_integration(__DIR__ . "/api.md"); ?>
290290

291-
<?php echo markdown_integration(__DIR__ . "/database.md"); ?>
291+
<?php markdown_integration(__DIR__ . "/database.md"); ?>
292292

293-
<?php echo markdown_integration(__DIR__ . "/CHANGELOG.md"); ?>
293+
<?php markdown_integration(__DIR__ . "/CHANGELOG.md"); ?>
294294

295295
<footer>
296296
<p class="smallgray">

0 commit comments

Comments
 (0)