Test Failed
Pull Request — master (#1082)
by Maxim
11:40
created

Registry::getOptions()   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 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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 1313
     */
18
    public function __construct(
19
        private Config $config,
20
        private array $objects = [],
21 1313
        private Options $options = new Options(),
22
    ) {
23 1313
    }
24
25 1313
    public function set(string $name, object $value): void
26
    {
27
        $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 1313
     * @return T
36
     */
37 1313
    public function get(string $name, string $interface): object
38 1313
    {
39 1313
        $className = $this->config->$name;
40 1313
        $result = $this->objects[$name] ?? new $className($this);
41
        \assert($result instanceof $interface);
42
        return $result;
43
    }
44
45
    public function getOptions(): Options
46
    {
47
        return $this->options;
48
    }
49
}
50