Pool::getItemDuration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/stash-cache/blob/master/LICENSE
6
 * @link       https://github.com/flipbox/stash-cache
7
 */
8
9
namespace Flipbox\Stash;
10
11
/**
12
 * @author Flipbox Factory <[email protected]>
13
 * @since 1.0.0
14
 */
15
class Pool extends \Stash\Pool implements PoolDurationInterface
16
{
17
18
    /**
19
     * The cache duration
20
     *
21
     * @var null|int|\DateInterval
22
     */
23
    protected $itemDuration;
24
25
    /**
26
     * @inheritdoc
27
     */
28 2
    public function setItemDuration($duration)
29
    {
30 2
        if (!$duration instanceof \DateInterval) {
31 2
            $duration = (int)$duration;
32
        }
33
34 2
        $this->itemDuration = $duration;
35
36 2
        return $this;
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 2
    public function getItemDuration()
43
    {
44 2
        return $this->itemDuration;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getItem($key)
51
    {
52
        // Get cache item
53
        $item = parent::getItem($key);
54
55
        // Set the expiration
56
        $item->expiresAfter($this->getItemDuration());
0 ignored issues
show
Bug introduced by
It seems like $this->getItemDuration() targeting Flipbox\Stash\Pool::getItemDuration() can also be of type null; however, Stash\Interfaces\ItemInterface::expiresAfter() does only seem to accept integer|object<DateInterval>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
57
58
        return $item;
59
    }
60
}
61