Completed
Pull Request — master (#7)
by Fabrice
02:29
created

FlowAncestryAbstract::hasParent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
/**
13
 * Abstract Class FlowAncestryAbstract
14
 */
15
abstract class FlowAncestryAbstract extends FlowInterruptAbstract
16
{
17
    /**
18
     * The parent Flow, only set when branched
19
     *
20
     * @var FlowInterface
21
     */
22
    public $parent;
23
24
    /**
25
     * Set parent Flow, happens only when branched
26
     *
27
     * @param FlowInterface $flow
28
     *
29
     * @return $this
30
     */
31
    public function setParent(FlowInterface $flow)
32
    {
33
        $this->parent = $flow;
34
35
        return $this;
36
    }
37
38
    /**
39
     * Get eventual parent Flow
40
     *
41
     * @return FlowInterface
42
     */
43
    public function getParent()
44
    {
45
        return $this->parent;
46
    }
47
48
    /**
49
     * Tells if this flow has a parent
50
     *
51
     * @return bool
52
     */
53
    public function hasParent()
54
    {
55
        return !empty($this->parent);
56
    }
57
58
    /**
59
     * Get this Flow's root Flow
60
     *
61
     * @param FlowInterface $flow Root Flow, or self if root flow
62
     *
63
     * @return FlowInterface
64
     */
65
    public function getRootFlow(FlowInterface $flow)
66
    {
67
        while ($flow->hasParent()) {
68
            $flow = $flow->getParent();
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $flow. This often makes code more readable.
Loading history...
69
        }
70
71
        return $flow;
72
    }
73
}
74