TestCache::setEnabled()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
}