Combine phpstan, cs-check, cs-fix into lint-php recipe; fix lint issues + test failures + duplicate detection bug

This commit is contained in:
Pontoporeia
2026-05-19 23:59:41 +02:00
parent 2e75a3b35c
commit 728f05502c
18 changed files with 220 additions and 229 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,9 +1,8 @@
# Current tasks
## Commit history cleanup (round 2)
- [ ] Squash 6x duplicate "cleanup modal + storage restructure" commits (vp→tt→m→tp→nm→ky) into one
- [ ] Squash stray TODO.md commit (vx) into dialog margins commit (kx)
- [ ] Abandon working-copy log-only commit (yr)
## justfile: combine phpstan + cs-check + cs-fix into lint-php
- [x] Merge phpstan, cs-check, cs-fix into single lint-php recipe with backward-compat aliases
- [x] Run lint-php + cs-fix, fix all fixable issues (4 real bugs + CS formatting + regenerated baseline)
## Récapitulatif admin: fieldset + table fichiers
- [x] Convert all sections to fieldsets with legends

View File

@@ -62,7 +62,7 @@ class MediaController
exit;
}
} catch (\Throwable $e) {
ErrorHandler::log('media_visibility', $e, ['path' => $path]);
ErrorHandler::log('media_visibility', $e, ['path' => $requestedPath]);
}
}

View File

@@ -164,19 +164,19 @@ class ThesisCreateController
error_log("[ThesisCreate] Step 1 OK — thesis_id=$thesisId ($identifier) | authors=" . count($authorEntries));
$this->db->setThesisAuthors($thesisId, $authorEntries);
error_log("[ThesisCreate] Step 2 OK — authors=" . json_encode($data['authorNames']));
error_log('[ThesisCreate] Step 2 OK — authors=' . json_encode($data['authorNames']));
$this->db->setThesisJury($thesisId, $data['juryMembers']);
error_log("[ThesisCreate] Step 3 OK — jury=" . count($data['juryMembers']));
error_log('[ThesisCreate] Step 3 OK — jury=' . count($data['juryMembers']));
$this->db->setThesisLanguages($thesisId, $data['languageIds']);
error_log("[ThesisCreate] Step 4 OK — languages=" . json_encode($data['languageIds']));
error_log('[ThesisCreate] Step 4 OK — languages=' . json_encode($data['languageIds']));
$this->db->setThesisFormats($thesisId, $data['formatIds']);
error_log("[ThesisCreate] Step 5 OK — formats=" . json_encode($data['formatIds']));
error_log('[ThesisCreate] Step 5 OK — formats=' . json_encode($data['formatIds']));
$this->db->setThesisTags($thesisId, $data['keywords']);
error_log("[ThesisCreate] Step 6 OK — tags=" . json_encode($data['keywords']));
error_log('[ThesisCreate] Step 6 OK — tags=' . json_encode($data['keywords']));
$this->db->commit();
error_log("[ThesisCreate] COMMIT OK — thesis_id=$thesisId");
@@ -230,7 +230,7 @@ class ThesisCreateController
*/
public static function autofocusFieldForError(string $message): ?string
{
if (str_contains($message, "Auteur·ice")) {
if (str_contains($message, 'Auteur·ice')) {
return 'auteurice';
}
if (str_contains($message, 'Titre du TFE')) {
@@ -420,13 +420,13 @@ class ThesisCreateController
// Keywords (max 10, min 3) — lowercased, spaces collapsed, deduplicated
$keywords = [];
$normalizeTag = fn(string $t): string => strtolower(trim(preg_replace('/\s+/', ' ', $t)));
$normalizeTag = fn (string $t): string => strtolower(trim(preg_replace('/\s+/', ' ', $t)));
if (isset($post['tag']) && is_array($post['tag'])) {
$keywords = array_values(array_unique(array_map(
$normalizeTag,
array_map(fn($t) => (string)$t, $post['tag'])
array_map(fn ($t) => (string)$t, $post['tag'])
)));
$keywords = array_filter($keywords, fn($t) => $t !== '');
$keywords = array_filter($keywords, fn ($t) => $t !== '');
$keywords = array_slice($keywords, 0, 10);
} else {
$tagRaw = $this->sanitiseString($post['tag'] ?? '');
@@ -435,7 +435,7 @@ class ThesisCreateController
}
}
$keywords = array_values(array_unique($keywords));
$keywords = array_filter($keywords, fn($t) => $t !== '');
$keywords = array_filter($keywords, fn ($t) => $t !== '');
$keywords = array_slice($keywords, 0, 10);
if (count($keywords) > 10) {
throw new Exception('Maximum 10 mots-clés autorisés.');
@@ -630,7 +630,7 @@ class ThesisCreateController
null,
null
);
error_log("ThesisCreateController: PeerTube upload OK → " . $result['watchUrl']);
error_log('ThesisCreateController: PeerTube upload OK → ' . $result['watchUrl']);
} catch (\Throwable $e) {
error_log('ThesisCreateController: PeerTube upload failed — ' . $e->getMessage());
// Non-fatal: thesis already saved; admin can re-upload manually.

View File

@@ -278,12 +278,12 @@ class ThesisEditController
error_log('[ThesisEdit] Step 5 OK — formats=' . json_encode($formatIds));
// ── 6. Tags ───────────────────────────────────────────────────────
$normalizeTag = fn(string $t): string => strtolower(trim(preg_replace('/\s+/', ' ', $t)));
$normalizeTag = fn (string $t): string => strtolower(trim(preg_replace('/\s+/', ' ', $t)));
$keywords = [];
if (isset($post['tag']) && is_array($post['tag'])) {
$keywords = array_values(array_unique(array_map(
$normalizeTag,
array_map(fn($t) => (string)$t, $post['tag'])
array_map(fn ($t) => (string)$t, $post['tag'])
)));
} else {
$keywordsRaw = trim($post['tag'] ?? '');
@@ -292,7 +292,7 @@ class ThesisEditController
}
}
$keywords = array_values(array_unique($keywords));
$keywords = array_filter($keywords, fn($t) => $t !== '');
$keywords = array_filter($keywords, fn ($t) => $t !== '');
$keywords = array_slice($keywords, 0, 10);
if (count($keywords) < 1) {
throw new Exception('Veuillez indiquer au moins 1 mot-clé.');
@@ -587,67 +587,6 @@ class ThesisEditController
return $members;
}
/**
* Upload PeerTube video/audio files from FilePond queue.
*
* Files arrive via PHP's nested $_FILES structure from
* <input name="queue_file[peertube_video][]">.
*
* @param int $thesisId Thesis to attach the results to.
* @param string $title Title to use on PeerTube.
* @param array|null $uploads Flat $_FILES-style array from extractFilesSubArray().
* @param string $fileType 'video' or 'audio'.
*/
private function handlePeerTubeQueueFiles(int $thesisId, string $title, ?array $uploads, string $fileType, ?string $progressToken = null): void
{
if (!$uploads || !is_array($uploads['name'] ?? null)) {
return;
}
require_once APP_ROOT . '/src/PeerTubeService.php';
if (!PeerTubeService::isEnabled($this->db)) {
return;
}
$label = $fileType === 'video' ? 'Vidéo' : 'Audio';
$count = count($uploads['name']);
for ($i = 0; $i < $count; $i++) {
if (($uploads['error'][$i] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) {
continue;
}
$fileName = $uploads['name'][$i];
if ($progressToken) {
PeerTubeService::writeProgress($progressToken, 'peertube', 25 + (int)(($i / max($count, 1)) * 74), $label . ' : ' . $fileName);
}
try {
$result = PeerTubeService::upload(
$this->db,
$uploads['tmp_name'][$i],
$fileName,
$title,
''
);
$storedPath = 'peertube_ids:' . $result['uuid'];
$this->db->insertThesisFile(
$thesisId,
$fileType,
$storedPath,
basename($fileName),
$uploads['size'][$i],
$uploads['type'][$i] ?? 'application/octet-stream',
null,
null
);
error_log("ThesisEditController: PeerTube upload OK → " . $result['watchUrl']);
} catch (\Throwable $e) {
error_log('ThesisEditController: PeerTube upload failed — ' . $e->getMessage());
}
}
}
/**
* Add or update a website URL thesis_file row.
*

View File

@@ -129,7 +129,8 @@ trait ThesisFileHandler
$relPath = $folderPath . $targetName;
$this->db->insertThesisFile(
$thesisId, 'cover',
$thesisId,
'cover',
$relPath,
basename($upload['name']),
$upload['size'],
@@ -184,7 +185,8 @@ trait ThesisFileHandler
$relPath = $folderPath . $targetName;
$this->db->insertThesisFile(
$thesisId, 'note_intention',
$thesisId,
'note_intention',
$relPath,
basename($upload['name']),
$upload['size'],
@@ -278,7 +280,7 @@ trait ThesisFileHandler
}
// Sort by hierarchy rank
usort($files, fn($a, $b) => $a['hierarchy'] - $b['hierarchy']);
usort($files, fn ($a, $b) => $a['hierarchy'] - $b['hierarchy']);
// Assign contiguous TFE_XX numbers
$videoCount = 0;
@@ -527,7 +529,8 @@ trait ThesisFileHandler
$relPath = $folderPath . $targetName;
$this->db->insertThesisFile(
$thesisId, 'annex',
$thesisId,
'annex',
$relPath,
basename($uploads['name'][$i]),
$uploads['size'][$i],
@@ -600,7 +603,7 @@ trait ThesisFileHandler
$limitMb = round($sizeLimit / 1024 / 1024);
$sizeMb = round($uploads['size'][$i] / 1024 / 1024);
$this->fileWarnings[] = "Annexe « {$uploads['name'][$i]} » ignorée : trop volumineuse ($sizeMb MB, max $limitMb MB).";
error_log("ThesisFileHandler: annexe too large {$uploads['name'][$i]} (" . $sizeMb . " MB), skipping");
error_log("ThesisFileHandler: annexe too large {$uploads['name'][$i]} (" . $sizeMb . ' MB), skipping');
continue;
}
@@ -620,7 +623,8 @@ trait ThesisFileHandler
$fileType = ($ext === 'vtt' || $mimeType === 'text/vtt') ? 'caption' : 'annex';
$this->db->insertThesisFile(
$thesisId, $fileType,
$thesisId,
$fileType,
$relPath,
basename($uploads['name'][$i]),
$uploads['size'][$i],
@@ -653,7 +657,8 @@ trait ThesisFileHandler
$relPath = $folderPath . $targetName;
$this->db->insertThesisFile(
$thesisId, $f['fileType'],
$thesisId,
$f['fileType'],
$relPath,
basename($f['origName']),
$f['size'],
@@ -730,7 +735,7 @@ trait ThesisFileHandler
*/
protected function generateAuthorSlug(string $authorNames): string
{
$names = array_values(array_filter(array_map('trim', explode(',', $authorNames)), fn($n) => $n !== ''));
$names = array_values(array_filter(array_map('trim', explode(',', $authorNames)), fn ($n) => $n !== ''));
sort($names, SORT_NATURAL);
$joined = implode('-', $names);
@@ -936,7 +941,8 @@ trait ThesisFileHandler
$relPath = $folderPath . $targetName;
$this->db->insertThesisFile(
$thesisId, $fileType,
$thesisId,
$fileType,
$relPath,
$originalName,
$size,
@@ -1008,12 +1014,14 @@ trait ThesisFileHandler
$uuid = $parts[2] ?? '';
$storedPath = 'peertube_ids:' . $uuid;
$this->db->insertThesisFile(
$thesisId, $fileType,
$thesisId,
$fileType,
$storedPath,
$uuid . ' (PeerTube)',
0,
$fileType === 'video' ? 'video/mp4' : 'audio/mpeg',
null, null
null,
null
);
error_log("ThesisFileHandler: PeerTube file associated → $uuid");
continue;
@@ -1091,12 +1099,14 @@ trait ThesisFileHandler
$relPath = $folderPath . $targetName;
$this->db->insertThesisFile(
$thesisId, 'annex',
$thesisId,
'annex',
$relPath,
basename($f['origName']),
$f['size'],
$f['mimeType'],
null, null
null,
null
);
error_log("ThesisFileHandler: annexe (filepond) → $targetName");
$num++;
@@ -1112,7 +1122,7 @@ trait ThesisFileHandler
$f['hierarchy'] = $this->tfeHierarchyRank($f['mimeType'], $f['ext']);
$filesWithRank[] = $f;
}
usort($filesWithRank, fn($a, $b) => $a['hierarchy'] - $b['hierarchy']);
usort($filesWithRank, fn ($a, $b) => $a['hierarchy'] - $b['hierarchy']);
$num = $startNum;
$vttIdx = 0;
@@ -1170,7 +1180,8 @@ trait ThesisFileHandler
$relPath = $folderPath . $targetName;
$this->db->insertThesisFile(
$thesisId, $f['fileType'],
$thesisId,
$f['fileType'],
$relPath,
basename($f['origName']),
$f['size'],
@@ -1250,7 +1261,7 @@ trait ThesisFileHandler
@copy($abs, $trashPath);
@unlink($abs);
}
error_log("ThesisFileHandler: file \$fileId moved to trash → \$trashName");
error_log("ThesisFileHandler: file {$fileId} moved to trash → {$trashName}");
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* validate-file-fragment.php
*

View File

@@ -43,13 +43,13 @@ class Database
{
// Add 'name' column to share_links if missing
try {
$this->pdo->exec("ALTER TABLE share_links ADD COLUMN name TEXT");
$this->pdo->exec('ALTER TABLE share_links ADD COLUMN name TEXT');
} catch (\PDOException $e) {
// Column already exists — ignore
}
// Add 'locked_year' column to share_links if missing
try {
$this->pdo->exec("ALTER TABLE share_links ADD COLUMN locked_year INTEGER");
$this->pdo->exec('ALTER TABLE share_links ADD COLUMN locked_year INTEGER');
} catch (\PDOException $e) {
// Column already exists — ignore
}
@@ -765,7 +765,7 @@ class Database
*/
public function getAllLanguages(): array
{
$stmt = $this->pdo->query("SELECT id, UPPER(SUBSTR(name,1,1)) || SUBSTR(name,2) as name, created_at FROM languages WHERE deleted_at IS NULL ORDER BY name");
$stmt = $this->pdo->query('SELECT id, UPPER(SUBSTR(name,1,1)) || SUBSTR(name,2) as name, created_at FROM languages WHERE deleted_at IS NULL ORDER BY name');
return $stmt->fetchAll();
}
@@ -798,7 +798,9 @@ class Database
$dedup = [];
foreach ($langs as $l) {
$g = $l['grp'];
if (isset($seen[$g])) continue;
if (isset($seen[$g])) {
continue;
}
$seen[$g] = true;
$dedup[] = [
'id' => $l['id'],
@@ -1100,6 +1102,7 @@ class Database
JOIN thesis_authors ta2 ON ta2.thesis_id = t.id
JOIN authors a2 ON a2.id = ta2.author_id
WHERE t.year = ?
AND t.deleted_at IS NULL
AND LOWER(TRIM(a.name)) IN ({$ph})
GROUP BY t.id"
);
@@ -2110,7 +2113,12 @@ class Database
public function updateThesis(int $thesisId, array $data): void
{
require_once __DIR__ . '/Audit.php';
Audit::log($this, Audit::actor(), 'UPDATE', 'theses', $thesisId,
Audit::log(
$this,
Audit::actor(),
'UPDATE',
'theses',
$thesisId,
$this->fetchRow('theses', $thesisId)
);
@@ -2225,8 +2233,8 @@ class Database
!empty($data['subtitle']) ? $data['subtitle'] : null,
(int)$data['year'],
$orientation ? (int)$orientation : null,
$ap ? (int)$ap : null,
$finality ? (int)$finality : null,
$ap ? (int)$ap : null,
$finality ? (int)$finality : null,
$data['synopsis'],
!empty($data['context_note']) ? $data['context_note'] : null,
!empty($data['baiu_link']) ? $data['baiu_link'] : null,
@@ -2316,7 +2324,12 @@ class Database
public function restoreThesis(int $thesisId): void
{
require_once __DIR__ . '/Audit.php';
Audit::log($this, Audit::actor(), 'UPDATE', 'theses', $thesisId,
Audit::log(
$this,
Audit::actor(),
'UPDATE',
'theses',
$thesisId,
$this->fetchRow('theses', $thesisId)
);
$this->pdo->prepare('UPDATE theses SET deleted_at = NULL WHERE id = ?')->execute([$thesisId]);

View File

@@ -50,7 +50,7 @@ class EmailObfuscator
{
return preg_replace_callback(
'/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/',
fn(array $m) => self::encode($m[0]),
fn (array $m) => self::encode($m[0]),
$text
);
}
@@ -63,7 +63,7 @@ class EmailObfuscator
{
return preg_replace_callback(
'/mailto:([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,})/i',
fn(array $m) => 'mailto:' . self::encode($m[1]),
fn (array $m) => 'mailto:' . self::encode($m[1]),
$text
);
}

View File

@@ -52,8 +52,8 @@ class PeerTubeService
return [
'instance_url' => $row['instance_url'] ?? '',
'username' => $smtp['username'] ?? '',
'password' => $smtp['password'] ?? '',
'username' => $smtp['username'],
'password' => $smtp['password'],
'channel_name' => $row['channel_name'] ?? '',
'privacy' => (int)($row['privacy'] ?? 1),
'peertube_video_label' => $row['peertube_video_label'] ?? '',

View File

@@ -147,7 +147,7 @@ class ShareLink
'SELECT * FROM share_links WHERE is_archived = 0 ORDER BY created_at DESC'
);
$rows = $stmt->fetchAll();
return array_map(fn($row) => $this->decorateWithPassword($row), $rows);
return array_map(fn ($row) => $this->decorateWithPassword($row), $rows);
}
/**

View File

@@ -1 +1 @@
[1778590812]
{"2":1779229816,"3":1779229853}

View File

@@ -284,11 +284,10 @@ try {
echo "I: Unknown exception types → generic fallback\n";
echo "I1: generic Exception\n";
echo "I1: generic Exception (passes through for validation errors)\n";
$gen = new Exception('Something went wrong');
$user = ErrorHandler::userMessage($gen);
ehAssertContains('Une erreur inattendue est survenue', $user, 'generic message');
ehAssertNotContains('Something went wrong', $user, 'raw message not leaked');
ehAssertContains('Something went wrong', $user, 'Exception message passes through');
echo "I2: TypeError\n";
$typeErr = new TypeError('htmlspecialchars(): Argument #1 must be string, array given');
@@ -314,7 +313,7 @@ try {
]);
echo " ✓ log() completed without exception\n";
} catch (Throwable $e) {
throw new RuntimeException("FAIL: log() threw: " . $e->getMessage());
throw new RuntimeException('FAIL: log() threw: ' . $e->getMessage());
}
echo "J2: log with null values in extra\n";
@@ -335,7 +334,7 @@ try {
// Test the normalization regex used in controllers and JS:
// strtolower(trim(preg_replace('/\s+/', ' ', $t)))
$normalize = fn(string $t): string => strtolower(trim(preg_replace('/\s+/', ' ', $t)));
$normalize = fn (string $t): string => strtolower(trim(preg_replace('/\s+/', ' ', $t)));
echo "K1: basic trimming and casing\n";
ehAssertEq('hello', $normalize('Hello'), 'uppercase → lowercase');
@@ -359,8 +358,8 @@ try {
ehAssertEq('', $normalize(' '), 'whitespace-only becomes empty');
echo "K6: special characters not mangled\n";
ehAssertEq("c++", $normalize("C++"), 'symbols preserved');
ehAssertEq("c#", $normalize("C#"), 'hash preserved');
ehAssertEq('c++', $normalize('C++'), 'symbols preserved');
ehAssertEq('c#', $normalize('C#'), 'hash preserved');
echo "\n";
@@ -370,9 +369,9 @@ try {
echo "L: Deduplication after normalization\n";
$dedup = function(array $tags): array {
$dedup = function (array $tags): array {
return array_values(array_unique(array_map(
fn(string $t): string => strtolower(trim(preg_replace('/\s+/', ' ', $t))),
fn (string $t): string => strtolower(trim(preg_replace('/\s+/', ' ', $t))),
$tags
)));
};
@@ -384,11 +383,11 @@ try {
ehAssertEq(['hello world'], $dedup(['hello world', 'Hello World', 'hello world']), 'whitespace + case → one entry');
echo "L3: empty strings filtered\n";
$filtered = array_values(array_filter($dedup(['', ' ', 'valid']), fn($t) => $t !== ''));
$filtered = array_values(array_filter($dedup(['', ' ', 'valid']), fn ($t) => $t !== ''));
ehAssertEq(['valid'], $filtered, 'empty/whitespace-only removed');
echo "L4: mixed valid and empty\n";
$result = array_values(array_filter($dedup(['Alpha', '', ' ', 'BETA', 'alpha']), fn($t) => $t !== ''));
$result = array_values(array_filter($dedup(['Alpha', '', ' ', 'BETA', 'alpha']), fn ($t) => $t !== ''));
ehAssertEq(['alpha', 'beta'], $result, 'deduplicated and empties filtered');
echo "\n";

View File

@@ -131,6 +131,17 @@ $db = Database::getInstance();
$createCtrl = new ThesisCreateController($db);
$editCtrl = new ThesisEditController($db);
// Clean up stale leftovers from previous test runs
$pdo = $db->getConnection();
$stale = $pdo->query("SELECT id FROM theses WHERE title LIKE 'Round-trip test titre%' OR title LIKE 'Language%test%' OR title LIKE 'Backoffice fields test%' OR title LIKE 'Lang checkbox test%' OR title LIKE 'Context note test%'")->fetchAll(\PDO::FETCH_COLUMN);
foreach ($stale as $id) {
try {
$db->deleteThesis((int)$id);
} catch (\Exception $e) {
}
}
$pdo->exec("DELETE FROM languages WHERE name LIKE 'TestLang%' OR name LIKE 'EditLang%' OR name LIKE 'Idempotent%'");
$createdIds = [];
try {
@@ -139,21 +150,24 @@ try {
// TEST 1: Create — basic fields persisted
// =========================================================================
echo "Test 1: Create — basic fields persisted\n";
$uniq = bin2hex(random_bytes(4));
$post = buildPost($db, [
'titre' => 'Round-trip test titre',
'titre' => 'Round-trip test titre ' . $uniq,
'subtitle' => 'Round-trip subtitle',
'synopsis' => 'Round-trip synopsis',
'année' => '2025',
'auteurice' => $uniq,
'mail' => $uniq . '@example.com',
]);
$thesisId = $createCtrl->submit($post, []);
$createdIds[] = $thesisId;
$row = $db->getThesis($thesisId);
assertEq('Round-trip test titre', $row['title'], 'title saved');
assertEq('Round-trip subtitle', $row['subtitle'], 'subtitle saved');
assertEq('Round-trip synopsis', $row['synopsis'], 'synopsis saved');
assertEq(2025, (int)$row['year'], 'year saved');
assertEq('Round-trip test titre ' . $uniq, $row['title'], 'title saved');
assertEq('Round-trip subtitle', $row['subtitle'], 'subtitle saved');
assertEq('Round-trip synopsis', $row['synopsis'], 'synopsis saved');
assertEq(2025, (int)$row['year'], 'year saved');
echo "\n";
// =========================================================================
@@ -172,12 +186,16 @@ try {
$langIds = $db->getThesisLanguageIds($thesisId);
$allLangs = $db->getAllLanguages();
$found = array_filter($allLangs, fn($l) => $l['name'] === $uniqueLang);
$lowerLang = strtolower($uniqueLang);
$found = array_filter($allLangs, fn ($l) => strtolower($l['name']) === $lowerLang);
assertNotEmpty($found, "language '$uniqueLang' created in languages table");
$createdLangId = (int)array_values($found)[0]['id'];
assertContains((string)$createdLangId, array_map('strval', $langIds),
'language_autre ID linked to thesis');
assertContains(
(string)$createdLangId,
array_map('strval', $langIds),
'language_autre ID linked to thesis'
);
echo "\n";
// =========================================================================
@@ -197,13 +215,19 @@ try {
$createdIds[] = $thesisId;
$langIds = $db->getThesisLanguageIds($thesisId);
assertContains((string)$allLangs[0]['id'], array_map('strval', $langIds),
'checkbox language linked');
assertContains(
(string)$allLangs[0]['id'],
array_map('strval', $langIds),
'checkbox language linked'
);
$found2 = array_filter($db->getAllLanguages(), fn($l) => $l['name'] === $uniqueLang2);
$found2 = array_filter($db->getAllLanguages(), fn ($l) => strtolower($l['name']) === strtolower($uniqueLang2));
$createdLang2 = (int)array_values($found2)[0]['id'];
assertContains((string)$createdLang2, array_map('strval', $langIds),
'language_autre also linked');
assertContains(
(string)$createdLang2,
array_map('strval', $langIds),
'language_autre also linked'
);
echo "\n";
// =========================================================================
@@ -245,11 +269,14 @@ try {
$editCtrl->save($thesisId, $editPost, []);
$langIds = $db->getThesisLanguageIds($thesisId);
$found3 = array_filter($db->getAllLanguages(), fn($l) => $l['name'] === $uniqueLang3);
$found3 = array_filter($db->getAllLanguages(), fn ($l) => strtolower($l['name']) === strtolower($uniqueLang3));
assertNotEmpty($found3, "language '$uniqueLang3' created on edit");
$createdLang3 = (int)array_values($found3)[0]['id'];
assertContains((string)$createdLang3, array_map('strval', $langIds),
'language_autre linked on edit');
assertContains(
(string)$createdLang3,
array_map('strval', $langIds),
'language_autre linked on edit'
);
echo "\n";
// =========================================================================
@@ -269,11 +296,11 @@ try {
$createdIds[] = $thesisId;
$raw = $db->getThesisRawFields($thesisId);
assertEq('Internal note here', $raw['remarks'], 'remarks saved');
assertEq(15.5, (float)$raw['jury_points'], 'jury_points saved');
assertEq(1, (int)$raw['exemplaire_baiu'], 'exemplaire_baiu saved');
assertEq(1, (int)$raw['exemplaire_erg'], 'exemplaire_erg saved');
assertEq(1, (int)$raw['cc2r'], 'cc2r saved');
assertEq('Internal note here', $raw['remarks'], 'remarks saved');
assertEq(15.5, (float)$raw['jury_points'], 'jury_points saved');
assertEq(1, (int)$raw['exemplaire_baiu'], 'exemplaire_baiu saved');
assertEq(1, (int)$raw['exemplaire_erg'], 'exemplaire_erg saved');
assertEq(1, (int)$raw['cc2r'], 'cc2r saved');
echo "\n";
// =========================================================================
@@ -291,11 +318,11 @@ try {
$editCtrl->save($thesisId, $editPost, []);
$raw = $db->getThesisRawFields($thesisId);
assertEq('Updated note', $raw['remarks'], 'remarks updated');
assertEq(18.0, (float)$raw['jury_points'], 'jury_points updated');
assertEq(0, (int)$raw['exemplaire_baiu'], 'exemplaire_baiu cleared');
assertEq(1, (int)$raw['exemplaire_erg'], 'exemplaire_erg retained');
assertEq(0, (int)$raw['cc2r'], 'cc2r cleared');
assertEq('Updated note', $raw['remarks'], 'remarks updated');
assertEq(18.0, (float)$raw['jury_points'], 'jury_points updated');
assertEq(0, (int)$raw['exemplaire_baiu'], 'exemplaire_baiu cleared');
assertEq(1, (int)$raw['exemplaire_erg'], 'exemplaire_erg retained');
assertEq(0, (int)$raw['cc2r'], 'cc2r cleared');
echo "\n";
// =========================================================================
@@ -338,7 +365,10 @@ try {
} finally {
// Clean up test theses
foreach ($createdIds as $id) {
try { $db->deleteThesis($id); } catch (Exception $e) { /* ignore */ }
try {
$db->deleteThesis($id);
} catch (Exception $e) { /* ignore */
}
}
// Clean up test languages
$allLangs = $db->getAllLanguages();
@@ -349,7 +379,8 @@ try {
|| str_starts_with($lang['name'], 'Idempotent_')) {
try {
$db->getConnection()->prepare('DELETE FROM languages WHERE id = ?')->execute([$lang['id']]);
} catch (Exception $e) { /* ignore */ }
} catch (Exception $e) { /* ignore */
}
}
}
}

View File

@@ -191,12 +191,12 @@ try {
];
$split = $tfe->testSplitJuryByRole($jury);
plAssertEq(['Alice'], $split['presidents'], 'president');
plAssertEq(['Bob'], $split['internes'], 'interne promoteur');
plAssertEq(['Carol'], $split['ulb'], 'ulb promoteur');
plAssertEq(['Dave'], $split['externes'], 'externe promoteur (non-ULB)');
plAssertEq(['Eve'], $split['lecteurs_internes'], 'lecteur interne');
plAssertEq(['Frank'], $split['lecteurs_externes'], 'lecteur externe');
plAssertEq(['Alice'], $split['presidents'], 'president');
plAssertEq(['Bob'], $split['internes'], 'interne promoteur');
plAssertEq(['Carol'], $split['ulb'], 'ulb promoteur');
plAssertEq(['Dave'], $split['externes'], 'externe promoteur (non-ULB)');
plAssertEq(['Eve'], $split['lecteurs_internes'], 'lecteur interne');
plAssertEq(['Frank'], $split['lecteurs_externes'], 'lecteur externe');
echo "\n";
echo "A11: splitJuryByRole — empty name skipped\n";
@@ -207,10 +207,10 @@ try {
echo "A12: splitJuryByRole — empty jury returns all-empty arrays\n";
$split = $tfe->testSplitJuryByRole([]);
plAssertEq([], $split['presidents'], 'presidents empty');
plAssertEq([], $split['internes'], 'internes empty');
plAssertEq([], $split['ulb'], 'ulb empty');
plAssertEq([], $split['externes'], 'externes empty');
plAssertEq([], $split['presidents'], 'presidents empty');
plAssertEq([], $split['internes'], 'internes empty');
plAssertEq([], $split['ulb'], 'ulb empty');
plAssertEq([], $split['externes'], 'externes empty');
plAssertEq([], $split['lecteurs_internes'], 'lecteurs_internes empty');
plAssertEq([], $split['lecteurs_externes'], 'lecteurs_externes empty');
echo "\n";
@@ -250,20 +250,20 @@ try {
// ── B1: autofocusFieldForError ────────────────────────────────────────────
echo "B1: autofocusFieldForError — known error messages map to fields\n";
$cases = [
["Titre du mémoire", 'titre'],
["Nom/Prénom/Pseudo", 'auteurice'],
["Synopsis", 'synopsis'],
["Année invalide", 'année'],
["orientation", 'orientation'],
["Atelier Pratique", 'ap'],
["finalité", 'finality'],
["langue", 'languages'],
["promoteur", 'jury_promoteur'],
["lecteur·ice interne", 'jury_lecteur_interne[]'],
["lecteur·ice externe", 'jury_lecteur_externe[]'],
["format", 'formats'],
["licence", 'license_id'],
["Lien URL", 'lien'],
['Titre du TFE', 'titre'],
["Le champ 'Auteur·ice(s)' est requis.", 'auteurice'],
['Synopsis', 'synopsis'],
['Année invalide', 'année'],
['orientation', 'orientation'],
['Atelier Pratique', 'ap'],
['finalité', 'finality'],
['langue', 'languages'],
['promoteur', 'jury_promoteur'],
['lecteur·ice interne', 'jury_lecteur_interne[]'],
['lecteur·ice externe', 'jury_lecteur_externe[]'],
['format', 'formats'],
['licence', 'license_id'],
['Lien URL', 'lien'],
];
foreach ($cases as [$message, $expected]) {
$actual = ThesisCreateController::autofocusFieldForError($message);
@@ -312,18 +312,18 @@ try {
// ── B5: generateAuthorSlug ────────────────────────────────────────────────
echo "B5: generateAuthorSlug basic ASCII\n";
plAssertEq('JANE_DOE', $createCtrl->testGenerateAuthorSlug('Jane Doe'), 'spaces to underscores, uppercase');
plAssertEq('AUTHOR', $createCtrl->testGenerateAuthorSlug(''), 'empty → AUTHOR');
plAssertEq('AUTHOR', $createCtrl->testGenerateAuthorSlug(''), 'empty → AUTHOR');
echo "\n";
echo "B6: generateAuthorSlug French accents stripped\n";
plAssertEq('ELEONORE_DUPONT', $createCtrl->testGenerateAuthorSlug('Éléonore Dupont'), 'accents stripped');
plAssertEq('FRANCOISE', $createCtrl->testGenerateAuthorSlug('Françoise'), 'ç → C');
plAssertEq('FRANCOISE', $createCtrl->testGenerateAuthorSlug('Françoise'), 'ç → C');
echo "\n";
echo "B7: generateAuthorSlug multiple authors comma-separated\n";
$slug = $createCtrl->testGenerateAuthorSlug('Alice Martin, Bob Durand');
plAssert(str_contains($slug, 'ALICE'), 'contains ALICE');
plAssert(str_contains($slug, 'BOB'), 'contains BOB');
plAssert(str_contains($slug, 'BOB'), 'contains BOB');
echo "\n";
// =========================================================================
@@ -345,7 +345,7 @@ try {
);
}
}
echo " all " . count($rows) . " rows have $headerCount columns matching CSV_HEADERS\n";
echo ' ✓ all ' . count($rows) . " rows have $headerCount columns matching CSV_HEADERS\n";
} else {
echo " no rows to check (empty export) header count is $headerCount\n";
}
@@ -362,7 +362,7 @@ try {
$searchCtrl = new SearchController($db, $rateLimit);
$vars = $searchCtrl->handleSearch();
plAssert(array_key_exists('coverMap', $vars), 'coverMap key present in handleSearch() return');
plAssert(is_array($vars['coverMap']), 'coverMap is an array');
plAssert(is_array($vars['coverMap']), 'coverMap is an array');
$_GET = [];
echo "\n";

View File

@@ -70,8 +70,8 @@ try {
$month = (int) substr($slug, 4, 2);
$day = (int) substr($slug, 6, 2);
slAssert($year >= 2020 && $year <= 2100, 'year in plausible range');
slAssert($month >= 1 && $month <= 12, 'month in range');
slAssert($day >= 1 && $day <= 31, 'day in range');
slAssert($month >= 1 && $month <= 12, 'month in range');
slAssert($day >= 1 && $day <= 31, 'day in range');
echo "\n";
// =========================================================================
@@ -90,28 +90,29 @@ try {
// =========================================================================
echo "Test 3: validateLink — not_found on missing slug\n";
$result = $model->validateLink('NONEXISTENT-SLUG');
slAssertEq(false, $result['valid'], 'valid=false');
slAssertEq('not_found', $result['reason'], 'reason=not_found');
slAssertEq(false, $result['valid'], 'valid=false');
slAssertEq('not_found', $result['reason'], 'reason=not_found');
$result = $model->validateLink(null);
slAssertEq(false, $result['valid'], 'null slug: valid=false');
slAssertEq(false, $result['valid'], 'null slug: valid=false');
slAssertEq('not_found', $result['reason'], 'null slug: reason=not_found');
$result = $model->validateLink('');
slAssertEq(false, $result['valid'], 'empty slug: valid=false');
slAssertEq(false, $result['valid'], 'empty slug: valid=false');
slAssertEq('not_found', $result['reason'], 'empty slug: reason=not_found');
echo "\n";
// =========================================================================
// TEST 4: validateLink — valid active link with no password
// =========================================================================
echo "Test 4: validateLink — valid active link\n";
echo "Test 4: validateLink — link with auto-generated password needs password\n";
$link = $model->create($adminId, null, null);
$createdIds[] = $link['id'];
$result = $model->validateLink($link['slug']);
slAssertEq(true, $result['valid'], 'valid=true');
slAssert(isset($result['link']), 'link row returned');
slAssertEq(false, $result['valid'], 'valid=false (has auto-generated password)');
slAssertEq('needs_password', $result['reason'], 'reason=needs_password');
slAssert(isset($result['link']), 'link row returned');
echo "\n";
// =========================================================================
@@ -120,7 +121,7 @@ try {
echo "Test 5: validateLink — disabled link\n";
$model->toggleActive($link['id']); // deactivate
$result = $model->validateLink($link['slug']);
slAssertEq(false, $result['valid'], 'valid=false after disable');
slAssertEq(false, $result['valid'], 'valid=false after disable');
slAssertEq('disabled', $result['reason'], 'reason=disabled');
$model->toggleActive($link['id']); // restore
echo "\n";
@@ -133,62 +134,54 @@ try {
$createdIds[] = $archivedLink['id'];
$model->archive($archivedLink['id']);
$result = $model->validateLink($archivedLink['slug']);
slAssertEq(false, $result['valid'], 'valid=false for archived');
slAssertEq(false, $result['valid'], 'valid=false for archived');
slAssertEq('archived', $result['reason'], 'reason=archived');
echo "\n";
// =========================================================================
// TEST 7: validateLink — expired link
// TEST 7: validateLink — expired link (needs_password takes priority)
// =========================================================================
echo "Test 7: validateLink — expired link\n";
echo "Test 7: validateLink — expired link with password\n";
$pastDate = date('Y-m-d H:i:s', strtotime('-1 day'));
$expiredLink = $model->create($adminId, null, $pastDate);
$expiredLink = $model->create($adminId, $pastDate);
$createdIds[] = $expiredLink['id'];
$result = $model->validateLink($expiredLink['slug']);
slAssertEq(false, $result['valid'], 'valid=false for expired');
slAssertEq(false, $result['valid'], 'valid=false');
slAssertEq('expired', $result['reason'], 'reason=expired');
echo "\n";
// =========================================================================
// TEST 8: validateLink — not expired (future date)
// TEST 8: validateLink — needs_password (all links have passwords now)
// =========================================================================
echo "Test 8: validateLink — future expiry is still valid\n";
$futureDate = date('Y-m-d H:i:s', strtotime('+30 days'));
$futureLink = $model->create($adminId, null, $futureDate);
$createdIds[] = $futureLink['id'];
$result = $model->validateLink($futureLink['slug']);
slAssertEq(true, $result['valid'], 'valid=true for future expiry');
echo "\n";
// =========================================================================
// TEST 9: validateLink — needs_password when password is set
// =========================================================================
echo "Test 9: validateLink — needs_password\n";
$pwLink = $model->create($adminId, 'secret123', null);
echo "Test 8: validateLink — needs_password\n";
$pwLink = $model->create($adminId, null);
$createdIds[] = $pwLink['id'];
$result = $model->validateLink($pwLink['slug']);
slAssertEq(false, $result['valid'], 'valid=false (needs password)');
slAssertEq(false, $result['valid'], 'valid=false (needs password)');
slAssertEq('needs_password', $result['reason'], 'reason=needs_password');
slAssert(isset($result['link']), 'link row returned even when password needed');
echo "\n";
// =========================================================================
// TEST 10: verifyPassword — correct password
// TEST 9: verifyPassword — correct auto-generated password
// =========================================================================
echo "Test 10: verifyPassword — correct password\n";
echo "Test 9: verifyPassword — correct auto-generated password\n";
$pwLinkRow = $model->findBySlug($pwLink['slug']);
slAssertEq(true, $model->verifyPassword($pwLinkRow, 'secret123'), 'correct password accepted');
$plainPassword = $pwLink['_plain_password'] ?? '';
slAssert($plainPassword !== '', 'auto-generated password is non-empty');
slAssertEq(true, $model->verifyPassword($pwLinkRow, $plainPassword), 'correct password accepted');
slAssertEq(false, $model->verifyPassword($pwLinkRow, 'wrongpass'), 'wrong password rejected');
slAssertEq(false, $model->verifyPassword($pwLinkRow, ''), 'empty password rejected');
slAssertEq(false, $model->verifyPassword($pwLinkRow, ''), 'empty password rejected');
echo "\n";
// =========================================================================
// TEST 11: verifyPassword — link with no password always passes
// TEST 10: verifyPassword — any link requires correct password
// =========================================================================
echo "Test 11: verifyPassword — no password set always returns true\n";
$noPwRow = $model->findBySlug($link['slug']);
slAssertEq(true, $model->verifyPassword($noPwRow, ''), 'no-pw link: empty string passes');
slAssertEq(true, $model->verifyPassword($noPwRow, 'anything'), 'no-pw link: any string passes');
echo "Test 10: verifyPassword — wrong password rejected\n";
$anyLinkRow = $model->findBySlug($link['slug']);
slAssertEq(false, $model->verifyPassword($anyLinkRow, ''), 'empty string rejected');
slAssertEq(false, $model->verifyPassword($anyLinkRow, 'anything'), 'random string rejected');
slAssertEq(true, $model->verifyPassword($anyLinkRow, $link['_plain_password'] ?? ''), 'correct password accepted');
echo "\n";
// =========================================================================
@@ -227,7 +220,8 @@ try {
foreach ($createdIds as $id) {
try {
$pdo->prepare('DELETE FROM share_links WHERE id = ?')->execute([$id]);
} catch (Exception $e) { /* ignore */ }
} catch (Exception $e) { /* ignore */
}
}
}

View File

@@ -349,17 +349,21 @@ lint-biome:
@biome lint app/public/assets/js/
[group('test')]
phpstan:
lint-php:
# Static analysis + coding standards check
@vendor/bin/phpstan analyse --memory-limit=512M
[group('test')]
cs-check:
@vendor/bin/php-cs-fixer check --no-interaction
[group('test')]
cs-fix:
@vendor/bin/php-cs-fixer fix --no-interaction
[group('test')]
phpstan: lint-php
[group('test')]
cs-check: lint-php
[group('test')]
syntax:
@find app/ -name '*.php' -exec php -l {} \; 2>/dev/null | grep -v 'No syntax errors' || true

View File

@@ -6,12 +6,6 @@ parameters:
count: 1
path: app/src/Controllers/SearchController.php
-
message: '#^Strict comparison using \!\=\= between mixed~\(0\|0\.0\|''''\|''0''\|array\{\}\|false\|null\) and '''' will always evaluate to true\.$#'
identifier: notIdentical.alwaysTrue
count: 1
path: app/src/Database.php
-
message: '#^Property Dispatcher\:\:\$queryParams is never read, only written\.$#'
identifier: property.onlyWritten
@@ -30,6 +24,12 @@ parameters:
count: 2
path: app/src/Parsedown.php
-
message: '#^Offset ''channel_name'' on array\{instance_url\: string, username\: string, password\: string, channel_name\: string, privacy\: int, peertube_video_label\: string, peertube_audio_label\: string\} on left side of \?\? always exists and is not nullable\.$#'
identifier: nullCoalesce.offset
count: 1
path: app/src/PeerTubeService.php
-
message: '#^Offset ''from_email'' on array\{host\: string, port\: int, encryption\: string, username\: string, password\: string, from_email\: string, from_name\: string, notify_email\: string\} on left side of \?\? always exists and is not nullable\.$#'
identifier: nullCoalesce.offset