Completed
Push — master ( 57e7bf...8a74a7 )
by P.R.
01:36
created

ReferenceHtmlFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 100 %
Metric Value
wmc 4
dl 42
loc 42
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generate_chapter() 11 11 2
A write_into_file() 11 11 1
A 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
"""
2
SDoc
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
# ----------------------------------------------------------------------------------------------------------------------
9
from sdoc.helper.Html import Html
10
from sdoc.sdoc2 import node_store
11
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
12
13
14 View Code Duplication
class ReferenceHtmlFormatter(HtmlFormatter):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
15
    """
16
    HtmlFormatter for generating HTML code for references.
17
    """
18
19
    # ------------------------------------------------------------------------------------------------------------------
20
    def generate(self, node, file):
21
        """
22
        Generates the HTML code for a reference node.
23
24
        :param sdoc.sdoc2.node.ReferenceNode.ReferenceNode node: The reference node.
25
        :param file file: The output file.
26
        """
27
        self.write_into_file(node, file)
28
29
        super().generate(node, file)
30
31
    # ------------------------------------------------------------------------------------------------------------------
32
    def generate_chapter(self, node, file):
33
        """
34
        Generates the HTML code for a reference node.
35
36
        :param sdoc.sdoc2.node.ReferenceNode.ReferenceNode node: The reference node.
37
        :param file file: The output file.
38
        """
39
        if file:
40
            self.write_into_file(node, file)
41
42
        super().generate_chapter(node, file)
43
44
    # ------------------------------------------------------------------------------------------------------------------
45
    def write_into_file(self, node, file):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
46
        """
47
        Writes data into opened file.
48
49
        :param sdoc.sdoc2.node.ReferenceNode.ReferenceNode node: The reference node.
50
        :param file file: The output file.
51
        """
52
        attributes = {'class': node.get_option_value('class'),
53
                      'href': node.get_option_value('href')}
54
55
        file.write(Html.generate_element('a', attributes, node.argument))
56
57
58
# ----------------------------------------------------------------------------------------------------------------------
59
node_store.register_formatter('ref', 'html', ReferenceHtmlFormatter)
60