Passed
Push — master ( 2b04c5...3174fa )
by Jesús
01:25 queued 12s
created

GlobalServices::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\Util;
6
7
/**
8
 * This class is a helper to store global services if needed.
9
 *
10
 * For example, to be able to access the kernel data from your framework
11
 * in order to get the real (already instantiated) services and inject them
12
 * as dependencies in your gacela.php config file.
13
 *
14
 * This util class is not used for the class resolver.
15
 */
16
final class GlobalServices
17
{
18
    /** @var array<string,object> Global instances */
19
    private static array $globalInstances = [];
20
21
    public static function add(string $key, object $resolvedClass): void
22
    {
23
        self::$globalInstances[$key] = $resolvedClass;
24
    }
25
26
    public static function get(string $key): ?object
27
    {
28
        return self::$globalInstances[$key] ?? null;
29
    }
30
}
31