Passed
Branch master (17b603)
by P.R.
01:31
created

etlt.writer.Writer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 82.61 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 19
dl 57
loc 69
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A Writer.__exit__() 2 2 1
A Writer.__enter__() 2 2 1
A Writer.fields() 8 8 1
A Writer.writerow() 10 10 1
A Writer.__init__() 7 7 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
ETLT
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
import abc
9
import copy
10
11
12 View Code Duplication
class Writer(metaclass=abc.ABCMeta):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
13
    """
14
    Abstract parent class for writing rows to a destination.
15
    """
16
17
    # ------------------------------------------------------------------------------------------------------------------
18
    def __init__(self):
19
        """
20
        Object constructor.
21
        """
22
23
        self._fields = []
24
        """
25
        The fields (or columns) that must be written to the destination.
26
27
        :type: list[str]
28
        """
29
30
    # ------------------------------------------------------------------------------------------------------------------
31
    @property
32
    def fields(self):
33
        """
34
        Getter for fields.
35
36
        :rtype: list[str]
37
        """
38
        return copy.copy(self._fields)
39
40
    # ------------------------------------------------------------------------------------------------------------------
41
    @fields.setter
42
    def fields(self, fields):
43
        """
44
        Setter for fields.
45
46
        :param list[str] fields: The fields (or columns) that must be written to the destination.
47
        """
48
        self._fields = fields
49
50
    # ------------------------------------------------------------------------------------------------------------------
51
    @abc.abstractmethod
52
    def writerow(self, row):
53
        """
54
        Writes a row to the destination.
55
56
        :param dict[str,T] row: The row.
57
58
        :rtype: None
59
        """
60
        raise NotImplementedError()
61
62
    # ------------------------------------------------------------------------------------------------------------------
63
    def __enter__(self):
64
        raise NotImplementedError()
65
66
    # ------------------------------------------------------------------------------------------------------------------
67
    def __exit__(self, exc_type, exc_value, traceback):
68
        raise NotImplementedError()
69
70
# ----------------------------------------------------------------------------------------------------------------------
71