CallsProcessFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 95.24%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 42
rs 10
ccs 20
cts 21
cp 0.9524
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 9 1
A construct_process() 0 5 1
A _update_structure() 0 9 3
A _create_stages() 0 5 2
1
"""Contains factory class of process with calls stages."""
2
3 1
from grortir.main.model.processes.calls_process import CallsProcess
4 1
from grortir.main.model.stages.calls_stage import CallsStage
5
6
7 1
class CallsProcessFactory:
8
    """Class which produce process with the same type of stages.
9
10
    Attributes:
11
        structure_type (str): represent type of structure
12
        how_many_nodes (int): how many nodes should be in generated process
13
        max_calls (int): max_calls for stages
14
        process (CallsProcess): process which will be incrementally build
15
        initial_vec (tuple): initial vector
16
    """
17
18 1
    def __init__(self, structure_type, how_many_nodes, max_calls,
19
                 initial_vec=()):
20
        """Constructor."""
21 1
        self.max_calls = max_calls
22 1
        self._stages_to_add = []
23 1
        self.structure_type = structure_type
24 1
        self.how_many_nodes = how_many_nodes
25 1
        self.process = CallsProcess()
26 1
        self.initial_vec = initial_vec
27
28 1
    def _update_structure(self):
29
        """Update structure of process."""
30 1
        if self.structure_type == "linear":
31 1
            if len(self._stages_to_add) > 1:
32 1
                self.process.add_path(self._stages_to_add)
33
            else:
34
                self.process.add_node(self._stages_to_add[0])
0 ignored issues
show
Bug introduced by
The Instance of CallsProcess does not seem to have a member named add_node.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
35
        else:
36 1
            raise NotImplementedError()
37
38 1
    def _create_stages(self):
39
        """Create stages which will be injected to process."""
40 1
        for i in range(self.how_many_nodes):
41 1
            self._stages_to_add += [
42
                CallsStage(str(i), self.max_calls, self.initial_vec)]
43
44 1
    def construct_process(self):
45
        """Construct process."""
46 1
        self._create_stages()
47 1
        self._update_structure()
48
        return self.process
49