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

FlowRegistry::set()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
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\NodalFlowException;
13
14
/**
15
 * class FlowRegistry
16
 */
17
class FlowRegistry
18
{
19
    /**
20
     * @var array
21
     */
22
    protected static $registry = [];
23
24
    /**
25
     * @param string $key
26
     * @param mixed  $value
27
     */
28
    public static function set($key, $value)
29
    {
30
        if (!isset(static::$registry[$key])) {
31
            throw new NodalFlowException('');
32
        }
33
        static::$registry[$key] = $value;
34
    }
35
36
    /**
37
     * @param null|string $key
38
     *
39
     * @return array|mixed|null
40
     */
41
    public static function &getRef($key = null)
42
    {
43
        if ($key !== null) {
44
            if (!array_key_exists($key, static::$registry)) {
45
                static::$registry[$key] = null;
46
            }
47
48
            return static::$registry[$key];
49
        }
50
51
        return static::$registry;
52
    }
53
}
54