1919# HARMONIZER SCORE: ~0.85 (!! DISHARMONY)
2020# OTHER TOOLS: All pass ✓
2121
22+
2223def validate_email (email : str ) -> bool :
2324 """
2425 BUG: Function claims to validate, but actually sends emails!
@@ -39,15 +40,18 @@ def validate_email(email: str) -> bool:
3940 return True
4041 return False
4142
43+
4244def send_welcome_email (email ):
4345 """Placeholder - in real code, this would send email"""
4446 print (f"Sending email to { email } " )
4547
48+
4649# FIX: Separate validation from action
4750def validate_email_fixed (email : str ) -> bool :
4851 """Just validates, doesn't send"""
4952 return "@" in email and "." in email
5053
54+
5155def process_new_user (email : str ) -> bool :
5256 """Orchestrates validation AND sending"""
5357 if validate_email_fixed (email ):
@@ -62,6 +66,7 @@ def process_new_user(email: str) -> bool:
6266# HARMONIZER SCORE: ~0.95 (!! CRITICAL DISHARMONY)
6367# OTHER TOOLS: All pass ✓
6468
69+
6570def get_user_by_id (user_id : int ):
6671 """
6772 BUG: Function claims to GET, but actually DELETES!
@@ -83,20 +88,25 @@ def get_user_by_id(user_id: int):
8388 db .execute (f"DELETE FROM users WHERE id = { user_id } " )
8489 return user_id
8590
91+
8692def get_database_connection ():
8793 """Placeholder"""
94+
8895 class FakeDB :
8996 def execute (self , query ):
9097 print (f"Executing: { query } " )
98+
9199 return FakeDB ()
92100
101+
93102# FIX: Name matches behavior
94103def delete_user_by_id (user_id : int ):
95104 """Honestly named - clearly destructive"""
96105 db = get_database_connection ()
97106 db .execute (f"DELETE FROM users WHERE id = { user_id } " )
98107 return user_id
99108
109+
100110def get_user_by_id_fixed (user_id : int ):
101111 """Actually gets without modifying"""
102112 db = get_database_connection ()
@@ -111,6 +121,7 @@ def get_user_by_id_fixed(user_id: int):
111121# HARMONIZER SCORE: ~0.75 (!! DISHARMONY)
112122# OTHER TOOLS: Might pass
113123
124+
114125def check_file_exists (filepath : str ) -> bool :
115126 """
116127 BUG: Function claims to check, but creates if missing!
@@ -129,22 +140,26 @@ def check_file_exists(filepath: str) -> bool:
129140
130141 if not os .path .exists (filepath ):
131142 # VIOLATION: Check functions shouldn't create!
132- with open (filepath , 'w' ) as f :
143+ with open (filepath , "w" ) as f :
133144 f .write ("" )
134145 return False
135146 return True
136147
148+
137149# FIX: Separate check from creation
138150def check_file_exists_fixed (filepath : str ) -> bool :
139151 """Pure check - no side effects"""
140152 import os
153+
141154 return os .path .exists (filepath )
142155
156+
143157def ensure_file_exists (filepath : str ) -> bool :
144158 """Honest name - creates if missing"""
145159 import os
160+
146161 if not os .path .exists (filepath ):
147- with open (filepath , 'w' ) as f :
162+ with open (filepath , "w" ) as f :
148163 f .write ("" )
149164 return False
150165 return True
@@ -156,6 +171,7 @@ def ensure_file_exists(filepath: str) -> bool:
156171# HARMONIZER SCORE: ~0.70 (!! DISHARMONY)
157172# OTHER TOOLS: Tests might pass if they expect side effects
158173
174+
159175def calculate_total_price (items : list ) -> float :
160176 """
161177 BUG: Function claims to calculate, but also saves to database!
@@ -171,26 +187,29 @@ def calculate_total_price(items: list) -> float:
171187 - Hard to test
172188 - Violates single responsibility
173189 """
174- total = sum (item [' price' ] for item in items )
190+ total = sum (item [" price" ] for item in items )
175191
176192 # VIOLATION: Calculate functions shouldn't persist!
177- save_to_database (' total_price' , total )
193+ save_to_database (" total_price" , total )
178194
179195 return total
180196
197+
181198def save_to_database (key , value ):
182199 """Placeholder"""
183200 print (f"Saving { key } = { value } to database" )
184201
202+
185203# FIX: Separate calculation from persistence
186204def calculate_total_price_fixed (items : list ) -> float :
187205 """Pure calculation - no side effects"""
188- return sum (item ['price' ] for item in items )
206+ return sum (item ["price" ] for item in items )
207+
189208
190209def calculate_and_save_total_price (items : list ) -> float :
191210 """Honest name - calculates AND saves"""
192211 total = calculate_total_price_fixed (items )
193- save_to_database (' total_price' , total )
212+ save_to_database (" total_price" , total )
194213 return total
195214
196215
@@ -200,6 +219,7 @@ def calculate_and_save_total_price(items: list) -> float:
200219# HARMONIZER SCORE: ~0.80 (!! DISHARMONY)
201220# OTHER TOOLS: Hard to catch without semantic analysis
202221
222+
203223def read_configuration (config_file : str ) -> dict :
204224 """
205225 BUG: Function claims to read, but updates last_accessed timestamp!
@@ -217,26 +237,31 @@ def read_configuration(config_file: str) -> dict:
217237 """
218238 import json
219239
220- with open (config_file , 'r' ) as f :
240+ with open (config_file , "r" ) as f :
221241 config = json .load (f )
222242
223243 # VIOLATION: Read functions shouldn't modify!
224244 update_last_accessed_timestamp (config_file )
225245
226246 return config
227247
248+
228249def update_last_accessed_timestamp (filepath ):
229250 """Placeholder"""
230251 import time
252+
231253 print (f"Updating timestamp for { filepath } to { time .time ()} " )
232254
255+
233256# FIX: Either truly read-only OR honest name
234257def read_configuration_fixed (config_file : str ) -> dict :
235258 """Pure read - no side effects"""
236259 import json
237- with open (config_file , 'r' ) as f :
260+
261+ with open (config_file , "r" ) as f :
238262 return json .load (f )
239263
264+
240265def read_and_track_configuration (config_file : str ) -> dict :
241266 """Honest name - reads AND tracks access"""
242267 config = read_configuration_fixed (config_file )
@@ -250,6 +275,7 @@ def read_and_track_configuration(config_file: str) -> dict:
250275# HARMONIZER SCORE: ~0.90 (!! CRITICAL DISHARMONY)
251276# OTHER TOOLS: Might not catch unless tests verify original list unchanged
252277
278+
253279def filter_invalid_users (users : list ) -> list :
254280 """
255281 BUG: Function claims to filter (read), but deletes from database!
@@ -270,32 +296,35 @@ def filter_invalid_users(users: list) -> list:
270296 valid_users = []
271297
272298 for user in users :
273- if user [' email' ] and user [' name' ]:
299+ if user [" email" ] and user [" name" ]:
274300 valid_users .append (user )
275301 else :
276302 # VIOLATION: Filter shouldn't delete from DB!
277- delete_user_from_database (user ['id' ])
303+ delete_user_from_database (user ["id" ])
278304
279305 return valid_users
280306
307+
281308def delete_user_from_database (user_id ):
282309 """Placeholder"""
283310 print (f"DELETING user { user_id } from database!" )
284311
312+
285313# FIX: Separate filtering from deletion
286314def filter_invalid_users_fixed (users : list ) -> list :
287315 """Pure filter - no side effects"""
288- return [u for u in users if u ['email' ] and u ['name' ]]
316+ return [u for u in users if u ["email" ] and u ["name" ]]
317+
289318
290319def remove_invalid_users (users : list ) -> list :
291320 """Honest name - filters AND deletes from database"""
292321 valid_users = []
293322
294323 for user in users :
295- if user [' email' ] and user [' name' ]:
324+ if user [" email" ] and user [" name" ]:
296325 valid_users .append (user )
297326 else :
298- delete_user_from_database (user ['id' ])
327+ delete_user_from_database (user ["id" ])
299328
300329 return valid_users
301330
@@ -306,6 +335,7 @@ def remove_invalid_users(users: list) -> list:
306335# HARMONIZER SCORE: ~0.65 (!! DISHARMONY)
307336# OTHER TOOLS: Tests might catch if they expect no exceptions
308337
338+
309339def log_error_message (message : str ):
310340 """
311341 BUG: Function claims to log, but raises exception!
@@ -326,11 +356,13 @@ def log_error_message(message: str):
326356 if "critical" in message .lower ():
327357 raise RuntimeError (f"Critical error: { message } " )
328358
359+
329360# FIX: Either log OR raise, not both under "log" name
330361def log_error_message_fixed (message : str ):
331362 """Just logs - never raises"""
332363 print (f"ERROR: { message } " )
333364
365+
334366def handle_error_message (message : str ):
335367 """Honest name - logs AND may raise"""
336368 print (f"ERROR: { message } " )
0 commit comments