Passed
Push — master ( dbb7ba...c6992b )
by Kanstantsin
04:38
created

ExternalCacheStatefulFile::getCachedStateArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace tkanstantsin\fileupload\model;
5
6
class ExternalCacheStatefulFile extends ExternalFile implements ICacheStateful
7
{
8
    /**
9
     * @var array
10
     */
11
    private $cachedState = [];
12
13
    /**
14
     * @param array $cachedState
15
     */
16
    public function setCachedStateArray(array $cachedState): void
17
    {
18
        $this->cachedState = $cachedState;
19
    }
20
21
    /**
22
     * @return array
23
     */
24
    public function getCachedStateArray(): array
25
    {
26
        return $this->cachedState;
27
    }
28
29
    /**
30
     * @param string $format
31
     *
32
     * @see Factory::$formatterConfigArray
33
     * @return int
34
     */
35
    public function getCachedAt(string $format): ?int
36
    {
37
        $cachedAt = $this->cachedState[$format] ?? null;
38
        if ($cachedAt <= 0) {
39
            $cachedAt = null;
40
        }
41
42
        return $cachedAt;
43
    }
44
45
    /**
46
     * @param string $format
47
     * @param int $cachedAt
48
     */
49
    public function setCachedAt(string $format, int $cachedAt): void
50
    {
51
        $this->cachedState[$format] = $cachedAt;
52
        if ($cachedAt <= 0) {
53
            unset($this->cachedState[$format]);
54
        }
55
    }
56
57
    /**
58
     * @param string $format
59
     *
60
     * @return bool
61
     */
62
    public function getIsCached(string $format): bool
63
    {
64
        return $this->getCachedAt($format) !== null;
65
    }
66
}