sdoc.sdoc.SDocVisitor.SDocVisitor.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 3

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 12
loc 12
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nop 2
crap 1
1
# ----------------------------------------------------------------------------------------------------------------------
2 1
from typing import Optional
3
4 1
from antlr4.Token import CommonToken
5 1
from cleo.io.io import IO
6
7
8 1 View Code Duplication
class SDocVisitor:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9
    """
10
    Parent visitor for SDoc level 1 & 2.
11
    """
12
13
    # ------------------------------------------------------------------------------------------------------------------
14 1
    def __init__(self, io: IO):
15
        """
16
        Object constructor.
17
        """
18
19 1
        self._io: IO = io
20
        """
21
        Styled output formatter.
22
        """
23
24 1
        self._errors: int = 0
25 1
        """
26
        The error count.
27
        """
28
29
    # ------------------------------------------------------------------------------------------------------------------
30 1
    @property
31 1
    def errors(self) -> int:
32
        """
33
        Getter for the error count.
34
        """
35 1
        return self._errors
36
37
    # ------------------------------------------------------------------------------------------------------------------
38 1
    def _error(self, message: str, token: Optional[CommonToken] = None) -> None:
39
        """
40
        Logs an error.
41
42
        :param str message: The error message.This message will be appended with 'at filename:line.column' ot the token.
43
        :param antlr4.Token.CommonToken token: The token where the error occurred.
44
        """
45
        self._errors += 1
46
47
        filename = token.getInputStream().fileName  # Replace fileName with get_source_name() when implemented in ANTLR.
48
        line_number = token.line
49
        column_number = token.column + 1
50
        messages = [message]
51
        if token:
52
            messages.append('Position: {0!s}:{1:d}.{2:d}'.format(filename, line_number, column_number))
53
        self._io.write_error(messages)
54
55
# ----------------------------------------------------------------------------------------------------------------------
56