Failed Conditions
Pull Request — master (#1127)
by Mischa
01:56
created

coalib.output.printers.ConfWriter.write_section()   F

Complexity

Conditions 11

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 11
dl 0
loc 27
rs 3.1765

How to fix   Complexity   

Complexity

Complex classes like coalib.output.printers.ConfWriter.write_section() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
from pyprint.Printer import Printer
2
3
4
class StringPrinter(Printer):
5
    """
6
    This is a simple printer that prints everything to a string.
7
    """
8
9
    def __init__(self):
10
        """
11
        Creates a new StringPrinter with an empty print string.
12
        """
13
        Printer.__init__(self)
14
15
        self._string = ""
16
17
    def _print(self, output, **kwargs):
18
        self._string += output
19
20
    def clear(self):
21
        """
22
        Clears the print string.
23
        """
24
        self._string = ""
25
26
    @property
27
    def string(self):
28
        """
29
        Gets the print string.
30
        """
31
        return self._string
32