Skip to content

Sourcery refactored master branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master
Open

Sourcery refactored master branch#1
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot commented Sep 10, 2021

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 szepix September 10, 2021 07:38
@sourcery-ai sourcery-ai bot force-pushed the sourcery/master branch 12 times, most recently from d268b71 to b85e299 Compare September 10, 2021 07:44
Comment on lines 178 to 181
raise InvalidDateRange
except ValueError:
raise InvalidDate
except AttributeError:
except (ValueError, AttributeError):
raise InvalidDate
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Reservation.__init__ refactored with the following changes:

Comment on lines -208 to +206
except ValueError:
raise InvalidDate
except AttributeError:
except (ValueError, AttributeError):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Rent.__init__ refactored with the following changes:

}

if type == "Van":
elif type == "Van":
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function cars_as_dict refactored with the following changes:

  • Simplify conditional into switch-like form (switch)

Comment on lines -35 to +36
overdue = []
if cars:
overdue = []
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function overdue_cars refactored with the following changes:

Comment on lines 53 to +96
cars_as_list = cars_as_dict(cars)
if len(criteria) != 0:
for car in cars_as_list:
criteria_met = 0
criteria_size = len(criteria)
for crit_name in criteria:
crit = criteria[crit_name]
car_crit = car[crit_name]
if isinstance(crit, dict):
if crit_name == 'Rent':
if car_crit is not None and crit['Return date'] is not None:
car_date = datetime.strptime(car_crit['Return date'], '%d.%m.%Y').date()
crit_date = datetime.strptime(crit['Return date'], '%d.%m.%Y').date()
if car_crit is None or crit['Return date'] is None or car_date < crit_date:
criteria_met += 1
continue
if crit_name == 'Reservation':
if car_crit is not None and crit['Due Reservation Date'] is not None:
car_date = datetime.strptime(car_crit['Due Reservation Date'], '%d.%m.%Y').date()
crit_date = datetime.strptime(crit['Due Reservation Date'], '%d.%m.%Y').date()
if car_crit is None or crit['Due Reservation Date'] is None or car_date < crit_date:
criteria_met += 1
continue
if len(criteria) == 0:
return []

criteria_size += len(crit)
for add in crit:
if crit[add] != '':
try:
if crit[add] == car_crit[add] or crit[add] == '':
criteria_met += 1
except Exception:
pass
else:
criteria_met += 1
criteria_met += 1
else:
if crit == car_crit or crit == '':
criteria_meeting = []
for car_index, car in enumerate(cars_as_list):
criteria_met = 0
criteria_size = len(criteria)
for crit_name in criteria:
crit = criteria[crit_name]
car_crit = car[crit_name]
if isinstance(crit, dict):
if crit_name == 'Rent':
if car_crit is not None and crit['Return date'] is not None:
car_date = datetime.strptime(car_crit['Return date'], '%d.%m.%Y').date()
crit_date = datetime.strptime(crit['Return date'], '%d.%m.%Y').date()
if car_crit is None or crit['Return date'] is None or car_date < crit_date:
criteria_met += 1
if(criteria_met == criteria_size):
car_class = cars[car_index]
criteria_meeting.append(car_class)
car_index += 1
return criteria_meeting
else:
return []
continue
if crit_name == 'Reservation':
if car_crit is not None and crit['Due Reservation Date'] is not None:
car_date = datetime.strptime(car_crit['Due Reservation Date'], '%d.%m.%Y').date()
crit_date = datetime.strptime(crit['Due Reservation Date'], '%d.%m.%Y').date()
if car_crit is None or crit['Due Reservation Date'] is None or car_date < crit_date:
criteria_met += 1
continue

criteria_size += len(crit)
for add in crit:
if crit[add] != '':
try:
if crit[add] == car_crit[add]:
criteria_met += 1
except Exception:
pass
else:
criteria_met += 1
criteria_met += 1
elif crit in [car_crit, '']:
criteria_met += 1
if(criteria_met == criteria_size):
car_class = cars[car_index]
criteria_meeting.append(car_class)
return criteria_meeting
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function search_database refactored with the following changes:

self.cars = read_from_database()
else:
self.cars = []
self.cars = read_from_database() or []
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function CarRentalWindow.__init__ refactored with the following changes:

Comment on lines -65 to +63
if car.reservation:
if car.reservation.check_expiration() == "EXPIRED":
car.reservation = None
if car.reservation and car.reservation.check_expiration() == "EXPIRED":
car.reservation = None
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function CarRentalWindow.check_reservations refactored with the following changes:

@sourcery-ai
Copy link
Copy Markdown
Author

sourcery-ai bot commented Sep 10, 2021

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.65%.

Quality metrics Before After Change
Complexity 15.03 🙂 12.76 🙂 -2.27 👍
Method Length 80.51 🙂 80.05 🙂 -0.46 👍
Working memory 10.93 😞 10.75 😞 -0.18 👍
Quality 53.99% 🙂 54.64% 🙂 0.65% 👍
Other metrics Before After Change
Lines 710 699 -11
Changed files Quality Before Quality After Quality Change
car_rental.py 74.23% 🙂 75.31% ⭐ 1.08% 👍
car_rental_io.py 40.53% 😞 40.95% 😞 0.42% 👍
database_actions.py 42.02% 😞 45.06% 😞 3.04% 👍
gui.py 55.95% 🙂 55.99% 🙂 0.04% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
database_actions.py search_database 64 ⛔ 221 ⛔ 17 ⛔ 15.03% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
gui.py CarRentalWindow.set_text 31 😞 231 ⛔ 10 😞 31.97% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
car_rental_io.py read_from_json 11 🙂 223 ⛔ 19 ⛔ 34.58% 😞 Try splitting into smaller methods. Extract out complex expressions
gui.py CarRentalWindow._reserve_rent 17 🙂 242 ⛔ 13 😞 34.83% 😞 Try splitting into smaller methods. Extract out complex expressions
gui.py CarRentalWindow.edit_add_to_database 8 ⭐ 187 😞 18 ⛔ 40.73% 😞 Try splitting into smaller methods. 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.

0 participants