PluginClassResolverCacheDecorator::resolve()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
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\Configuration\Helper\Business\Plugin;
13
14
class PluginClassResolverCacheDecorator implements PluginClassResolverInterface
15
{
16
    /**
17
     * @var array<string, object>
18
     */
19
    private array $cache;
20
21 2
    public function __construct(private readonly PluginClassResolverInterface $pluginClassResolver)
22
    {
23 2
        $this->cache = [];
24
    }
25
26 2
    public function resolve(string $pluginAlias): object
27
    {
28 2
        if (\array_key_exists($pluginAlias, $this->cache)) {
29 1
            return $this->cache[$pluginAlias];
30
        }
31
32 2
        $result = $this->pluginClassResolver->resolve($pluginAlias);
33
34 2
        $this->cache[$pluginAlias] = $result;
35
36 2
        return $result;
37
    }
38
}
39