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

Resolver   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 10
dl 0
loc 19
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 17 2
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