CachePool   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 39
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getCachePsr16() 0 5 1
A getCachePsr6() 0 11 2
A getCacheSymfony() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Cache\Business\Pool;
15
16
use Micro\Plugin\Cache\Business\Adapter\AdapterFactoryInterface;
17
use Psr\Cache\CacheItemPoolInterface;
18
use Symfony\Component\Cache\Adapter\AbstractAdapter;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Cache\Adapter\AbstractAdapter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Symfony\Component\Cache\Adapter\Psr16Adapter;
20
use Symfony\Component\Cache\Psr16Cache;
21
22
class CachePool implements CachePoolInterface
23
{
24
    /**
25
     * @var array<string, CacheItemPoolInterface>
26
     */
27
    private array $cacheItemsCollection;
28
29 4
    public function __construct(
30
        private readonly AdapterFactoryInterface $adapterFactory
31
    ) {
32 4
        $this->cacheItemsCollection = [];
33
    }
34
35 4
    public function getCachePsr16(string $cachePoolName): CacheItemPoolInterface
36
    {
37 4
        $cache = new Psr16Cache($this->getCachePsr6($cachePoolName));
38
39 4
        return new Psr16Adapter($cache);
40
    }
41
42 4
    public function getCachePsr6(string $cachePoolName): CacheItemPoolInterface
43
    {
44 4
        if (\array_key_exists($cachePoolName, $this->cacheItemsCollection)) {
45 4
            return $this->cacheItemsCollection[$cachePoolName];
46
        }
47
48 4
        $item = $this->adapterFactory->create($cachePoolName);
49
50 4
        $this->cacheItemsCollection[$cachePoolName] = $item;
51
52 4
        return $item;
53
    }
54
55 4
    public function getCacheSymfony(string $cachePoolName): AbstractAdapter
56
    {
57
        /** @var AbstractAdapter $item */
58 4
        $item = $this->getCachePsr16($cachePoolName);
59
60 4
        return $item;
61
    }
62
}
63