Pool   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 63.64%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 46
ccs 7
cts 11
cp 0.6364
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setItemDuration() 0 10 2
A getItemDuration() 0 4 1
A getItem() 0 10 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