Created
May 24, 2025 14:23
-
-
Save mcsee/a4f08aa097dbf1822beb80534b078af4 to your computer and use it in GitHub Desktop.
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InvoiceProcessor: | |
def process_invoice(self, invoice_data, database): | |
# Business logic mixed with database access | |
customer = database.execute( | |
"SELECT * FROM customers WHERE id = ?", | |
invoice_data['customer_id'] | |
).fetchone() | |
if customer['credit_limit'] < invoice_data['amount']: | |
raise Exception("Credit limit exceeded") | |
# More business logic | |
tax = invoice_data['amount'] * 0.21 | |
total = invoice_data['amount'] + tax | |
# Direct database manipulation | |
database.execute( | |
"INSERT INTO invoices (customer_id, amount, tax, total) " | |
"VALUES (?, ?, ?, ?)", | |
(invoice_data['customer_id'], invoice_data['amount'], | |
tax, total) | |
) | |
database.commit() | |
return total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment