Memory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
wmc 2
lcom 1
cbo 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A memoizeCallable() 0 11 2
1
<?php
2
namespace DominionEnterprises\Memoize;
3
4
/**
5
 * An in-memory memoizer that keeps the cached values around for the lifetime of this instance.
6
 */
7
class Memory implements Memoize
8
{
9
    /**
10
     * The saved results
11
     *
12
     * @var array
13
     */
14
    private $_cache = [];
15
16
    /**
17
     * $cacheTime is ignored - this will keep the results around for the lifetime of this instance.
18
     *
19
     * @see Memoize::memoizeCallable
20
     */
21
    public function memoizeCallable($key, $compute, $cacheTime = null)
22
    {
23
        if (array_key_exists($key, $this->_cache)) {
24
            return $this->_cache[$key];
25
        }
26
27
        $result = call_user_func($compute);
28
        $this->_cache[$key] = $result;
29
30
        return $result;
31
    }
32
}
33