Passed
Pull Request — master (#648)
by Konstantin
114:10 queued 112:16
created

prune_ReadingOrder.prune_ReadingOrder()   D

Complexity

Conditions 12

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 18
rs 4.8
c 0
b 0
f 0
cc 12
nop 1

How to fix   Complexity   

Complexity

Complex classes like prune_ReadingOrder.prune_ReadingOrder() 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
def prune_ReadingOrder(self):
2
    """
3
    Remove any empty ReadingOrder elements
4
    """
5
    ro = self.get_Page().get_ReadingOrder()
6
    if ro:
7
        og = ro.get_OrderedGroup()
8
        if og and (not og.get_RegionRefIndexed() and
9
                   not og.get_OrderedGroupIndexed() and
10
                   not og.get_UnorderedGroupIndexed()):
11
            og = None
12
        ug = ro.get_UnorderedGroup()
13
        if ug and (not ug.get_RegionRef() and
14
                   not ug.get_OrderedGroup() and
15
                   not ug.get_UnorderedGroup()):
16
            ug = None
17
        if not og and not ug:
18
            self.get_Page().set_ReadingOrder(None)
19