Skip to content

[access] refactor(quota): split the quota read and the quota decision into named steps - #5961

Merged
rubenvdlinde merged 3 commits into
developmentfrom
quality/i21-tenant-quota
Nov 12, 2026
Merged

rubenvdlinde merged 3 commits into
developmentfrom
quality/i21-tenant-quota

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

What changed

TenantQuotaService::getQuota and ::decide read as short lists of steps:

  • getQuota() builds its findAll() config through quotaQuery() (with its comment) and reads the first row through firstQuotaRow(); the row read and the Organisation limit overlay stay inside the same catch, so a failure anywhere still answers null.
  • decide() answers unlimited for a missing limit, the hard-limit decision through exceededDecision() (the block / throttle / warn answers are now the EXCEEDED_DECISIONS map, any other enforcement still warns) and the allowed decision through allowDecision() (soft once the warning threshold is reached).

Behaviour is unchanged: the same decisions, soft flags and reasons at every boundary, the same query, the same null answers.

Not touched: initialize() and persistQuota() (open #5353) and resetIfDue() (open #4882).

Characterisation tests (committed first, green on the old code)

Added to TenantQuotaServiceTest: testEveryDecisionIsExact (unlimited, within the limit, at the warning threshold, at the limit itself, a string limit, a custom warning percent, a larger increment, block, throttle, warn and an unknown enforcement, each as the whole answer) and testAQuotaReadThatThrowsAnswersNull. Mutation check: refusing at the limit instead of past it turns the tests red.

What ran

  • vendor/bin/phpunit -c phpunit-unit.xml --no-coverage on TenantQuotaServiceTest, TenantScopedLookupsTest, TenantQuotaWritePathsTest, tests/Unit/BackgroundJob, QuotaConsumptionListenerTest and tests/Unit/Architecture: 241 tests, one inherited failure: ServiceCatchReturnsNullTest::testEveryAllowlistEntryNamesALiveSite names OpenRegisterBridge::approvalService#1, which is red on development too.
  • vendor/bin/phpcs and vendor/bin/phpstan analyse on the service: clean.

Figures (TenantQuotaService.php)

before after
unit lines in units over complexity 5 103 45
unit lines in units over 15 lines 128 70
getQuota (lines / complexity) 30 / 7 15 / 5
decide 28 / 6 14 / 3

Every new helper is at most 15 lines, complexity 5 or below and takes at most 2 parameters.

Maintainability floor: compare against development holds.

Left in this file: initialize (complexity 8) is changed by open #5353.

AI-assisted: prepared with Claude Code (claude-opus-5-5); reviewed by a maintainer before merge.


Generated by Claude Code

… the split

Assisted-by: ClaudeCode:claude-opus-5-5
…ed steps

getQuota builds its query through quotaQuery and reads the first row through firstQuotaRow, all inside the same catch. decide answers the hard-limit decision from the EXCEEDED_DECISIONS map through exceededDecision and the allowed decision through allowDecision.

Assisted-by: ClaudeCode:claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants