Completed
Push — 10.x ( c22aa1 )
by Tim
12:07
created

RegistryProcessor::flushCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Services\RegistryProcessor
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2019 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Services;
22
23
use TechDivision\Import\Cache\CacheAdapterInterface;
24
25
/**
26
 * Array based implementation of a registry.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2019 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/techdivision/import
32
 * @link      http://www.techdivision.com
33
 */
34
class RegistryProcessor implements RegistryProcessorInterface
35
{
36
37
    /**
38
     * The cache adapter instance.
39
     *
40
     * @var \TechDivision\Import\Cache\CacheAdapterInterface
41
     */
42
    protected $cacheAdapter;
43
44
    /**
45
     * Initialize the repository with the passed connection and utility class name.
46
     *
47
     * @param \TechDivision\Import\Cache\CacheAdapterInterface $cacheAdapter The cache adapter instance
48
     */
49
    public function __construct(CacheAdapterInterface $cacheAdapter)
50
    {
51
        $this->cacheAdapter = $cacheAdapter;
52
    }
53
54
    /**
55
     * Register the passed attribute under the specified key in the registry.
56
     *
57
     * @param string  $key        The cache key to use
58
     * @param mixed   $value      The value that has to be cached
59
     * @param array   $references An array with references to add
60
     * @param boolean $override   Flag that allows to override an exising cache entry
61
     *
62
     * @return void
63
     * @throws \Exception Is thrown, if the key has already been used
64
     */
65
    public function setAttribute($key, $value, array $references = array(), $override = false)
66
    {
67
        $this->cacheAdapter->toCache($key, $value, $references, $override);
68
    }
69
70
    /**
71
     * Return's the attribute with the passed key from the registry.
72
     *
73
     * @param mixed $key The key to return the attribute for
74
     *
75
     * @return mixed The requested attribute
76
     */
77
    public function getAttribute($key)
78
    {
79
        return $this->cacheAdapter->fromCache($key);
80
    }
81
82
    /**
83
     * Query whether or not an attribute with the passed key has already been registered.
84
     *
85
     * @param mixed $key The key to query for
86
     *
87
     * @return boolean TRUE if the attribute has already been registered, else FALSE
88
     */
89
    public function hasAttribute($key)
90
    {
91
        return $this->cacheAdapter->isCached($key);
92
    }
93
94
    /**
95
     * Remove the attribute with the passed key from the registry.
96
     *
97
     * @param mixed $key The key of the attribute to return
98
     *
99
     * @return void
100
     */
101
    public function removeAttribute($key)
102
    {
103
        $this->cacheAdapter->removeAttribute($key);
0 ignored issues
show
Bug introduced by
The method removeAttribute() does not seem to exist on object<TechDivision\Impo...\CacheAdapterInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
104
    }
105
106
    /**
107
     * Flush the cache.
108
     *
109
     * @return void
110
     */
111
    public function flushCache()
112
    {
113
        $this->cacheAdapter->flushCache();
114
    }
115
116
    /**
117
     * Raises the value for the attribute with the passed key by one.
118
     *
119
     * @param mixed $key         The key of the attribute to raise the value for
120
     * @param mixed $counterName The name of the counter to raise
121
     *
122
     * @return integer The counter's new value
123
     */
124
    public function raiseCounter($key, $counterName)
125
    {
126
        return $this->cacheAdapter->raiseCounter($key, $counterName);
127
    }
128
129
    /**
130
     * This method merges the passed attributes with an array that
131
     * has already been added under the passed key.
132
     *
133
     * If no value will be found under the passed key, the attributes
134
     * will simply be registered.
135
     *
136
     * @param mixed $key        The key of the attributes that has to be merged with the passed ones
137
     * @param array $attributes The attributes that has to be merged with the exising ones
138
     *
139
     * @return void
140
     * @throws \Exception Is thrown, if the already registered value is no array
141
     * @link http://php.net/array_replace_recursive
142
     */
143
    public function mergeAttributesRecursive($key, array $attributes)
144
    {
145
        $this->cacheAdapter->mergeAttributesRecursive($key, $attributes);
146
    }
147
}
148