Function generate_random_path
has a Cognitive Complexity of 92 (exceeds 5 allowed). Consider refactoring. Open
def generate_random_path(num_road_tiles, branchiness_factor, loopiness_factor, curviness_factor):
def pick_adjacent_node(nodes, connections, branchiness_factor, curviness_factor):
for attempts in range(5):
origin = pick_origin_node(nodes, connections, branchiness_factor)
possibles = []
- Read upRead up
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"
Further reading
Function generate_decor
has a Cognitive Complexity of 68 (exceeds 5 allowed). Consider refactoring. Open
def generate_decor(path, num_tiles):
DECOR_DATA = decor_data()
DECOR_SUM = decor_sum()
def find_node_by_coordinate(x, y, dec, nodes):
- Read upRead up
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"
Further reading
File random_road.py
has 329 lines of code (exceeds 250 allowed). Consider refactoring. Open
from __future__ import absolute_import
import json
import math
import random
Function generate_traffic_lights
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def generate_traffic_lights(path):
degree2Nodes = []
degree3or4Nodes = []
for node in path:
- Read upRead up
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"
Further reading
Consider simplifying this complex logical expression. Open
if (
coord["x"] // GRID_SIZE == x
and coord["y"] // GRID_SIZE == y
or (
elem == "pond"
Function create
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def create(episode=None):
num_tiles = episode.r_num_tiles if episode else DEFAULT_NUM_TILES
branchiness = episode.r_branchiness if episode else DEFAULT_BRANCHINESS
loopiness = episode.r_loopiness if episode else DEFAULT_LOOPINESS
- Read upRead up
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"
Further reading
Function generate_random_map_data
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def generate_random_map_data(
Avoid deeply nested control flow statements. Open
if adjacent_node_index > node_index and adjacent_node != nodes[0]:
if adjacent_node_index not in connections[node_index]:
possible_loops.append((node_index, adjacent_node_index))
Function append_decor
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def append_decor(decor, x, y, dec, dx=0, dy=0):
Function pick_destination_node
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def pick_destination_node(nodes, connections, origin, possibles, curviness_factor):
Similar blocks of code found in 2 locations. Consider refactoring. Open
x = x * GRID_SIZE + int((GRID_SIZE - decor_object.width) * 0.5 * (1 - dx))
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 47.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
y = y * GRID_SIZE + int((GRID_SIZE - decor_object.height) * 0.5 * (1 - dy))
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 47.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76