sdoc.sdoc1.SDoc1Interpreter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 78 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 22
dl 39
loc 50
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A SDoc1Interpreter.__init__() 7 7 1
A SDoc1Interpreter.process() 22 22 2

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
import os
2
3 1
import antlr4
4 1
from cleo.io.io import IO
5
6 1
from sdoc.antlr.sdoc1Lexer import sdoc1Lexer
7 1
from sdoc.antlr.sdoc1Parser import sdoc1Parser
8 1
from sdoc.sdoc1.SDoc1Visitor import SDoc1Visitor
9
10
11 1 View Code Duplication
class SDoc1Interpreter:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
12
    """
13
    Class for processing SDoc1 documents.
14
    """
15
16
    # ------------------------------------------------------------------------------------------------------------------
17 1
    def __init__(self, io: IO):
18
        """
19
        Object constructor.
20
        """
21
22 1
        self._io: IO = io
23 1
        """
24
        Styled output formatter.
25
        """
26
27
    # ------------------------------------------------------------------------------------------------------------------
28 1
    def process(self, infile: str, outfile: str) -> int:
29
        """
30
        Processes a SDoc1 document.
31
32
        :param str infile: The input filename with the SDoc1 document.
33
        :param str outfile: The output filename with the SDoc2 document.
34
        """
35 1
        in_stream = antlr4.FileStream(infile)
36
37 1
        self._io.write_line('Writing <fso>{0!s}</fso>'.format(outfile))
38 1
        with open(outfile, 'wt') as out_stream:
39 1
            lexer = sdoc1Lexer(in_stream)
40 1
            tokens = antlr4.CommonTokenStream(lexer)
41 1
            parser = sdoc1Parser(tokens)
42 1
            tree = parser.sdoc()
43
44 1
            visitor = SDoc1Visitor(self._io, root_dir=os.path.dirname(os.path.realpath(infile)))
45
46 1
            visitor.output = out_stream
47 1
            visitor.visit(tree)
48
49 1
            return visitor.errors
50
51
# ----------------------------------------------------------------------------------------------------------------------
52