FlowEventProxyTrait::getFlow()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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\Events;
11
12
use fab2s\NodalFlow\Flows\FlowInterface;
13
use fab2s\NodalFlow\Nodes\NodeInterface;
14
15
/**
16
 * trait FlowEventProxyTrait
17
 *
18
 * A good example on how BC could use the S from Symfony
19
 */
20
trait FlowEventProxyTrait
21
{
22
    /**
23
     * @var array
24
     */
25
    protected static $eventList;
26
27
    /**
28
     * @var FlowInterface
29
     */
30
    protected $flow;
31
32
    /**
33
     * @var NodeInterface|null
34
     */
35
    protected $node;
36
37
    /**
38
     * FlowEvent constructor.
39
     *
40
     * @param FlowInterface      $flow
41
     * @param NodeInterface|null $node
42
     */
43
    public function __construct(FlowInterface $flow, NodeInterface $node = null)
44
    {
45
        $this->flow = $flow;
46
        $this->node = $node;
47
    }
48
49
    /**
50
     * @return FlowInterface
51
     */
52
    public function getFlow(): FlowInterface
53
    {
54
        return $this->flow;
55
    }
56
57
    /**
58
     * @return NodeInterface|null
59
     */
60
    public function getNode(): ? NodeInterface
61
    {
62
        return $this->node;
63
    }
64
65
    /**
66
     * @param NodeInterface|null $node
67
     *
68
     * @return FlowEventInterface
69
     */
70
    public function setNode(NodeInterface $node = null): FlowEventInterface
71
    {
72
        $this->node = $node;
73
74
        /* @var FlowEventInterface $this */
75
        return $this;
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    public static function getEventList(): array
82
    {
83
        /* @var FlowEventInterface $this */
84
        if (!isset(static::$eventList)) {
0 ignored issues
show
Bug introduced by
Accessing eventList on the interface fab2s\NodalFlow\Events\FlowEventInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
85
            static::$eventList = [
86
                FlowEventInterface::FLOW_START    => FlowEventInterface::FLOW_START,
87
                FlowEventInterface::FLOW_PROGRESS => FlowEventInterface::FLOW_PROGRESS,
88
                FlowEventInterface::FLOW_CONTINUE => FlowEventInterface::FLOW_CONTINUE,
89
                FlowEventInterface::FLOW_BREAK    => FlowEventInterface::FLOW_BREAK,
90
                FlowEventInterface::FLOW_SUCCESS  => FlowEventInterface::FLOW_SUCCESS,
91
                FlowEventInterface::FLOW_FAIL     => FlowEventInterface::FLOW_FAIL,
92
            ];
93
        }
94
95
        return static::$eventList;
96
    }
97
}
98