Test Failed
Pull Request — master (#1045)
by Aleksei
07:42
created

Resolver::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 17
rs 9.9666
c 1
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Core\Internal\Proxy;
6
7
use Spiral\Core\ContainerScope;
8
use Spiral\Core\Exception\Container\ContainerException;
9
10
/**
11
 * @internal
12
 */
13
final class Resolver
14
{
15
    public static function resolve(string $alias): object
16
    {
17
        $c = ContainerScope::getContainer() ?? throw new ContainerException('Proxy is out of scope.');
18
19
        try {
20
            $result = $c->get($alias) ?? throw new ContainerException(
21
                'Resolved `null` from the container.',
22
            );
23
        } catch (ContainerException $e) {
24
            throw new ContainerException(
25
                // todo : find required scope
26
                \sprintf('Unable to resolve `%s` in a Proxy.', $alias),
27
                previous: $e,
28
            );
29
        }
30
31
        return $result;
32
    }
33
}
34