Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Infer type of auth()->authenticate() and Auth::authenticate() calls #1957

Open
wants to merge 4 commits into
base: 2.x
Choose a base branch
from

Conversation

robchett
Copy link

@robchett robchett commented May 24, 2024

  • Added or updated tests
  • Documented user facing changes

Changes

Add return type detection to

  • Auth::authenticate()
  • auth()->authenticate()

Breaking changes

@robchett robchett changed the title Infer type of auth()->authenticate() and Auth::authenticate() calls feat: Infer type of auth()->authenticate() and Auth::authenticate() calls May 24, 2024
@robchett robchett force-pushed the auth_authenticate_return_type branch from 788a3d7 to 3746512 Compare June 21, 2024 13:18
@robchett robchett force-pushed the auth_authenticate_return_type branch from 3746512 to 5c58c3c Compare June 21, 2024 14:04
@robchett robchett requested a review from calebdw June 21, 2024 14:25
tests/Type/data/auth.php Outdated Show resolved Hide resolved
tests/Type/GeneralTypeTest.php Outdated Show resolved Hide resolved
src/ReturnTypes/AuthExtension.php Outdated Show resolved Hide resolved
@robchett robchett force-pushed the auth_authenticate_return_type branch from 42c61c9 to a1a6569 Compare June 24, 2024 08:14
@robchett
Copy link
Author

@calebdw how would you deal with the change from
@method static \Illuminate\Contracts\Auth\Authenticatable|bool loginUsingId(mixed $id, bool $remember = false)
to
@method static \Illuminate\Contracts\Auth\Authenticatable|false loginUsingId(mixed $id, bool $remember = false)
in different versions of laravel?

@calebdw
Copy link
Contributor

calebdw commented Jun 24, 2024

@calebdw how would you deal with the change from @method static \Illuminate\Contracts\Auth\Authenticatable|bool loginUsingId(mixed $id, bool $remember = false) to @method static \Illuminate\Contracts\Auth\Authenticatable|false loginUsingId(mixed $id, bool $remember = false) in different versions of laravel?

It depends, if you need to correct the types then you would need to create new versioned stubs (look in the stubs/10.0.0 dir for examples).

If the types are correct and you're just having issues with asserting the type returned from a method, then you'll have to only include your assertion files for certain versions. For example, in the GeneralTypeTest:

image

@robchett robchett force-pushed the auth_authenticate_return_type branch from 994c62b to cb654ba Compare June 24, 2024 17:09
@robchett
Copy link
Author

Thanks @calebdw, I'll keep that in mind for next time. I think I'll leave it as is as there isn't any larastan logic applied to loginById

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