Skip to content

Commit 5a6215c

Browse files
author
HugoFara
committed
chore(backend): removes dual namespaces.
1 parent 0cb984a commit 5a6215c

30 files changed

+100
-329
lines changed

.psalm/stubs.php

Lines changed: 3 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
<?php
22

33
/**
4-
* Psalm stub file for runtime-defined constants and global function wrappers.
4+
* Psalm stub file for runtime-defined constants and namespaced functions.
55
*
66
* This file provides type information for:
77
* 1. Constants defined at runtime (e.g., LWT_BASE_PATH in index.php)
8-
* 2. Global function wrappers that call namespaced implementations
9-
* 3. Namespaced functions that Psalm cannot trace through dynamic includes
10-
*
11-
* The namespaced implementations exist in the codebase and Psalm can trace them.
12-
* These stubs are for the global-namespace backward-compatibility wrappers.
8+
* 2. Namespaced functions that Psalm cannot trace through dynamic includes
139
*
1410
* @psalm-suppress UnusedClass
1511
* @psalm-suppress UnusedMethod
@@ -67,153 +63,4 @@ function getVersionNumber(): string {}
6763

6864
define('LWT_BASE_PATH', __DIR__ . '/..');
6965

70-
// =============================================================================
71-
// GLOBAL FUNCTION WRAPPERS
72-
// These are backward-compatibility wrappers defined in various files.
73-
// They delegate to namespaced implementations.
74-
// =============================================================================
75-
76-
// ---------------------------------------------------------------------------
77-
// From ExportService.php / export_helpers.php
78-
// ---------------------------------------------------------------------------
79-
80-
/**
81-
* @param int $wid
82-
* @param string $before
83-
* @param int $brack
84-
* @param int $tohtml
85-
* @return string
86-
*/
87-
function getWordTagList(int $wid, string $before = ' ', int $brack = 1, int $tohtml = 1): string {}
88-
89-
/**
90-
* @param string $ann
91-
* @return string|false
92-
*/
93-
function annotationToJson($ann): string|false {}
94-
95-
// ---------------------------------------------------------------------------
96-
// From vite_helper.php
97-
// ---------------------------------------------------------------------------
98-
99-
/**
100-
* @return bool
101-
*/
102-
function should_use_vite(): bool {}
103-
104-
// ---------------------------------------------------------------------------
105-
// From text_navigation.php / TextNavigationService.php
106-
// ---------------------------------------------------------------------------
107-
108-
/**
109-
* @param int $textId
110-
* @param string $urlPath
111-
* @param bool $showTitle
112-
* @param string $addParam
113-
* @return string
114-
*/
115-
function getPreviousAndNextTextLinks(int $textId, string $urlPath, bool $showTitle, string $addParam): string {}
116-
117-
/**
118-
* @param int $textId
119-
* @return string
120-
*/
121-
function getAnnotationLink(int $textId): string {}
122-
123-
// ---------------------------------------------------------------------------
124-
// From SelectOptionsBuilder / UI helpers
125-
// These are called from Views without full namespace qualification
126-
// ---------------------------------------------------------------------------
127-
128-
/**
129-
* @param mixed $v
130-
* @return string
131-
*/
132-
function get_seconds_selectoptions($v): string {}
133-
134-
/**
135-
* @param mixed $v
136-
* @return string
137-
*/
138-
function get_playbackrate_selectoptions($v): string {}
139-
140-
/**
141-
* @param mixed $value
142-
* @return string
143-
*/
144-
function get_checked($value): string {}
145-
146-
/**
147-
* @param mixed $value
148-
* @param mixed $selval
149-
* @return string
150-
*/
151-
function get_selected($value, $selval): string {}
152-
153-
/**
154-
* @param mixed $v
155-
* @param bool $all
156-
* @param bool $not9899
157-
* @param bool $off
158-
* @return string
159-
*/
160-
function get_wordstatus_selectoptions($v, $all, $not9899, $off = true): string {}
161-
162-
/**
163-
* @param mixed $v
164-
* @return string
165-
*/
166-
function get_tagsort_selectoptions($v): string {}
167-
168-
// ---------------------------------------------------------------------------
169-
// From TagService / tags.php
170-
// ---------------------------------------------------------------------------
171-
172-
/**
173-
* @param int $refresh
174-
* @return array<int, string>
175-
*/
176-
function get_tags($refresh = 0): array {}
177-
178-
/**
179-
* @param int $refresh
180-
* @return array<int, string>
181-
*/
182-
function get_texttags($refresh = 0): array {}
183-
184-
// ---------------------------------------------------------------------------
185-
// From status/scoring utilities
186-
// ---------------------------------------------------------------------------
187-
188-
/**
189-
* @return array<int, array{name: string, abbr: string}>
190-
*/
191-
function get_statuses(): array {}
192-
193-
/**
194-
* @param string $fieldname
195-
* @param int $statusrange
196-
* @return string
197-
*/
198-
function makeStatusCondition($fieldname, $statusrange): string {}
199-
200-
/**
201-
* @param int $currstatus
202-
* @param int $statusrange
203-
* @return bool
204-
*/
205-
function checkStatusRange($currstatus, $statusrange): bool {}
206-
207-
/**
208-
* @param string $type
209-
* @return string
210-
*/
211-
function make_score_random_insert_update($type): string {}
212-
213-
/**
214-
* @param int $method
215-
* @return string
216-
*/
217-
function getsqlscoreformula($method): string {}
218-
219-
} // end global namespace
66+
}

src/backend/Controllers/TextController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use Lwt\Services\TextService;
1919
use Lwt\Services\TextDisplayService;
20+
use Lwt\Services\TextNavigationService;
2021
use Lwt\Services\TagService;
2122
use Lwt\Services\LanguageService;
2223
use Lwt\Services\LanguageDefinitions;
@@ -518,7 +519,7 @@ public function display(array $params): void
518519
$rtlScript = $settings['rtlScript'];
519520

520521
// Get navigation links
521-
$textLinks = \getPreviousAndNextTextLinks(
522+
$textLinks = (new TextNavigationService())->getPreviousAndNextTextLinks(
522523
$textId,
523524
'display_impr_text.php?text=',
524525
true,

src/backend/Services/ExportService.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @since 3.0.0
2020
*/
2121

22-
namespace Lwt\Services {
22+
namespace Lwt\Services;
2323

2424
use Lwt\Database\Connection;
2525

@@ -425,5 +425,3 @@ private function sendDownloadResponse(string $content, string $filename): never
425425
exit();
426426
}
427427
}
428-
429-
} // End namespace Lwt\Services

src/backend/Services/SentenceService.php

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @since 3.0.0 Migrated from Core/Text/sentence_operations.php
1616
*/
1717

18-
namespace Lwt\Services {
18+
namespace Lwt\Services;
1919

2020
use Lwt\Core\Globals;
2121
use Lwt\Core\StringUtils;
@@ -747,31 +747,3 @@ public function renderExampleSentencesArea(int $lang, string $termlc, string $ta
747747
return ob_get_clean();
748748
}
749749
}
750-
751-
} // End namespace Lwt\Services
752-
753-
namespace {
754-
755-
// =============================================================================
756-
// GLOBAL FUNCTION WRAPPERS (for backward compatibility)
757-
// =============================================================================
758-
759-
use Lwt\Services\SentenceService;
760-
761-
/**
762-
* Prepare the area for example sentences of a word.
763-
*
764-
* @param int $lang Language ID
765-
* @param string $termlc Term text in lowercase
766-
* @param string $selector JS selector for target textarea
767-
* @param int $wid Word ID
768-
*
769-
* @return void Outputs HTML directly
770-
*/
771-
function exampleSentencesArea(int $lang, string $termlc, string $selector, int $wid): void
772-
{
773-
$service = new SentenceService();
774-
echo $service->renderExampleSentencesArea($lang, $termlc, $selector, $wid);
775-
}
776-
777-
} // End global namespace

src/backend/Services/SimilarTermsService.php

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @since 3.0.0 Migrated from Core/Text/simterms.php
1313
*/
1414

15-
namespace Lwt\Services {
15+
namespace Lwt\Services;
1616

1717
use Lwt\Core\Globals;
1818
use Lwt\Database\Connection;
@@ -452,26 +452,3 @@ public function printSimilarTermsTabRow(): string
452452
return '';
453453
}
454454
}
455-
456-
} // End namespace Lwt\Services
457-
458-
namespace {
459-
460-
// =============================================================================
461-
// GLOBAL FUNCTION WRAPPERS (for backward compatibility)
462-
// =============================================================================
463-
464-
use Lwt\Services\SimilarTermsService;
465-
466-
/**
467-
* Print a row for similar terms if the feature is enabled.
468-
*
469-
* @return string HTML output
470-
*/
471-
function printSimilarTermsTabRow(): string
472-
{
473-
$service = new SimilarTermsService();
474-
return $service->printSimilarTermsTabRow();
475-
}
476-
477-
} // End global namespace

src/backend/Services/TextNavigationService.php

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @since 3.0.0 Migrated from Core/Text/text_navigation.php
1313
*/
1414

15-
namespace Lwt\Services {
15+
namespace Lwt\Services;
1616

1717
use Lwt\Core\Globals;
1818
use Lwt\Core\Http\InputValidator;
@@ -174,13 +174,13 @@ public function getPreviousAndNextTextLinks(int $textId, string $url, bool $only
174174
for ($i = 1; $i < $listlen - 1; $i++) {
175175
if ($list[$i] == $textId) {
176176
if ($list[$i - 1] !== 0) {
177-
$title = htmlspecialchars(getTextTitle($list[$i - 1]), ENT_QUOTES, 'UTF-8');
177+
$title = htmlspecialchars(self::getTextTitle($list[$i - 1]), ENT_QUOTES, 'UTF-8');
178178
$prev = '<a href="' . $url . $list[$i - 1] . '" target="_top">' . IconHelper::render('circle-chevron-left', ['title' => 'Previous Text: ' . $title, 'alt' => 'Previous Text: ' . $title]) . '</a>';
179179
} else {
180180
$prev = IconHelper::render('circle-chevron-left', ['title' => 'No Previous Text', 'alt' => 'No Previous Text', 'class' => 'icon-muted']);
181181
}
182182
if ($list[$i + 1] !== 0) {
183-
$title = htmlspecialchars(getTextTitle($list[$i + 1]), ENT_QUOTES, 'UTF-8');
183+
$title = htmlspecialchars(self::getTextTitle($list[$i + 1]), ENT_QUOTES, 'UTF-8');
184184
$next = '<a href="' . $url . $list[$i + 1] .
185185
'" target="_top">' . IconHelper::render('circle-chevron-right', ['title' => 'Next Text: ' . $title, 'alt' => 'Next Text: ' . $title]) . '</a>';
186186
} else {
@@ -192,50 +192,19 @@ public function getPreviousAndNextTextLinks(int $textId, string $url, bool $only
192192
return $add . IconHelper::render('circle-chevron-left', ['title' => 'No Previous Text', 'alt' => 'No Previous Text', 'class' => 'icon-muted']) . '
193193
' . IconHelper::render('circle-chevron-right', ['title' => 'No Next Text', 'alt' => 'No Next Text', 'class' => 'icon-muted']);
194194
}
195-
}
196-
197-
} // End namespace Lwt\Services
198-
199-
namespace {
200-
201-
// =============================================================================
202-
// GLOBAL FUNCTION WRAPPERS (for backward compatibility)
203-
// =============================================================================
204-
205-
use Lwt\Services\TextNavigationService;
206-
use Lwt\Database\QueryBuilder;
207-
208-
/**
209-
* Get the title of a text by its ID.
210-
*
211-
* @param int $textId Text ID
212-
*
213-
* @return string Text title, or empty string if not found
214-
*/
215-
function getTextTitle(int $textId): string
216-
{
217-
$result = QueryBuilder::table('texts')
218-
->where('TxID', '=', $textId)
219-
->valuePrepared('TxTitle');
220-
return $result !== null ? (string) $result : '';
221-
}
222195

223-
/**
224-
* Return navigation arrows to previous and next texts.
225-
*
226-
* @param int $textid ID of the current text
227-
* @param string $url Base URL to append before $textid
228-
* @param bool $onlyann Restrict to annotated texts only
229-
* @param string $add Some content to add before the output
230-
*
231-
* @return string Arrows to previous and next texts.
232-
*
233-
* @see \Lwt\Services\TextNavigationService::getPreviousAndNextTextLinks()
234-
*/
235-
function getPreviousAndNextTextLinks(int $textid, string $url, bool|int $onlyann, string $add): string
236-
{
237-
$service = new TextNavigationService();
238-
return $service->getPreviousAndNextTextLinks($textid, $url, (bool) $onlyann, $add);
196+
/**
197+
* Get the title of a text by its ID.
198+
*
199+
* @param int $textId Text ID
200+
*
201+
* @return string Text title, or empty string if not found
202+
*/
203+
public static function getTextTitle(int $textId): string
204+
{
205+
$result = QueryBuilder::table('texts')
206+
->where('TxID', '=', $textId)
207+
->valuePrepared('TxTitle');
208+
return $result !== null ? (string) $result : '';
209+
}
239210
}
240-
241-
} // End global namespace

0 commit comments

Comments
 (0)