Completed
Pull Request — master (#336)
by James
03:24
created

NewRelicHookSensor   C

Complexity

Total Complexity 54

Size/Duplication

Total Lines 257
Duplicated Lines 0 %
Metric Value
dl 0
loc 257
rs 6.8539
wmc 54

19 Methods

Rating   Name   Duplication   Size   Complexity  
A _get_servers() 0 11 3
B _app_hook_handler() 0 26 4
A _get_sensor_config() 0 3 1
A add_trigger() 0 2 1
A _dispatch_trigger() 0 3 1
A setup() 0 2 1
A remove_trigger() 0 2 1
A __init__() 0 16 1
D _dispatch_server_normal() 0 27 8
A _server_hook_handler() 0 21 4
A cleanup() 0 2 1
A update_trigger() 0 2 1
F run() 0 49 11
A _dispatch_application_normal() 0 19 4
B handle_nrhook() 0 33 5
A _get_sensor_config_param() 0 6 2
B _get_hook_handler() 0 14 5
A _get_application() 0 7 3
A _get_headers_as_dict() 0 6 2

How to fix   Complexity   

Complex Class

Complex classes like NewRelicHookSensor often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import json
2
3
import urbandict
4
5
from st2actions.runners.pythonrunner import Action
6
7
__all__ = [
8
    'GetDefinitionsAction'
9
]
10
11
12
class GetDefinitionsAction(Action):
13
    def run(self, term):
14
        result = urbandict.define(term)
15
        result = json.dumps(result)
16
        return result
17