Passed
Pull Request — master (#1104)
by Maxim
12:14
created

InvalidContainerScopeException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
dl 0
loc 15
ccs 5
cts 6
cp 0.8333
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Core\Exception\Shared;
6
7
use Psr\Container\NotFoundExceptionInterface;
8
use Spiral\Core\Container;
9
use Spiral\Core\Internal\Introspector;
10
11
/**
12
 * The exception may be thrown when the Container is unable to resolve requested dependency in the given scope.
13
 */
14
class InvalidContainerScopeException extends \RuntimeException implements NotFoundExceptionInterface
15
{
16
    protected string $scope;
17 3
    public function __construct(
18
        protected readonly string $id,
19
        Container|string|null $scopeOrContainer = null,
20
        protected readonly ?string $requiredScope = null,
21
    ) {
22 3
        $this->scope = \is_string($scopeOrContainer)
23
            ? $scopeOrContainer
24 3
            : Introspector::scopeName($scopeOrContainer);
25
26 3
        $req = $this->requiredScope !== null ? ", `$this->requiredScope` is required" : '';
27
28 3
        parent::__construct("Unable to resolve `$id` in the `$this->scope` scope{$req}.");
29
    }
30
}
31