I am running rubocop on rails and it gave me the message below.
W: Shadowing outer local variable - user.
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
^^^^
This is the code.
def self.from_omniauth(auth)
user = User.where(email: auth.info.email).first
if user
return user
else
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.fullname = auth.info.name
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.image = auth.info.image
user.password = Devise.friendly_token[0, 20]
end
end
end
This means that the user
provided as a block arguments will overwrite the user
variable defined here user = User.where(email: auth.info.email).first
To overcome it you'll need to change the name of one of the variables. Either something like:
result = User.where...
return result if result
Or:
where(provider: auth.provider, uid: auth.uid).first_or_create do |u|
u.fullname = auth.info.name
...
end
Some more info: https://github.com/bbatsov/ruby-style-guide#no-shadowing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With