Completed
Pull Request — master (#81)
by Greg
02:13
created

CacheWrapper::has()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
namespace Consolidation\AnnotatedCommand\Cache;
3
4
/**
5
 * Make a generic cache object conform to our expected interface.
6
 */
7
class CacheWrapper implements SimpleCacheInterface
8
{
9
    protected $dataStore;
10
11
    public function __construct($dataStore)
12
    {
13
        $this->dataStore = $dataStore;
14
    }
15
16
    /**
17
     * Test for an entry from the cache
18
     * @param string $key
19
     * @return boolean
20
     */
21
    public function has($key)
22
    {
23
        if (method_exists($this->dataStore, 'has')) {
24
            return $this->dataStore->has($className);
0 ignored issues
show
Bug introduced by
The variable $className does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
25
        }
26
        $test = $this->dataStore->get($key);
27
        return !empty($test);
28
    }
29
30
    /**
31
     * Get an entry from the cache
32
     * @param string $key
33
     * @return array
34
     */
35
    public function get($key)
36
    {
37
        return (array) $this->dataStore->get($key);
38
    }
39
40
    /**
41
     * Store an entry in the cache
42
     * @param string $key
43
     * @param array $data
44
     */
45
    public function set($key, $data)
46
    {
47
        $this->dataStore->set($key, $data);
48
    }
49
}
50