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

CustomServicesResolverAwareTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __call() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework;
6
7
use Gacela\Framework\ClassResolver\CustomService\CustomServiceResolver;
8
9
trait CustomServicesResolverAwareTrait
10
{
11
    /** @var array<string,?object> */
12
    private array $customServices = [];
13
14
    public function __call(string $name, array $arguments = []): ?object
15
    {
16
        $resolvableType = lcfirst(ltrim($name, 'get'));
17
18
        if (!isset($this->customServices[$resolvableType])) {
19
            $className = $this->servicesMapping()[$resolvableType];
20
21
            $this->customServices[$resolvableType] = (new CustomServiceResolver($resolvableType))
22
                ->resolve($className);
23
        }
24
25
        return $this->customServices[$resolvableType];
26
    }
27
28
    /**
29
     * @return array<string,class-string>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string,class-string> at position 4 could not be parsed: Unknown type name 'class-string' at position 4 in array<string,class-string>.
Loading history...
30
     */
31
    abstract protected function servicesMapping(): array;
32
}
33