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

[11.x] fix: intersect Authenticatable with Model in UserProvider phpdocs #54061

Draft
wants to merge 1 commit into
base: 11.x
Choose a base branch
from

Conversation

calebdw
Copy link
Contributor

@calebdw calebdw commented Jan 2, 2025

Hello!

This adds the Model intersection to Authenticatable types (and visa versa) in the UserProvider phpdocs. This prevents redundant checks in user / package land to satisfy phpstan when calling methods that don't exist on the other type.

Thanks!

@taylorotwell
Copy link
Member

I'm not sure why the contract would require an Eloquent model. 🤔

@taylorotwell taylorotwell marked this pull request as draft January 2, 2025 22:57
@calebdw
Copy link
Contributor Author

calebdw commented Jan 3, 2025

@taylorotwell, these are just docblock changes so not breaking (at the moment, eventually the method signature should be updated).

Not all of the contract methods require a Model, but some do call Model methods and would failing if the intersection type is not guaranteed:

/**
* Update the "remember me" token for the given user in storage.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param string $token
* @return void
*/
public function updateRememberToken(UserContract $user, #[\SensitiveParameter] $token)
{
$user->setRememberToken($token);
$timestamps = $user->timestamps;
$user->timestamps = false;
$user->save();
$user->timestamps = $timestamps;
}

Due to this, I just updated all of them for consistency, but I can remove the intersection from the methods that don't have to have it as a parameter.

The method that particularly caused problems for me was createModel because it's not Authenticatable

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