Skip to content

fix: resolve 5 SonarQube issues - merge nested ifs and extract constants#32

Open
sonarqube-agent[bot] wants to merge 1 commit into
mainfrom
remediate-main-20260509-090206-a96d77ea
Open

fix: resolve 5 SonarQube issues - merge nested ifs and extract constants#32
sonarqube-agent[bot] wants to merge 1 commit into
mainfrom
remediate-main-20260509-090206-a96d77ea

Conversation

@sonarqube-agent
Copy link
Copy Markdown

Consolidates nested if statements in construct_mapping_global.py to reduce unnecessary nesting and improves code maintainability in construct_mappings.py by extracting duplicated string literals into four constants (ICON_PLUS, MAP_STYLE, INDENT, ARROW_PLUS). This eliminates code smells flagged by SonarQube and makes the codebase more readable and easier to maintain.

View Project in SonarCloud


Fixed Issues

python:S1066 - Merge this if statement with the enclosing one. • MAJORView issue

Location: PlantUML/construct_mapping_global.py:76

Why is this an issue?

Nested code - blocks of code inside blocks of code - is eventually necessary, but increases complexity. This is why keeping the code as flat as possible, by avoiding unnecessary nesting, is considered a good practice.

What changed

This hunk merges two nested if statements — if row[1] != row[2]: and if row[3] is not None and row[4] is not None: — into a single if statement using and: if row[1] != row[2] and row[3] is not None and row[4] is not None:. This reduces unnecessary nesting, making the code flatter and more readable, which directly addresses the code smell about collapsible nested if statements at line 76 in construct_mapping_global.py.

--- a/PlantUML/construct_mapping_global.py
+++ b/PlantUML/construct_mapping_global.py
@@ -75,10 +75,9 @@ def extract_data(data):
-        if row[1] != row[2]:
-            if row[3] is not None and row[4] is not None:
-                elem_types = json.loads(row[4])
-                for elem_type in elem_types:
-                    if elem_type['code'] == 'Reference':
-                        for target_profil in elem_type['targetProfile']:
-                            for profil in extracted_data.keys():
-                                if target_profil in extracted_data[profil]['urls']:
-                                    if profil not in extracted_data[resource]['links']:
-                                        extracted_data[resource]['links'][profil] = str(row[7]) + '..' + str(row[8])
+        if row[1] != row[2] and row[3] is not None and row[4] is not None:
+            elem_types = json.loads(row[4])
+            for elem_type in elem_types:
+                if elem_type['code'] == 'Reference':
+                    for target_profil in elem_type['targetProfile']:
+                        for profil in extracted_data.keys():
+                            if target_profil in extracted_data[profil]['urls']:
+                                if profil not in extracted_data[resource]['links']:
+                                    extracted_data[resource]['links'][profil] = str(row[7]) + '..' + str(row[8])
python:S1192 - Define a constant instead of duplicating this literal '<&plus> ' 6 times. • CRITICALView issue

Location: PlantUML/construct_mappings.py:308

Why is this an issue?

Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all occurrences.

What changed

Defines four constants (ICON_PLUS, MAP_STYLE, INDENT, ARROW_PLUS) that replace duplicated string literals throughout the code. ICON_PLUS replaces the 6 duplications of '<&plus> ', MAP_STYLE replaces the 9 duplications of ' #back:WhiteSmoke;header:LightGray {', INDENT replaces the 16 duplications of '\n ', and ARROW_PLUS replaces the 3 duplications of ' => <&plus> '. This hunk provides the constant definitions that all subsequent hunks reference.

--- a/PlantUML/construct_mappings.py
+++ b/PlantUML/construct_mappings.py
@@ -280,0 +281,4 @@ def generate_plantuml(structured_data, output_path, colors):
+    ICON_PLUS = '<&plus> '
+    MAP_STYLE = ' #back:WhiteSmoke;header:LightGray {'
+    INDENT = '\n    '
+    ARROW_PLUS = ' => <&plus> '
python:S1192 - Define a constant instead of duplicating this literal ' #back:WhiteSmoke;header:LightGray {' 9 times. • CRITICALView issue

Location: PlantUML/construct_mappings.py:313

Why is this an issue?

Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all occurrences.

What changed

Defines four constants (ICON_PLUS, MAP_STYLE, INDENT, ARROW_PLUS) that replace duplicated string literals throughout the code. ICON_PLUS replaces the 6 duplications of '<&plus> ', MAP_STYLE replaces the 9 duplications of ' #back:WhiteSmoke;header:LightGray {', INDENT replaces the 16 duplications of '\n ', and ARROW_PLUS replaces the 3 duplications of ' => <&plus> '. This hunk provides the constant definitions that all subsequent hunks reference.

--- a/PlantUML/construct_mappings.py
+++ b/PlantUML/construct_mappings.py
@@ -280,0 +281,4 @@ def generate_plantuml(structured_data, output_path, colors):
+    ICON_PLUS = '<&plus> '
+    MAP_STYLE = ' #back:WhiteSmoke;header:LightGray {'
+    INDENT = '\n    '
+    ARROW_PLUS = ' => <&plus> '
python:S1192 - Define a constant instead of duplicating this literal '\n ' 16 times. • CRITICALView issue

Location: PlantUML/construct_mappings.py:329

Why is this an issue?

Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all occurrences.

What changed

Defines four constants (ICON_PLUS, MAP_STYLE, INDENT, ARROW_PLUS) that replace duplicated string literals throughout the code. ICON_PLUS replaces the 6 duplications of '<&plus> ', MAP_STYLE replaces the 9 duplications of ' #back:WhiteSmoke;header:LightGray {', INDENT replaces the 16 duplications of '\n ', and ARROW_PLUS replaces the 3 duplications of ' => <&plus> '. This hunk provides the constant definitions that all subsequent hunks reference.

--- a/PlantUML/construct_mappings.py
+++ b/PlantUML/construct_mappings.py
@@ -280,0 +281,4 @@ def generate_plantuml(structured_data, output_path, colors):
+    ICON_PLUS = '<&plus> '
+    MAP_STYLE = ' #back:WhiteSmoke;header:LightGray {'
+    INDENT = '\n    '
+    ARROW_PLUS = ' => <&plus> '
python:S1192 - Define a constant instead of duplicating this literal ' => <&plus> ' 3 times. • CRITICALView issue

Location: PlantUML/construct_mappings.py:376

Why is this an issue?

Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all occurrences.

What changed

Defines four constants (ICON_PLUS, MAP_STYLE, INDENT, ARROW_PLUS) that replace duplicated string literals throughout the code. ICON_PLUS replaces the 6 duplications of '<&plus> ', MAP_STYLE replaces the 9 duplications of ' #back:WhiteSmoke;header:LightGray {', INDENT replaces the 16 duplications of '\n ', and ARROW_PLUS replaces the 3 duplications of ' => <&plus> '. This hunk provides the constant definitions that all subsequent hunks reference.

--- a/PlantUML/construct_mappings.py
+++ b/PlantUML/construct_mappings.py
@@ -280,0 +281,4 @@ def generate_plantuml(structured_data, output_path, colors):
+    ICON_PLUS = '<&plus> '
+    MAP_STYLE = ' #back:WhiteSmoke;header:LightGray {'
+    INDENT = '\n    '
+    ARROW_PLUS = ' => <&plus> '

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZZjJguBOPkSvG45yHz- for python:S1066 rule
- AZZjJgtKOPkSvG45yHz1 for python:S1192 rule
- AZZjJgtKOPkSvG45yHz3 for python:S1192 rule
- AZZjJgtKOPkSvG45yHz0 for python:S1192 rule
- AZZjJgtKOPkSvG45yHz2 for python:S1192 rule

Generated by SonarQube Agent (task: f9be9ffc-963c-4704-94c5-4b8ec30403ad)
@sonarqube-agent
Copy link
Copy Markdown
Author

⚠️ This repository does not have a CODEOWNERS file. The PR has been created but has not been automatically assigned to any reviewer. To ensure PRs are reviewed promptly, consider adding a CODEOWNERS file to your repository.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 9, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants