sdoc.sdoc2.formatter.html.DocumentHtmlFormatter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 77.42 %

Test Coverage

Coverage 64.52%

Importance

Changes 0
Metric Value
wmc 7
eloc 32
dl 48
loc 62
ccs 20
cts 31
cp 0.6452
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B DocumentHtmlFormatter.generate_document_node() 30 30 6
A DocumentHtmlFormatter.generate() 10 10 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
2
3 1
from sdoc.helper.Html import Html
4 1
from sdoc.sdoc2 import in_scope, out_scope
5 1
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
6 1
from sdoc.sdoc2.node.DocumentNode import DocumentNode
7 1
from sdoc.sdoc2.NodeStore import NodeStore
8
9
10 1 View Code Duplication
class DocumentHtmlFormatter(HtmlFormatter):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11
    """
12
    HtmlFormatter for generating HTML code for document node.
13
    """
14
15
    # ------------------------------------------------------------------------------------------------------------------
16 1
    def generate(self, node: DocumentNode, file: Any) -> None:
17
        """
18
        Generates the HTML code for a document node.
19
20
        :param DocumentNode node: The document node.
21
        :param any file: The output file.
22
        """
23 1
        self.generate_document_node(node, file)
24
25 1
        HtmlFormatter.generate(self, node, file)
26
27
    # ------------------------------------------------------------------------------------------------------------------
28 1
    @staticmethod
29 1
    def generate_document_node(node: DocumentNode, file: Any) -> None:
30
        """
31
        Generates the HTML code for heading node.
32
33
        :param DocumentNode node: The document node.
34
        :param any file: The output file.
35
        """
36 1
        file.write('<div class="sdoc-document-title-outer">')
37 1
        if node.title_node_id:
38
            title_node = in_scope(node.title_node_id)
39
            file.write(Html.generate_element('h1', {}, title_node.argument))
40
            out_scope(title_node)
41
42 1
        file.write('<div class="sdoc-document-title-inner">')
43
44 1
        if node.date_node_id:
45
            date_node = in_scope(node.date_node_id)
46
            if date_node.argument:
47
                file.write(Html.generate_element('span', {'class': 'sdoc-document-date'}, date_node.argument))
48
            out_scope(date_node)
49
50 1
        if node.version_node_id:
51
            version_node = in_scope(node.version_node_id)
52
            if version_node.argument:
53
                file.write(Html.generate_element('span', {'class': 'sdoc-document-version'}, version_node.argument))
54
            out_scope(version_node)
55
56 1
        file.write('</div>')
57 1
        file.write('</div>')
58
59
60
# ----------------------------------------------------------------------------------------------------------------------
61
NodeStore.register_formatter('document', 'html', DocumentHtmlFormatter)
62