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

CustomServicesResolverAwareTrait::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 12
rs 10
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