Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Dec 11, 2022

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from harendra263 December 11, 2022 07:21
self.sender = 'Codevo <admin@admin.com>'
self.email = email
self.url = url
pass
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Email.__init__ refactored with the following changes:

models.User.email == EmailStr(payload.email.lower()))
user = user_query.first()
if user:
if user := user_query.first():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_user refactored with the following changes:

Comment on lines -114 to -119
user = db.query(models.User).filter(models.User.id == user_id).first()
if not user:
if (
user := db.query(models.User)
.filter(models.User.id == user_id)
.first()
):
access_token = Authorize.create_access_token(
subject=str(user.id), expires_time=timedelta(minutes=ACCESS_TOKEN_EXPIRES_IN))
else:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED,
detail='The user belonging to this token no logger exist')
access_token = Authorize.create_access_token(
subject=str(user.id), expires_time=timedelta(minutes=ACCESS_TOKEN_EXPIRES_IN))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function refresh_token refactored with the following changes:

Comment on lines -48 to -52
post = db.query(models.Post).filter(models.Post.id == id).first()
if not post:
if post := db.query(models.Post).filter(models.Post.id == id).first():
return post
else:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,
detail=f"No post with this id: {id} found")
return post
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_post refactored with the following changes:

def get_me(db: Session = Depends(get_db), user_id: str = Depends(oauth2.require_user)):
user = db.query(models.User).filter(models.User.id == user_id).first()
return user
return db.query(models.User).filter(models.User.id == user_id).first()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_me refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Dec 11, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.59%.

Quality metrics Before After Change
Complexity 1.97 ⭐ 2.13 ⭐ 0.16 👎
Method Length 95.22 🙂 94.72 🙂 -0.50 👍
Working memory 9.09 🙂 9.25 🙂 0.16 👎
Quality 65.64% 🙂 65.05% 🙂 -0.59% 👎
Other metrics Before After Change
Lines 276 277 1
Changed files Quality Before Quality After Quality Change
app/email.py 84.47% ⭐ 84.32% ⭐ -0.15% 👎
app/routers/auth.py 57.00% 🙂 56.54% 🙂 -0.46% 👎
app/routers/post.py 73.21% 🙂 72.71% 🙂 -0.50% 👎
app/routers/user.py 83.75% ⭐ 85.17% ⭐ 1.42% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
app/routers/auth.py create_user 3 ⭐ 276 ⛔ 15 😞 43.22% 😞 Try splitting into smaller methods. Extract out complex expressions
app/routers/auth.py refresh_token 6 ⭐ 180 😞 9 🙂 56.15% 🙂 Try splitting into smaller methods
app/routers/auth.py login 3 ⭐ 206 ⛔ 9 🙂 57.03% 🙂 Try splitting into smaller methods
app/routers/post.py get_posts 0 ⭐ 92 🙂 12 😞 66.49% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

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