Completed
Push — master ( d594a1...81b2d1 )
by Matthias
02:04
created

BufferCollection::expired()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace MatthiasMullie\Scrapbook\Buffered\Utils;
4
5
use MatthiasMullie\Scrapbook\Adapters\Collections\MemoryStore as MemoryStoreCollection;
6
7
/**
8
 * @todo
9
 *
10
 * @author Matthias Mullie <[email protected]>
11
 * @copyright Copyright (c) 2014, Matthias Mullie. All rights reserved
12
 * @license LICENSE MIT
13
 */
14
class BufferCollection extends MemoryStoreCollection
15
{
16
    /**
17
     * @var Buffer
18
     */
19
    protected $cache;
20
21
    /**
22
     * @param Buffer $cache
23
     * @param string $name
24
     */
25
    public function __construct(Buffer $cache, $name)
26
    {
27
        parent::__construct($cache, $name);
28
    }
29
30
    /**
31
     * Check if a key existed in local storage, but is now expired.
32
     *
33
     * Because our local buffer is also just a real cache, expired items will
34
     * just return nothing, which will lead us to believe no such item exists in
35
     * that local cache, and we'll reach out to the real cache (where the value
36
     * may not yet have been expired because that may have been part of an
37
     * uncommitted write)
38
     * So we'll want to know when a value is in local cache, but expired!
39
     *
40
     * @param string $key
41
     *
42
     * @return bool
43
     */
44 View Code Duplication
    public function expired($key)
0 ignored issues
show
Duplication introduced by Matthias Mullie
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        if ($this->get($key) !== false) {
47
            // returned a value, clearly not yet expired
48
            return false;
49
        }
50
51
        // a known item, not returned by get, is expired
52
        return array_key_exists($key, $this->cache->items);
53
    }
54
}
55