refactor(globals): shrink the context to what actually carries state - #300
Merged
HugoFara merged 1 commit intoAug 30, 2026
Merged
Conversation
This was referenced Aug 30, 2026
Globals had grown into a grab-bag where only some of the contents did
anything. Four things came out:
- table() was the identity function — `return $tableName;` — left over from
a configurable table prefix that no longer exists. It read as though it
transformed the name, and HomeFacade even carried a comment claiming it
returned "properly prefixed" names. Its 185 call sites are now plain
strings, and the literal concatenations that produced ('DELETE FROM ' .
'words') are folded into single literals.
- query() forwarded one line to QueryBuilder::table(). Callers now say so.
- The error-display flag was set to false by initialize() and never set
true by anything; its single reader passed it straight to
setErrorReporting(). That reader now passes false outright, which is what
it always got. initialize() had nothing left to do and is gone.
- The mysqli handle lived in both Connection::$instance and
Globals::$dbConnection, with getInstance() resyncing from the second on
every call and setInstance() writing both. Connection now owns it alone
and Globals::get/setDbConnection() delegate. The accessors stay because
291 call sites use them as a "is the database up?" probe; the duplicated
storage was the problem, not the name.
One behaviour change falls out: Connection::reset() now genuinely clears the
handle instead of leaving a copy for the next getInstance() to recover.
testResetClearsInstance was asserting the opposite of its own name, so it now
asserts the clear and restores the shared connection for the rest of the run.
Also drops 29 Globals imports left unused by the above, and documents on the
class that the user context is a security boundary QueryBuilder depends on
rather than an ordinary setting.
HugoFara
force-pushed
the
refactor/shrink-globals
branch
from
August 30, 2026 22:14
fc2449e to
0f24088
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack 3 of 6. Base: #299.
Globalsgoes from 505 lines to 353.Most of the file's bulk did nothing. Four things come out:
table()was the identity function — literallyreturn $tableName;, leftover from a configurable table prefix that no longer exists. It read as though
it transformed the name, and
HomeFacadecarried a comment claiming itreturned "properly prefixed" names. Its 185 call sites are now plain
strings, and the literal concatenations that produced
('DELETE FROM ' . 'words')are folded into single literals.query()forwarded one line toQueryBuilder::table(). Callers now say so.falsebyinitialize()and never settrue by anything; its single reader passed it straight to
setErrorReporting(). That reader now passesfalseoutright, which is whatit always got.
initialize()then had nothing left to do.Connection::$instanceandGlobals::$dbConnection— withgetInstance()resyncing from the second onevery call and
setInstance()writing both.Connectionnow owns it aloneand the
Globalsaccessors delegate.Two judgement calls worth a second opinion
The
Globals::get/setDbConnection()accessors stay. 291 call sites use themas an "is the database up?" probe, mostly test skip guards. Rewriting all of
them would be churn for its own sake — the duplicated storage was the problem,
not the name.
Connection::reset()now genuinely clears the handle instead of leaving acopy for the next
getInstance()to recover. This is the one behaviour changein the PR.
testResetClearsInstancewas asserting the opposite of its own name;it now asserts the clear and restores the shared connection for the rest of the
run.
What is deliberately left alone
The user context (
currentUserId,multiUserEnabled,isCurrentUserAdmin) isload-bearing:
QueryBuilderreads it at lines 248/287/292/323/328 to scopeevery query, so a repository that looks unscoped is in fact filtered. That is
now stated on the class as a security boundary rather than a setting. Threading
a
UserIdthrough every repository call is a much larger change where a partialjob is a data-leak bug, so it is not attempted here.
Also drops 29
Globalsimports left unused by the above.Stack: #298 → #299 → 3 → #4 → #5 → #6