Passed
Push — master ( 96cf3f...2f1f5f )
by Maxim
06:45 queued 22s
created

Registry::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Core\Internal\Common;
6
7
use Spiral\Core\Config;
8
use Spiral\Core\Options;
9
10
/**
11
 * @internal
12
 */
13
final class Registry
14
{
15
    /**
16
     * @param array<string, object> $objects
17
     */
18 1322
    public function __construct(
19
        private Config $config,
20
        private array $objects = [],
21
        private Options $options = new Options(),
22
    ) {
23 1322
    }
24
25 1319
    public function set(string $name, object $value): void
26
    {
27 1319
        $this->objects[$name] = $value;
28
    }
29
30
    /**
31
     * @template T
32
     *
33
     * @param class-string<T> $interface
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<T> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<T>.
Loading history...
34
     *
35
     * @return T
36
     */
37 1319
    public function get(string $name, string $interface): object
38
    {
39 1319
        $className = $this->config->$name;
40 1319
        $result = $this->objects[$name] ?? new $className($this);
41 1319
        \assert($result instanceof $interface);
42 1319
        return $result;
43
    }
44
45 1322
    public function getOptions(): Options
46
    {
47 1322
        return $this->options;
48
    }
49
}
50