Pool::setItemDuration()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/cache/blob/master/LICENSE
6
 * @link       https://github.com/flipbox/cache
7
 */
8
9
namespace Flipbox\Cache;
10
11
use Stash\Pool as BasePool;
12
13
/**
14
 * @author Flipbox Factory <[email protected]>
15
 * @since 2.0.0
16
 */
17
class Pool extends BasePool implements PoolDurationInterface
18
{
19
20
    /**
21
     * The cache duration
22
     *
23
     * @var null|int|\DateInterval
24
     */
25
    protected $itemDuration;
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function setItemDuration($duration)
31
    {
32
        if (!$duration instanceof \DateInterval) {
33
            $duration = (int)$duration;
34
        }
35
36
        $this->itemDuration = $duration;
37
38
        return $this;
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function getItemDuration()
45
    {
46
        return $this->itemDuration;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getItem($key)
53
    {
54
        // Get cache item
55
        $item = parent::getItem($key);
56
57
        // Set the expiration
58
        $item->expiresAfter($this->getItemDuration());
0 ignored issues
show
Bug introduced by
It seems like $this->getItemDuration() targeting Flipbox\Cache\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...
59
60
        return $item;
61
    }
62
}
63