TestCache   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 32
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isEnabled() 0 3 1
A setEnabled() 0 3 1
A contains() 0 3 1
A get() 0 10 2
1
<?php
2
3
namespace Exsio\PhpObjectDecorator\Tests\Fixtures;
4
5
use Exsio\PhpObjectDecorator\PhpObjectDecoratorCacheInterface;
6
7
class TestCache implements PhpObjectDecoratorCacheInterface
8
{
9
10
    private array $cache = [];
11
12
    private bool $enabled = true;
13
14
    public function get(string $key, callable $provider): string
15
    {
16
        if (!$this->contains($key)) {
17
            $value             = $provider();
18
            $this->cache[$key] = $value;
19
20
            return $value;
21
        }
22
23
        return $this->cache[$key];
24
    }
25
26
    public function isEnabled(): bool
27
    {
28
        return $this->enabled;
29
    }
30
31
    public function contains(string $key)
32
    {
33
        return array_key_exists($key, $this->cache);
34
    }
35
36
    public function setEnabled(bool $enabled): void
37
    {
38
        $this->enabled = $enabled;
39
    }
40
41
}