Skip to content

[access] refactor(public-share): split PublicShareService share creation, opening and lookup into named steps - #1078

Open
rubenvdlinde wants to merge 2 commits into
developmentfrom
quality/i40-publicshare-steps
Open

rubenvdlinde wants to merge 2 commits into
developmentfrom
quality/i40-publicshare-steps

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

What changed

PublicShareService reads as named steps instead of three long, branchy methods. The public signatures, including the sensitive-parameter markers, are unchanged, and every new step that receives a password carries the same marker.

  • createPublicShare: authorisation first (unchanged), then newShare → applyPassword → applyExpiry (parseExpiry: the same three formats in the same order and the same message) → storeShare (insertShare, which keeps logging the exception class only).
  • renderShareContent: resolveActiveShare, then the password gate as lacksPassword / rejectsPassword (a wrong password is still recorded before the refusal), then shareContent (dashboard, view count, placements); the token and IP of the visit travel as a PublicShareVisit.
  • resolveActiveShare → findShareByToken, isExpired (parseStoredExpiry), with the three identical record-and-refuse blocks folded into refuseAccess. unlockShare and the render gate share registerPasswordFailure.

Allowed and refused outcomes are unchanged: the same exceptions, the same attempts recorded with the same action and IP in the same order, the same stored fields and log lines.

Characterisation tests

tests/Unit/Service/PublicShareServiceAccessGoldenTest.php was committed first, against the old code, and passes before and after: a non-owner non-admin refused before any token is made, the created share's fields, the password hashing (none, empty, set, "0"), every expiry format and the refused ones, the storage-failure log and message, admin creation; every closed share (unknown, revoked, expired in both stored formats) with exactly one recorded access attempt and no view counted; every password-gate case with its recorded events; and every unlock case including the throttle wait before the lookup. Expiry times are relative to now. Mutation check: disabling the revocation check on the old code turned two goldens red; restored before committing.

What ran

  • vendor/bin/phpunit -c phpunit.xml --no-coverage tests/Unit: 2774 tests OK (13 skipped, as on development), including the existing sensitive-parameter test.
  • vendor/bin/phpcs and vendor/bin/phpstan analyse on the touched lib files: clean.

Figures (touched files lib/Service/PublicShareService.php, lib/Service/PublicShareVisit.php)

before after
units over complexity 5 3 units, 121 lines 0
units over complexity 10 createPublicShare (11) none
units over 15 lines of code 5 units, 169 lines 3 units, 61 lines
units over 2 parameters 5 units, 148 lines 5 units, 86 lines

App-wide: unit complexity 4.02 → 4.08, unit size 3.40 → 3.42, unit interfacing 3.14 → 3.16, duplication 4.54 → 4.55.

Maintainability floor: compare against development holds.

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


Generated by Claude Code

…ions before the split

Assisted-by: ClaudeCode:claude-opus-5-5
…ing and lookup into named steps

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