Passed
Pull Request — master (#228)
by Jesús
04:37 queued 01:22
created

DocBlockResolverAwareTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
eloc 9
c 8
b 0
f 0
dl 0
loc 24
ccs 8
cts 8
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __call() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework;
6
7
use Gacela\Framework\ClassResolver\DocBlockService\DocBlockServiceResolver;
8
use Gacela\Framework\DocBlockResolver\DocBlockResolver;
9
10
trait DocBlockResolverAwareTrait
11
{
12
    /** @var array<string,?mixed> */
13
    private array $customServices = [];
14
15
    /**
16
     * @param string $method
17
     * @param array $parameters
18
     *
19
     * @return mixed
20
     */
21 25
    public function __call($method, $parameters = [])
22
    {
23 25
        if (isset($this->customServices[$method])) {
24 13
            return $this->customServices[$method];
25
        }
26
27 25
        $docBlockResolver = DocBlockResolver::fromCaller($this);
28 25
        $resolvable = $docBlockResolver->getDocBlockResolvable($method);
29
30 23
        $this->customServices[$method] = (new DocBlockServiceResolver($resolvable->resolvableType()))
31 23
            ->resolve($resolvable->className());
32
33 23
        return $this->customServices[$method];
34
    }
35
}
36