-
-
Notifications
You must be signed in to change notification settings - Fork 436
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
Load default auth model from config #602
Conversation
Thank you for your contribution! ❤️ Could you replace return+else-es×3? |
Hey @szepeviktor! I'd like to fix the style but there is a stylelint-PHPstan conflict: stylelint wants this form: /**
* Returns the default auth model from config.
*
* @return string|null
*/
private function getAuthModel(ConfigRepository $config)
{
if (
($guard = $config->get('auth.defaults.guard')) &&
($provider = $config->get('auth.guards.'.$guard.'.provider')) &&
($authModel = $config->get('auth.providers.'.$provider.'.model'))
) {
return $authModel;
} else {
return;
}
} But PHPStan will gives me the following errors:
If I change /**
* Returns the default auth model from config.
*
* @return string|void
*/
private function getAuthModel(ConfigRepository $config)
{
if (
($guard = $config->get('auth.defaults.guard')) &&
($provider = $config->get('auth.guards.'.$guard.'.provider')) &&
($authModel = $config->get('auth.providers.'.$provider.'.model'))
) {
return $authModel;
}
} Then I think a PHPStan bug (or an unhandled case) occurs:
There is a condition to handle if ($authModel = $this->getAuthModel($config)) {
return TypeCombinator::addNull(new ObjectType($authModel));
} So I've commited a much uglier solution and stylelint still wants to remove |
It is preferable to put errors in conditionals, leave normal/expected execution unindented. if (! ($guard = $config->get('auth.defaults.guard'))
|| ! ($provider = $config->get('auth.guards.'.$guard.'.provider'))
|| ! ($authModel = $config->get('auth.providers.'.$provider.'.model'))
) {
return;
}
return $authModel; |
Thank you!
|
Yes, we must pass a string only. |
Thank you @szepeviktor! |
Thank you. Please see https://github.com/nunomaduro/larastan/pull/603/files |
I see, all right. |
As you wish, it is example code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! It looks good.
Changes
This PR adds support for dynamic auth model load from config.
Replaces
with
(In the future maybe it can be extended with dynamic guard handling.)