Completed
Pull Request — master (#1)
by Fabrice
06:22
created

FlowAbstract   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 148
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 2
dl 0
loc 148
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getStats() 0 4 1
A getFlowMap() 0 4 1
A getNodes() 0 4 1
A getNodeMap() 0 4 1
A getProgressMod() 0 4 1
A getFlowStatus() 0 4 1
A getFlowId() 0 4 1
A setParent() 0 6 1
A getParent() 0 4 1
A hasParent() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of NodalFlow.
5
 *     (c) Fabrice de Stefanis / https://github.com/fab2s/NodalFlow
6
 * This source file is licensed under the MIT license which you will
7
 * find in the LICENSE file or at https://opensource.org/licenses/MIT
8
 */
9
10
namespace fab2s\NodalFlow\Flows;
11
12
use fab2s\NodalFlow\Nodes\NodeInterface;
13
14
/**
15
 * Abstract Class FlowAbstract
16
 */
17
abstract class FlowAbstract implements FlowInterface
18
{
19
    use FlowIdTrait;
20
21
    /**
22
     * The parent Flow, only set when branched
23
     *
24
     * @var FlowInterface
25
     */
26
    public $parent;
27
28
    /**
29
     * Current Flow Status
30
     *
31
     * @var FlowStatusInterface
32
     */
33
    protected $flowStatus;
34
35
    /**
36
     * The underlying node structure
37
     *
38
     * @var NodeInterface[]
39
     */
40
    protected $nodes = [];
41
42
    /**
43
     * @var FlowMapInterface
44
     */
45
    protected $flowMap;
46
47
    /**
48
     * Progress modulo to apply
49
     * Set to x if you want to trigger
50
     * progress every x iterations in flow
51
     *
52
     * @var int
53
     */
54
    protected $progressMod = 1024;
55
56
    /**
57
     * Get the stats array with latest Node stats
58
     *
59
     * @return array
60
     */
61
    public function getStats()
62
    {
63
        return $this->flowMap->getStats();
64
    }
65
66
    /**
67
     * Get the stats array with latest Node stats
68
     *
69
     * @return FlowMapInterface
70
     */
71
    public function getFlowMap()
72
    {
73
        return $this->flowMap;
74
    }
75
76
    /**
77
     * Get the Node array
78
     *
79
     * @return NodeInterface[]
80
     */
81
    public function getNodes()
82
    {
83
        return $this->nodes;
84
    }
85
86
    /**
87
     * Get/Generate Node Map
88
     *
89
     * @return array
90
     */
91
    public function getNodeMap()
92
    {
93
        return $this->flowMap->getNodeMap();
94
    }
95
96
    /**
97
     * Get current $progressMod
98
     *
99
     * @return int
100
     */
101
    public function getProgressMod()
102
    {
103
        return $this->progressMod;
104
    }
105
106
    /**
107
     * The Flow status can either indicate be:
108
     *      - clean (isClean()): everything went well
109
     *      - dirty (isDirty()): one Node broke the flow
110
     *      - exception (isException()): an exception was raised during the flow
111
     *
112
     * @return FlowStatusInterface
113
     */
114
    public function getFlowStatus()
115
    {
116
        return $this->flowStatus;
117
    }
118
119
    /**
120
     * getId() alias for backward compatibility
121
     *
122
     * @deprecated use `getId` instead
123
     *
124
     * @return string
125
     */
126
    public function getFlowId()
127
    {
128
        return $this->getId();
129
    }
130
131
    /**
132
     * Set parent Flow, happens only when branched
133
     *
134
     * @param FlowInterface $flow
135
     *
136
     * @return $this
137
     */
138
    public function setParent(FlowInterface $flow)
139
    {
140
        $this->parent = $flow;
141
142
        return $this;
143
    }
144
145
    /**
146
     * Get eventual parent Flow
147
     *
148
     * @return FlowInterface
149
     */
150
    public function getParent()
151
    {
152
        return $this->parent;
153
    }
154
155
    /**
156
     * Tells if this flow has a parent
157
     *
158
     * @return bool
159
     */
160
    public function hasParent()
161
    {
162
        return !empty($this->parent);
163
    }
164
}
165