MemoryCache   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isFresh() 0 8 2
A read() 0 4 1
A write() 0 5 1
1
<?php
2
3
/*
4
* This file is part of the Behat Gherkin.
5
* (c) Konstantin Kudryashov <[email protected]>
6
*
7
* For the full copyright and license information, please view the LICENSE
8
* file that was distributed with this source code.
9
*/
10
11
namespace Behat\Gherkin\Cache;
12
13
use Behat\Gherkin\Node\FeatureNode;
14
15
/**
16
 * Memory cache.
17
 * Caches feature into a memory.
18
 *
19
 * @author Konstantin Kudryashov <[email protected]>
20
 */
21
class MemoryCache implements CacheInterface
22
{
23
    private $features = array();
24
    private $timestamps = array();
25
26
    /**
27
     * Checks that cache for feature exists and is fresh.
28
     *
29
     * @param string  $path      Feature path
30
     * @param integer $timestamp The last time feature was updated
31
     *
32
     * @return Boolean
33
     */
34 3
    public function isFresh($path, $timestamp)
35
    {
36 3
        if (!isset($this->features[$path])) {
37 1
            return false;
38
        }
39
40 2
        return $this->timestamps[$path] > $timestamp;
41
    }
42
43
    /**
44
     * Reads feature cache from path.
45
     *
46
     * @param string $path Feature path
47
     *
48
     * @return FeatureNode
49
     */
50 1
    public function read($path)
51
    {
52 1
        return $this->features[$path];
53
    }
54
55
    /**
56
     * Caches feature node.
57
     *
58
     * @param string      $path    Feature path
59
     * @param FeatureNode $feature Feature instance
60
     */
61 3
    public function write($path, FeatureNode $feature)
62
    {
63 3
        $this->features[$path]   = $feature;
64 3
        $this->timestamps[$path] = time();
65 3
    }
66
}
67