LocatorCached   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 31
ccs 12
cts 12
cp 1
rs 10
c 2
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A lookup() 0 18 4
1
<?php
2
3
/*
4
 *  This file is part of the Micro framework package.
5
 *
6
 *  (c) Stanislau Komar <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 */
11
12
namespace Micro\Plugin\Locator\Locator;
13
14
/**
15
 * @todo: Update this afrer implements micro/cache plugin.
16
 */
17
class LocatorCached implements LocatorInterface
18
{
19
    /**
20
     * @var array<string, array<class-string>>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string, array<class-string>> at position 6 could not be parsed: Unknown type name 'class-string' at position 6 in array<string, array<class-string>>.
Loading history...
21
     */
22
    private array $results;
23
24 1
    public function __construct(
25
        private readonly LocatorInterface $locator
26
    ) {
27 1
        $this->results = [];
28
    }
29
30 1
    public function lookup(string $classOrInterfaceName): \Generator
31
    {
32 1
        if (\array_key_exists($classOrInterfaceName, $this->results)) {
33 1
            foreach ($this->results[$classOrInterfaceName] as $class) {
34 1
                yield $class;
35
            }
36
37 1
            return;
38
        }
39
40 1
        $results = [];
41 1
        foreach ($this->locator->lookup($classOrInterfaceName) as $class) {
42 1
            $results[] = $class;
43
44 1
            yield $class;
45
        }
46
47 1
        $this->results[$classOrInterfaceName] = $results;
48
    }
49
}
50