Skip to content

refactor(Helper,TokenManager): migrate guest cookie access to IRequest add typing throughout#5602

Open
joshtrichards wants to merge 12 commits intomainfrom
jtr/Helper-class-cleanup
Open

refactor(Helper,TokenManager): migrate guest cookie access to IRequest add typing throughout#5602
joshtrichards wants to merge 12 commits intomainfrom
jtr/Helper-class-cleanup

Conversation

@joshtrichards
Copy link
Copy Markdown
Member

@joshtrichards joshtrichards commented Apr 29, 2026

  • Target version: main

Summary

Moves guest-name cookie access off the $_COOKIE superglobal and onto the injected IRequest service, and modernizes Helper and TokenManager with new typing/docs/etc.

Changes

lib/Helper.php

  • Add declare(strict_types=1)
  • Add type hints to constructor (?string $userId) and all method signatures
  • Refactor parseFileId(): cleaner logic, throw \InvalidArgumentException instead of \Exception (all call sites either already capture this via "catch-all" \Exception handling or already let it bubble up so should be a non-issue) , add explode limit for correctness, add typed array shape to @return
  • Null-check preg_replace result in getNewFileName() to avoid silent failure
  • Remove getGuestNameFromCookie() (moved to TokenManager which was the only caller anyway)
  • Add/improve docblocks throughout

lib/TokenManager.php

  • Inject IRequest via constructor
  • Move getGuestNameFromCookie() here as a private method using IRequest::getCookie() instead of $_COOKIE
  • Add missing return types (Wopi, string, void)
  • Reformat long method signatures (one parameter per line)
  • Clean up redundant docblock tags where type hints are now explicit

TODO

  • Test / see what I broke

Checklist

  • Code is properly formatted
  • Sign-off message is added to all commits
  • Documentation (manuals or wiki) has been updated or is not required

Eliminates two unnecessary/undesirable things: (1) a external static helper method that was only called here and only once; (2) accessing global state and `$_COOKIE` directly.

Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
…ookies

Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards joshtrichards changed the title refactor: ... refactor(Helper,TokenManager): add strict types, type hints, and migrate guest cookie access to IRequest Apr 29, 2026
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards joshtrichards changed the title refactor(Helper,TokenManager): add strict types, type hints, and migrate guest cookie access to IRequest refactor(Helper,TokenManager): migrate guest cookie access to IRequest + light refactoring Apr 30, 2026
@joshtrichards joshtrichards marked this pull request as ready for review April 30, 2026 01:46
@joshtrichards joshtrichards changed the title refactor(Helper,TokenManager): migrate guest cookie access to IRequest + light refactoring refactor(Helper,TokenManager): migrate guest cookie access to IRequest add typing throughout May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Ready to be reviewed technical debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant