Passed
Push — bugfix/support-windows ( 517fb4...0e99e7 )
by Chema
04:47
created

DocBlockResolverAwareTrait::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 6
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 6
b 0
f 0
nc 2
nop 2
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 2
rs 10
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
     * @psalm-suppress LessSpecificImplementedReturnType
17
     *
18
     * @param string $method
19
     * @param array $parameters
20
     *
21
     * @return mixed
22
     */
23 25
    public function __call($method = '', $parameters = [])
24
    {
25 25
        if (isset($this->customServices[$method])) {
26 13
            return $this->customServices[$method];
27
        }
28
29 25
        $docBlockResolver = DocBlockResolver::fromCaller($this);
30 25
        $resolvable = $docBlockResolver->getDocBlockResolvable($method);
31
32 23
        $this->customServices[$method] = (new DocBlockServiceResolver($resolvable->resolvableType()))
33 23
            ->resolve($resolvable->className());
34
35 23
        return $this->customServices[$method];
36
    }
37
}
38