Skip to content

make two files worse - #100

Open
knorrest wants to merge 1 commit into
empear-analytics:masterfrom
knorrest:make-two-files-worse
Open

make two files worse#100
knorrest wants to merge 1 commit into
empear-analytics:masterfrom
knorrest:make-two-files-worse

Conversation

@knorrest

Copy link
Copy Markdown
Contributor

No description provided.

codescene-staging[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@knorrest
knorrest force-pushed the make-two-files-worse branch from 49735fb to fc6ded2 Compare May 27, 2026 10:10
codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-staging[bot]

This comment was marked as outdated.

@knorrest
knorrest force-pushed the make-two-files-worse branch from fc6ded2 to c9f9db9 Compare May 27, 2026 10:14
codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-staging[bot]

This comment was marked as outdated.

@codescene-delta-analysis

Copy link
Copy Markdown

/cs-agent skill:fix-code-health-degradations

@github-actions

github-actions Bot commented May 27, 2026

Copy link
Copy Markdown

CodeScene Refactoring Agent

✅ Completed

Summary

Fixed all newly introduced Code Health degradations in 2 files:

  • python-example.py: score improved (duplication removed, complex conditional extracted)
  • csharp-example.cs: score improved 7.56 → 9.09 (CalculateExecutionScore decomposed using ExecutionState struct)

Changes

  • Analyze change set — 2 files degraded: python-example.py and csharp-example.cs
  • Fix python-example.py — removed code duplication, extracted helpers for complex conditional
  • Fix csharp-example.cs — decomposed CalculateExecutionScore into focused helpers with ExecutionState
  • Verify improvements — analyze_change_set quality_gates: passed

Commits

4a289f4 - refactor: fix code health degradations in python-example.py and csharp-example.cs


Finished at 2026-05-27 10:37:18 UTC

codescene-staging[bot]

This comment was marked as outdated.

@knorrest
knorrest force-pushed the make-two-files-worse branch from 4a289f4 to c9f9db9 Compare June 4, 2026 09:44
codescene-staging[bot]

This comment was marked as outdated.

codescene-access[bot]

This comment was marked as outdated.

codescene-access[bot]

This comment was marked as outdated.

codescene-staging[bot]

This comment was marked as outdated.

@knorrest
knorrest force-pushed the make-two-files-worse branch from f40ae4f to 49cea05 Compare June 4, 2026 12:59

@codescene-access codescene-access Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Gates Failed
Enforce critical code health rules (1 file with Bumpy Road Ahead, Deep, Nested Complexity)
Enforce advisory code health rules (2 files with Complex Method, Complex Conditional, Lines of Code in a Single File, Code Duplication, Overall Code Complexity)

Fix Code Health degradations ℹ️

Gates Passed
4 Quality Gates Passed

Reason for failure
Enforce critical code health rules Violations Code Health Impact
csharp-example.cs 2 critical rules 10.00 → 7.57 Suppress
Enforce advisory code health rules Violations Code Health Impact
csharp-example.cs 2 advisory rules 10.00 → 7.57 Suppress
python-example.py 4 advisory rules 5.06 → 3.89 Suppress

See analysis details in CodeScene

Quality Gate Profile: Pay Down Tech Debt
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

Comment thread csharp-example.cs
Comment on lines +8 to +186
static int CalculateExecutionScore(string[] args, int seed, bool dryRun)
{
int score = seed;
int retries = 0;
bool force = false;
bool resetRequested = false;
bool hasCritical = false;
string mode = "normal";

if (args == null)
{
return -1;
}

if (args.Length == 0)
{
score -= 10;
}

for (int i = 0; i < args.Length; i++)
{
string token = args[i];

if (string.IsNullOrWhiteSpace(token))
{
score -= 2;
continue;
}

if (token.StartsWith("--"))
{
if (token == "--force")
{
force = true;
score += 7;
}
else if (token == "--reset")
{
resetRequested = true;
score = 5;
}
else if (token == "--boost")
{
score += 15;
}
else if (token == "--halve")
{
score /= 2;
}
else if (token == "--invert")
{
score = -score;
}
else
{
score -= 1;
}
}
else
{
int parsed;
if (int.TryParse(token, out parsed))
{
if (parsed > 100)
{
score += 20;
hasCritical = true;
}
else if (parsed < 0)
{
score -= 5;
}
else
{
score += parsed;
}
}
else if (token.Contains(":"))
{
string[] pair = token.Split(':');
if (pair.Length > 1)
{
mode = pair[0];
score += pair[1].Length;
}
else
{
score -= 3;
}
}
else
{
score += token.Length % 3;
}
}

if (mode == "strict")
{
score -= 2;
}
else if (mode == "relaxed")
{
score += 2;
}
else if (mode == "legacy")
{
score -= 1;
}
}

while (retries < 3 && score < 150)
{
if (score % 2 == 0)
{
score += retries + 4;
}
else
{
score -= retries + 1;
}

if (dryRun && retries == 1)
{
score -= 6;
}

if (score > 120 || retries == 2)
{
hasCritical = true;
}

if (score < 20)
{
score += 11;
}

retries++;
}

if (force && !dryRun && score > 0)
{
score += 30;
}

if (resetRequested && score > 10)
{
score = 10;
}

if (score % 5 == 0)
{
score += 1;
}

if (hasCritical && (score < 50 || score > 140))
{
score += 9;
}

if (mode == "strict")
{
if (score < 60)
{
score = 60;
}
}
else if (mode == "relaxed")
{
if (score < 20)
{
score = 20;
}
}
else if (mode == "legacy" && score < 40)
{
score = 40;
}

return score;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❌ New issue: Complex Method
CalculateExecutionScore has a cyclomatic complexity of 43, threshold = 9

Suppress

Comment thread csharp-example.cs
Comment on lines +147 to +162
if (force && !dryRun && score > 0)
{
score += 30;
}

if (resetRequested && score > 10)
{
score = 10;
}

if (score % 5 == 0)
{
score += 1;
}

if (hasCritical && (score < 50 || score > 140))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
CalculateExecutionScore has 2 complex conditionals with 4 branches, threshold = 2

Suppress

Comment thread csharp-example.cs
Comment on lines +8 to +186
static int CalculateExecutionScore(string[] args, int seed, bool dryRun)
{
int score = seed;
int retries = 0;
bool force = false;
bool resetRequested = false;
bool hasCritical = false;
string mode = "normal";

if (args == null)
{
return -1;
}

if (args.Length == 0)
{
score -= 10;
}

for (int i = 0; i < args.Length; i++)
{
string token = args[i];

if (string.IsNullOrWhiteSpace(token))
{
score -= 2;
continue;
}

if (token.StartsWith("--"))
{
if (token == "--force")
{
force = true;
score += 7;
}
else if (token == "--reset")
{
resetRequested = true;
score = 5;
}
else if (token == "--boost")
{
score += 15;
}
else if (token == "--halve")
{
score /= 2;
}
else if (token == "--invert")
{
score = -score;
}
else
{
score -= 1;
}
}
else
{
int parsed;
if (int.TryParse(token, out parsed))
{
if (parsed > 100)
{
score += 20;
hasCritical = true;
}
else if (parsed < 0)
{
score -= 5;
}
else
{
score += parsed;
}
}
else if (token.Contains(":"))
{
string[] pair = token.Split(':');
if (pair.Length > 1)
{
mode = pair[0];
score += pair[1].Length;
}
else
{
score -= 3;
}
}
else
{
score += token.Length % 3;
}
}

if (mode == "strict")
{
score -= 2;
}
else if (mode == "relaxed")
{
score += 2;
}
else if (mode == "legacy")
{
score -= 1;
}
}

while (retries < 3 && score < 150)
{
if (score % 2 == 0)
{
score += retries + 4;
}
else
{
score -= retries + 1;
}

if (dryRun && retries == 1)
{
score -= 6;
}

if (score > 120 || retries == 2)
{
hasCritical = true;
}

if (score < 20)
{
score += 11;
}

retries++;
}

if (force && !dryRun && score > 0)
{
score += 30;
}

if (resetRequested && score > 10)
{
score = 10;
}

if (score % 5 == 0)
{
score += 1;
}

if (hasCritical && (score < 50 || score > 140))
{
score += 9;
}

if (mode == "strict")
{
if (score < 60)
{
score = 60;
}
}
else if (mode == "relaxed")
{
if (score < 20)
{
score = 20;
}
}
else if (mode == "legacy" && score < 40)
{
score = 40;
}

return score;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❌ New issue: Bumpy Road Ahead
CalculateExecutionScore has 7 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is 3 blocks per function

Suppress

Comment thread csharp-example.cs
Comment on lines +8 to +186
static int CalculateExecutionScore(string[] args, int seed, bool dryRun)
{
int score = seed;
int retries = 0;
bool force = false;
bool resetRequested = false;
bool hasCritical = false;
string mode = "normal";

if (args == null)
{
return -1;
}

if (args.Length == 0)
{
score -= 10;
}

for (int i = 0; i < args.Length; i++)
{
string token = args[i];

if (string.IsNullOrWhiteSpace(token))
{
score -= 2;
continue;
}

if (token.StartsWith("--"))
{
if (token == "--force")
{
force = true;
score += 7;
}
else if (token == "--reset")
{
resetRequested = true;
score = 5;
}
else if (token == "--boost")
{
score += 15;
}
else if (token == "--halve")
{
score /= 2;
}
else if (token == "--invert")
{
score = -score;
}
else
{
score -= 1;
}
}
else
{
int parsed;
if (int.TryParse(token, out parsed))
{
if (parsed > 100)
{
score += 20;
hasCritical = true;
}
else if (parsed < 0)
{
score -= 5;
}
else
{
score += parsed;
}
}
else if (token.Contains(":"))
{
string[] pair = token.Split(':');
if (pair.Length > 1)
{
mode = pair[0];
score += pair[1].Length;
}
else
{
score -= 3;
}
}
else
{
score += token.Length % 3;
}
}

if (mode == "strict")
{
score -= 2;
}
else if (mode == "relaxed")
{
score += 2;
}
else if (mode == "legacy")
{
score -= 1;
}
}

while (retries < 3 && score < 150)
{
if (score % 2 == 0)
{
score += retries + 4;
}
else
{
score -= retries + 1;
}

if (dryRun && retries == 1)
{
score -= 6;
}

if (score > 120 || retries == 2)
{
hasCritical = true;
}

if (score < 20)
{
score += 11;
}

retries++;
}

if (force && !dryRun && score > 0)
{
score += 30;
}

if (resetRequested && score > 10)
{
score = 10;
}

if (score % 5 == 0)
{
score += 1;
}

if (hasCritical && (score < 50 || score > 140))
{
score += 9;
}

if (mode == "strict")
{
if (score < 60)
{
score = 60;
}
}
else if (mode == "relaxed")
{
if (score < 20)
{
score = 20;
}
}
else if (mode == "legacy" && score < 40)
{
score = 40;
}

return score;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❌ New issue: Deep, Nested Complexity
CalculateExecutionScore has a nested complexity depth of 4, threshold = 4

Suppress

Comment thread python-example.py
return res


def create_transaction_from_cart_for_checkout(cart: Cart) -> DbTransaction:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❌ New issue: Lines of Code in a Single File
This module has 621 lines of code, improve code health by reducing it to 600

Suppress

Comment thread python-example.py
Comment on lines +41 to +70
def create_transaction_from_cart_for_checkout(cart: Cart) -> DbTransaction:
"""Create a transaction based on cart information"""
res = DbTransaction(type=TransactionType.PURCHASE, currency=cart.currency, timestamp=now(),
total_amount=cart.total_amount, state=TransactionState.INITIALIZED, id=ObjectId())
items = []
vat: Dict[Decimal, Vat] = {}
for item in cart.items:
ps = item.product_set.fetch()
t_item = TransactionItem(amount=item.amount, count=item.count,
product_set_id=ps.full_id, product_set_title=item.product_set_title)
if item.manual_activation is not None:
t_item.manual_activation = item.manual_activation
if item.mtb_product_owner is not None:
t_item.mtb_product_owner = item.mtb_product_owner
if item.mtb_bearer is not None:
t_item.mtb_bearer = item.mtb_bearer
if item.start_of_validity is not None:
t_item.start_of_validity = item.start_of_validity
items.append(t_item)
for percentage, amount in ps.vat().items():
amount *= item.count
if percentage in vat:
vat[percentage].amount += amount
else:
vat[percentage] = Vat(amount=amount, percentage=percentage)
res.items = items
res.vat = list(vat.values())
res.discount_codes = list(cart.discount_codes)
res.description = cart.name
return res

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❌ New issue: Code Duplication
The module contains 3 functions with similar structure: create_transaction_from_cart,create_transaction_from_cart_for_checkout,create_transaction_from_cart_for_saved_cart

Suppress

Comment thread python-example.py
Comment on lines +195 to +198
if ((purchase.manual_activation and purchase.start_of_validity is None and mtb_bearer is None)
or (purchase.start_of_validity and not purchase.manual_activation and mtb_product_owner is None)
or (purchase.mtb_product_owner and mtb_bearer is not None and mtb_product_owner is not None
and mtb_bearer.owner.id == mtb_product_owner.id)):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
initialize_purchase_transaction has 1 complex conditionals with 9 branches, threshold = 2

Suppress

Comment thread python-example.py
return res


def create_transaction_from_cart_for_checkout(cart: Cart) -> DbTransaction:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❌ New issue: Overall Code Complexity
This module has a mean cyclomatic complexity of 8.21 across 28 functions. The mean complexity threshold is 8

Suppress

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