Registry::getData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author  : Jagepard <[email protected]>
7
 * @license https://mit-license.org/ MIT
8
 */
9
10
namespace Structural\Registry;
11
12
final class Registry
13
{
14
    const ALLOWED_KEYS = [
15
        'stdClass'
16
    ];
17
18
    private static array $data = [];
19
20
    /**
21
     * Receives data
22
     * -------------
23
     * Получает данные
24
     *
25
     * @param  string    $key
26
     * @return \stdClass
27
     */
28
    public static function getData(string $key): \stdClass
29
    {
30
        if (!array_key_exists($key, self::$data)) {
31
            throw new \InvalidArgumentException('Invalid key given');
32
        }
33
        
34
        return self::$data[$key];
35
    }
36
37
    /**
38
     * Adds data
39
     * ---------
40
     * Добавляет данные
41
     *
42
     * @param  string    $key
43
     * @param  \stdClass $data
44
     * @return void
45
     */
46
    public static function setData(string $key, \stdClass $data)
47
    {
48
        if (!in_array($key, self::ALLOWED_KEYS)) {
49
            throw new \InvalidArgumentException('Invalid key given');
50
        }
51
52
        self::$data[$key] = $data;
53
    }
54
}
55