Skip to content

fix(cp): cast user id to string in ResolvesUserId trait#32

Open
mylesthedev wants to merge 1 commit into
cboxdk:mainfrom
mylesthedev:fix/resolve-user-id-int-cast
Open

fix(cp): cast user id to string in ResolvesUserId trait#32
mylesthedev wants to merge 1 commit into
cboxdk:mainfrom
mylesthedev:fix/resolve-user-id-int-cast

Conversation

@mylesthedev
Copy link
Copy Markdown

The trait declares a : string return type, but Statamic's User::current()->id() returns int under the Eloquent users driver (only string under the file driver). With declare(strict_types=1) this raises a TypeError on every request that lands in DashboardController::index() or TokenController, breaking the entire /cp/mcp panel for sites using Statamic's Eloquent driver.

Cast at the trait boundary so the contract holds regardless of driver. The PHPDoc @var string annotation was incorrect under Eloquent — removed in favour of an explicit cast.

Adds a Pest unit test that mocks User::current() to return both int and string ids, covering the file driver, the Eloquent driver, and the unauthenticated case.

Description

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🔧 Tool enhancement
  • 📝 Documentation
  • ♻️ Refactoring

Related Issue

Fixes #

Testing

  • Tests pass (composer test)
  • Code quality checks pass (composer quality)
  • Tested manually with Statamic

Environment

  • Statamic:
  • Laravel:
  • PHP:

Checklist

  • My code follows the project style
  • I've added/updated tests if needed
  • Tool responses follow the standard format

Notes


Thanks for contributing to this alpha project! 🙏

The trait declares a `: string` return type, but Statamic's
`User::current()->id()` returns int under the Eloquent users driver
(only string under the file driver). With `declare(strict_types=1)`
this raises a TypeError on every request that lands in
DashboardController::index() or TokenController, breaking the entire
`/cp/mcp` panel for sites using Statamic's Eloquent driver.

Cast at the trait boundary so the contract holds regardless of driver.
The PHPDoc `@var string` annotation was incorrect under Eloquent —
removed in favour of an explicit cast.

Adds a Pest unit test that mocks `User::current()` to return both int
and string ids, covering the file driver, the Eloquent driver, and the
unauthenticated case.
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.

1 participant