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

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 75.93 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 20
dl 41
loc 54
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A ReferenceHtmlFormatter.write_into_file() 9 9 1
A ReferenceHtmlFormatter.get_html() 12 12 1
A ReferenceHtmlFormatter.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.formatter.html.HtmlFormatter import HtmlFormatter
5 1
from sdoc.sdoc2.node.ReferenceNode import ReferenceNode
6 1
from sdoc.sdoc2.NodeStore import NodeStore
7
8
9 1 View Code Duplication
class ReferenceHtmlFormatter(HtmlFormatter):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
10
    """
11
    HtmlFormatter for generating HTML code for references.
12
    """
13
14
    # ------------------------------------------------------------------------------------------------------------------
15 1
    def generate(self, node: ReferenceNode, file: Any) -> None:
16
        """
17
        Generates the HTML code for a reference node.
18
19
        :param ReferenceNode node: The reference node.
20
        :param any file: The output file.
21
        """
22 1
        self.write_into_file(node, file)
23
24 1
        HtmlFormatter.generate(self, node, file)
25
26
    # ------------------------------------------------------------------------------------------------------------------
27 1
    @staticmethod
28 1
    def write_into_file(node: ReferenceNode, file: Any) -> None:
29
        """
30
        Writes data into opened file.
31
32
        :param ReferenceNode node: The reference node.
33
        :param any file: The output file.
34
        """
35 1
        file.write(ReferenceHtmlFormatter.get_html(node))
36
37
    # ------------------------------------------------------------------------------------------------------------------
38 1
    @staticmethod
39 1
    def get_html(node: ReferenceNode) -> str:
40
        """
41
        Returns string with generated HTML tag.
42
43
        :param ReferenceNode node: The reference node.
44
        """
45 1
        attributes = {'class': node.get_option_value('class'),
46
                      'href':  node.get_option_value('href'),
47
                      'title': node.get_option_value('title')}
48
49 1
        return Html.generate_element('a', attributes, str(node.text))
50
51
52
# ----------------------------------------------------------------------------------------------------------------------
53
NodeStore.register_formatter('ref', 'html', ReferenceHtmlFormatter)
54