Completed
Push — master ( b34b71...1c0f48 )
by Andrii
12:24
created

Login.build()   C

Complexity

Conditions 10

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
c 1
b 0
f 0
dl 0
loc 20
rs 6

How to fix   Complexity   

Complexity

Complex classes like Login.build() 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
#!/usr/bin/env python
2
3
from heppy.Error import Error
4
from heppy.Request import Request
5
from heppy.Response import Response
6
7
class Login:
8
    @staticmethod
9
    def build(config, greeting, args = {}):
10
        if not args.get('login'):
11
            args['login'] = config['epp']['login']
12
        if not args.get('pw'):
13
            args['pw'] = config['epp']['password']
14
        if not greeting:
15
            Error.die(4, 'no greeting given')
16
        greeting = Response.parsexml(greeting)
17
        if not args.get('objURIs'):
18
            args['objURIs'] = greeting.get('objURIs')
19
            for uri in list(args['objURIs']):
20
                if not uri in Request.modules:
21
                    del args['objURIs'][uri]
22
        if not args.get('extURIs'):
23
            args['extURIs'] = greeting.get('extURIs')
24
            for uri in list(args['extURIs']):
25
                if not uri in Request.modules:
26
                    del args['extURIs'][uri]
27
        return Request.build('epp:login', args)
28