# LiberTEM/LiberTEM

### Summary

A
2 hrs

#### Function `get_udf_results` has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open

``````    def get_udf_results(self, udf_results, roi, damage):
'''
The AnalysisResults are calculated lazily in this function to reduce
'''``````

# Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

### A method's cognitive complexity is based on a few simple rules:

• Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
• Code is considered more complex for each "break in the linear flow of the code"
• Code is considered more complex when "flow breaking structures are nested"

#### Function `radial_mask_factory` has 9 arguments (exceeds 8 allowed). Consider refactoring. Open

``def radial_mask_factory(detector_y, detector_x, cx, cy, ri, ro, n_bins, max_order, use_sparse):``

#### Function "radial_mask_factory" has 9 parameters, which is greater than the 7 authorized. Open

``def radial_mask_factory(detector_y, detector_x, cx, cy, ri, ro, n_bins, max_order, use_sparse):``

A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

## Noncompliant Code Example

With a maximum number of 4 parameters:

```def do_something(param1, param2, param3, param4, param5):
...
```

## Compliant Solution

```def do_something(param1, param2, param3, param4):
...
```

#### Either merge this branch with the identical one on line "315" or change one of the implementations. Open

``            default = False``

Having two branches in the same `if` structure with the same implementation is at best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then they should be combined.

## Noncompliant Code Example

```if 0 <= a < 10:
do_the_thing()
elif 10 <= a < 20:
do_the_other_thing()
elif 20 <= a < 50:
do_the_thing()  # Noncompliant; duplicates first condition
else:
do_the_rest()

b = 4 if a > 12 else 4
```

## Compliant Solution

```if (0 <= a < 10) or (20 <= a < 50):
do_the_thing()
elif 10 <= a < 20:
do_the_other_thing()
else:
do_the_rest()

b = 4
```

or

```if 0 <= a < 10:
do_the_thing()
elif 10 <= a < 20:
do_the_other_thing()
elif 20 <= a < 50:
do_the_third_thing()
else:
do_the_rest()

b = 8 if a > 12 else 4
```

#### Take the required action to fix the issue indicated by this "FIXME" comment. Open

``        # FIXME more testing for optimum backend``

`FIXME` tags are commonly used to mark places where a bug is suspected, but which the developer wants to deal with later.

Sometimes the developer will not have the time or will simply forget to get back to that tag.

This rule is meant to track those tags and to ensure that they do not go unnoticed.

## Noncompliant Code Example

```def divide(numerator, denominator):
return numerator / denominator              # FIXME denominator value might be 0
```