CachedSchemaFactoryDecorator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 13
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createSchema() 0 12 2
A __construct() 0 4 1
1
<?php
2
namespace ElevenLabs\Api\Factory;
3
4
use Psr\Cache\CacheItemPoolInterface;
5
6
/**
7
 * Load/Store API Schema from Cache
8
 */
9
class CachedSchemaFactoryDecorator implements SchemaFactory
10
{
11
    /** @var SchemaFactory */
12
    private $schemaFactory;
13
14
    /** @var CacheItemPoolInterface */
15
    private $cache;
16
17
    public function __construct(CacheItemPoolInterface $cache, SchemaFactory $schemaFactory)
18 2
    {
19
        $this->cache = $cache;
20 2
        $this->schemaFactory = $schemaFactory;
21 2
    }
22 2
23
    public function createSchema($schemaFile)
24 2
    {
25
        $cacheKey = hash('sha1', $schemaFile);
26 2
        $item = $this->cache->getItem($cacheKey);
27 2
        if ($item->isHit()) {
28 2
            $schema = $item->get();
29 1
        } else {
30
            $schema = $this->schemaFactory->createSchema($schemaFile);
31 1
            $this->cache->save($item->set($schema));
32 1
        }
33
34
        return $schema;
35 2
    }
36
}
37