Passed
Pull Request — master (#1104)
by Maxim
10:52
created

InvalidContainerScopeException::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 12
ccs 5
cts 6
cp 0.8333
rs 10
c 1
b 0
f 0
cc 3
nc 4
nop 3
crap 3.0416
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