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

NewRelicHookSensor.run()   F

Complexity

Conditions 11

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 11
dl 0
loc 49
rs 3.1765

1 Method

Rating   Name   Duplication   Size   Complexity  
B NewRelicHookSensor.handle_nrhook() 0 33 5

How to fix   Complexity   

Complexity

Complex classes like NewRelicHookSensor.run() 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