- Database: extract private buildSearchConditions(array $params): array shared by searchTheses() and countSearchResults(), eliminating ~80 lines of duplication; add array type hints to both public methods - Database: add getThesesList(array $filters) and getAllYears() so admin/index.php no longer builds raw SQL inline - admin/index.php: replace inline PDO query block with $db->getThesesList() / $db->getAllYears(); drop the now-unused $pdo local - config/bootstrap.php: remove dead include_template() helper and the vendor/autoload.php Composer stub (no vendor/ directory exists) - apps/: delete entire directory (leftover artefact, no code references it) - tests/Integration/SearchTest.php: fix three searchTheses() calls from bare strings to proper array params to match the method signature (prevented TypeError)
6.4 KiB
Post-ERG – Dependency & Refactoring Analysis
Summary
The project has zero external PHP library dependencies (no Composer, no vendor/).
All PHP logic relies exclusively on standard PHP extensions: PDO/SQLite, finfo,
session_*, password_verify, hash_equals, random_bytes, json_*, SPL iterators.
There is one vendored CSS file (modern-normalize.min.css, 1 file, 8 lines).
The only real problems are internal structural bugs and dead code paths, not third-party dependencies. The tasks below are ordered from critical to nice-to-have.
Critical Bugs (broken at runtime)
-
Fix broken
lib/require paths in all admin pages Admin pages (add.php,edit.php,import.php,thanks.php,login.php,logout.php,actions/formulaire.php,actions/publish.php) all require../../lib/AdminAuth.phpand../../lib/Database.php, but thelib/directory does not exist. The actual files live insrc/. This means the entire admin panel is broken. Fix: change alllib/references tosrc/. -
Fix missing
modern-normalize.css(no.minvariant)templates/header.php,templates/head.php, andpublic/search.phpreferenceassets/modern-normalize.css(without.min), but onlymodern-normalize.min.cssexists. Either rename the file or update the references to be consistent. -
Fix
admin/index.phpinconsistencyadmin/index.phpusessrc/AdminAuth.php(correct) but then../../lib/Database.php(broken). It should load fromsrc/consistently.
Structural / Code-Quality Refactors
-
Unify and rename
src/path references across the entire codebase After fixing thelib/→src/migration, normalise every admin page to loadsrc/Database.phpandsrc/AdminAuth.phpviaAPP_ROOT(the constant already defined inbootstrap.php), removing the fragile relative-path../../chains. -
Eliminate the duplicate
searchTheses/countSearchResultscondition blockDatabase::searchTheses()andDatabase::countSearchResults()share identical WHERE-clause construction logic (~80 lines each). Extract a privatebuildSearchConditions(array $params): arrayhelper that returns[$conditions, $bindings]and call it from both methods. -
Remove
getConnection()/getPDO()alias duplication TheDatabaseclass exposesgetConnection(),getPDO(), and direct transaction delegation (beginTransaction,commit,rollback) purely because the admin code accesses raw PDO. Consider removinggetConnection()(alias ofgetPDO()) and instead promoting the most-used raw queries intoDatabasemethods, reducing direct PDO exposure. -
Move inline SQL in
admin/index.phpintoDatabaseadmin/index.phpbuilds a raw SQL query with dynamic filter conditions directly in the page. This is the only admin page doing so. Add agetThesesList(array $filters): arraymethod toDatabaseto match the pattern used everywhere else. -
Add a
getThesisByIdAdmin(int $id): ?arraymethod to remove repeated raw queries in adminadmin/thanks.phpandadmin/edit.phpeach call$db->getThesis($id)then immediately issue further raw PDO queries for related data (thesis_languages,thesis_formats, files). Consolidate into a method that returns everything needed for the admin detail view.
What Can Be Removed / Simplified
-
Remove
include_template()helper frombootstrap.php— it is never called The functioninclude_template($name)inconfig/bootstrap.phpis dead code; pages use directinclude APP_ROOT . '/templates/...'instead. -
Remove the Composer autoload stub from
bootstrap.phpbootstrap.phphasif (file_exists(APP_ROOT . '/vendor/autoload.php'))— there is no Composer vendor directory and no plan for one. Remove this dead branch. -
Delete
apps/admin/directoryapps/admin/contains onlydata/(empty with test data) anderror.logandtest.db. It appears to be a leftover from an earlier structure. If confirmed unused, delete it. -
Remove
apps/directory entirely if it contains only residual artefacts Related to the above — verify no active code referencesapps/.
What Needs External Dependencies (nothing — keep it that way)
- Authentication:
password_verify+session_*+random_bytes— already standard PHP. No dependency needed. - Database: PDO + SQLite — already standard PHP. No dependency needed.
- Rate limiting: File-based JSON sliding window — already implemented without deps. Could be replaced by Redis/APCu at scale, but unnecessary for current load.
- File serving / MIME validation:
finfo(fileinfo extension) — standard PHP bundled extension. - CSRF:
hash_equals+random_bytes— standard PHP. No dependency needed. - CSS reset (
modern-normalize): The single vendored file (8 lines, minified) is small enough to keep vendored. No CDN link, no build step. ✓
Testing Infrastructure
-
Fix
SearchTest.php— it callssearchTheses()with a string, not an array$db->searchTheses('art')passes a string, butsearchTheses()expectsarray $params. This test would throw a TypeError at runtime. Fix the call to$db->searchTheses(['query' => 'art']). -
Add a test for the
lib/→src/path fix once it is applied After the path fix, add a smoke test thatrequire-s each admin page's dependencies to catch future regressions.
Low Priority / Nice-to-Have
-
Normalise
modern-normalizeto a single canonical filename Pick either.min.cssor.cssand use it everywhere. Prefer.min.csssince the file is already minified. -
Consider extracting file-upload logic from
formulaire.phpintoDatabaseFile validation, directory creation, andinsertThesisFile()are scattered acrossformulaire.php. Wrapping them in aDatabase::attachFile()or a dedicatedFileUploadHandlerclass would makeformulaire.phpmuch shorter and the upload logic testable. -
Unify
head.phpvsheader.phptemplates The public site has bothtemplates/head.php(shared<head>tag) andtemplates/header.php(full<head>+<body><header>).tfe.phpuseshead.phpand renders its own<body>, whileindex.phpusesheader.php. This split is confusing. Consider makingheader.phpthe single entry point.