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

GlobalServices   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 13
ccs 0
cts 4
cp 0
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 3 1
A get() 0 3 1
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