Test Failed
Push — feature/custom-services-v2 ( dde5b5 )
by Chema
08:49
created

CustomServiceResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 28
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 9 2
A __construct() 0 3 1
A getResolvableType() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\ClassResolver\CustomService;
6
7
use Gacela\Framework\ClassResolver\AbstractClassResolver;
8
9
final class CustomServiceResolver extends AbstractClassResolver
10
{
11
    private string $resolvableType;
12
13
    public function __construct(string $resolvableType)
14
    {
15
        $this->resolvableType = $resolvableType;
16
    }
17
18
    /**
19
     * @param object|class-string $caller
0 ignored issues
show
Documentation Bug introduced by
The doc comment object|class-string at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in object|class-string.
Loading history...
20
     *
21
     * @throws CustomServiceNotFoundException
22
     */
23
    public function resolve($caller): ?object
24
    {
25
        $resolved = $this->doResolve($caller);
26
27
        if ($resolved === null) {
28
            throw new CustomServiceNotFoundException($caller, $this->resolvableType);
29
        }
30
31
        return $resolved;
32
    }
33
34
    protected function getResolvableType(): string
35
    {
36
        return $this->resolvableType;
37
    }
38
}
39