sdoc.sdoc2.node.PartNode   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 76.27 %

Test Coverage

Coverage 55%

Importance

Changes 0
Metric Value
wmc 5
eloc 21
dl 45
loc 59
ccs 11
cts 20
cp 0.55
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A PartNode.get_hierarchy_level() 5 5 1
A PartNode.__init__() 9 9 1
A PartNode.number() 14 14 2
A PartNode.get_command() 5 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1 1
from typing import Any, Dict
2
3 1
from cleo.io.io import IO
4
5 1
from sdoc.sdoc2.helper.Enumerable import Enumerable
6 1
from sdoc.sdoc2.node.HeadingNode import HeadingNode
7 1
from sdoc.sdoc2.NodeStore import NodeStore
8
9
10 1 View Code Duplication
class PartNode(HeadingNode):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11
    """
12
    SDoc2 node for parts.
13
    """
14
15
    # ------------------------------------------------------------------------------------------------------------------
16 1
    def __init__(self, io: IO, options: Dict[str, str], argument: str):
17
        """
18
        PartNode constructor
19
20
        :param OutputStyle io: The IO object.
21
        :param dict[str, str] options: The options of this part.
22
        :param str argument: The title of this part.
23
        """
24
        super().__init__(io, 'part', options, argument)
25
26
    # ------------------------------------------------------------------------------------------------------------------
27 1
    def get_command(self) -> str:
28
        """
29
        Returns command of this node (i.e. 'part').
30
        """
31
        return 'part'
32
33
    # ------------------------------------------------------------------------------------------------------------------
34 1
    def get_hierarchy_level(self, parent_hierarchy_level: int = -1) -> int:
35
        """
36
        Returns 0.
37
        """
38
        return 0
39
40
    # ------------------------------------------------------------------------------------------------------------------
41 1
    def number(self, enumerable_numbers: Dict[str, Any]) -> None:
42
        """
43
        Sets number of heading nodes.
44
45
        :param dict[str,any] enumerable_numbers:
46
        """
47
        if 'part' not in enumerable_numbers:
48
            enumerable_numbers['part'] = Enumerable()
49
50
        enumerable_numbers['part'].generate_numeration(self.get_hierarchy_level())
51
        enumerable_numbers['part'].increment_last_level()
52
        enumerable_numbers['part'].remove_starting_zeros()
53
54
        super().number(enumerable_numbers)
55
56
57
# ----------------------------------------------------------------------------------------------------------------------
58
NodeStore.register_inline_command('part', PartNode)
59