Completed
Push — master ( 815faa...197710 )
by Aimeos
07:55
created

Standard::getMultiple()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2014
6
 * @copyright Aimeos (aimeos.org), 2015-2016
7
 * @package MW
8
 * @subpackage MAdmin
9
 */
10
11
12
namespace Aimeos\MAdmin\Cache\Proxy;
13
14
15
/**
16
 * Cache proxy for creating cache object on demand.
17
 *
18
 * @package MAdmin
19
 * @subpackage Cache
20
 */
21
class Standard
22
	implements \Aimeos\MW\Cache\Iface
23
{
24
	private $object;
25
	private $context;
26
27
28
	/**
29
	 * Initializes the cache controller.
30
	 *
31
	 * @param \Aimeos\MShop\Context\Item\Iface $context MShop context object
32
	 */
33
	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
34
	{
35
		$this->context = $context;
36
	}
37
38
39
	/**
40
	 * Removes all expired cache entries.
41
	 *
42
	 * @throws \Aimeos\MW\Cache\Exception If the cache server doesn't respond
43
	 */
44
	public function cleanup()
45
	{
46
		$this->getObject()->cleanup();
47
	}
48
49
50
	/**
51
	 * Removes all entries of the site from the cache.
52
	 *
53
	 * @throws \Aimeos\MW\Cache\Exception If the cache server doesn't respond
54
	 */
55
	public function clear()
56
	{
57
		$this->getObject()->clear();
58
	}
59
60
61
	/**
62
	 * Removes the cache entry identified by the given key.
63
	 *
64
	 * @param string $key Key string that identifies the single cache entry
65
	 * @throws \Aimeos\MW\Cache\Exception If the cache server doesn't respond
66
	 */
67
	public function delete( $key )
68
	{
69
		$this->getObject()->delete( $key );
70
	}
71
72
73
	/**
74
	 * Removes the cache entries identified by the given keys.
75
	 *
76
	 * @param string[] $keys List of key strings that identify the cache entries
77
	 * 	that should be removed
78
	 * @throws \Aimeos\MW\Cache\Exception If the cache server doesn't respond
79
	 */
80
	public function deleteMultiple( $keys )
81
	{
82
		$this->getObject()->deleteMultiple( $keys );
0 ignored issues
show
Documentation introduced by
$keys is of type array<integer,string>, but the function expects a object<Aimeos\MW\Cache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
83
	}
84
85
86
	/**
87
	 * Removes the cache entries identified by the given tags.
88
	 *
89
	 * @param string[] $tags List of tag strings that are associated to one or more
90
	 * 	cache entries that should be removed
91
	 * @throws \Aimeos\MW\Cache\Exception If the cache server doesn't respond
92
	 */
93
	public function deleteByTags( array $tags )
94
	{
95
		$this->getObject()->deleteByTags( $tags );
96
	}
97
98
99
	/**
100
	 * Returns the cached value for the given key.
101
	 *
102
	 * @param string $key Path to the requested value like product/id/123
103
	 * @param mixed $default Value returned if requested key isn't found
104
	 * @return mixed Value associated to the requested key. If no value for the
105
	 * key is found in the cache, the given default value is returned
106
	 * @throws \Aimeos\MW\Cache\Exception If the cache server doesn't respond
107
	 */
108
	public function get( $key, $default = null )
109
	{
110
		return $this->getObject()->get( $key, $default );
111
	}
112
113
114
	/**
115
	 * Returns the cached values for the given cache keys if available.
116
	 *
117
	 * @param string[] $keys List of key strings for the requested cache entries
118
	 * @param mixed $default Default value to return for keys that do not exist
119
	 * @return array Associative list of key/value pairs for the requested cache
120
	 * 	entries. If a cache entry doesn't exist, neither its key nor a value
121
	 * 	will be in the result list
122
	 * @throws \Aimeos\MW\Cache\Exception If the cache server doesn't respond
123
	 */
124
	public function getMultiple( $keys, $default = null )
125
	{
126
		return $this->getObject()->getMultiple( $keys, $default );
0 ignored issues
show
Documentation introduced by
$keys is of type array<integer,string>, but the function expects a object<Aimeos\MW\Cache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
127
	}
128
129
130
	/**
131
	 * Returns the cached keys and values associated to the given tags if available.
132
	 *
133
	 * @param string[] $tags List of tag strings associated to the requested cache entries
134
	 * @return array Associative list of key/value pairs for the requested cache
135
	 * 	entries. If a tag isn't associated to any cache entry, nothing is returned
136
	 * 	for that tag
137
	 * @throws \Aimeos\MW\Cache\Exception If the cache server doesn't respond
138
	 */
139
	public function getMultipleByTags( array $tags )
140
	{
141
		return $this->getObject()->getMultipleByTags( $tags );
142
	}
143
144
145
	/**
146
	 * Sets the value for the given key in the cache.
147
	 *
148
	 * @param string $key Key string for the given value like product/id/123
149
	 * @param string $value Value string that should be stored for the given key
150
	 * @param int|string|null $expires Date/time string in "YYYY-MM-DD HH:mm:ss"
151
	 * 	format when the cache entry expires
152
	 * @param string[] $tags List of tag strings that should be assoicated to the
153
	 * 	given value in the cache
154
	 * @throws \Aimeos\MW\Cache\Exception If the cache server doesn't respond
155
	 */
156
	public function set( $key, $value, $expires = null, array $tags = array() )
157
	{
158
		$this->getObject()->set( $key, $value, $expires, $tags );
159
	}
160
161
162
	/**
163
	 * Adds or overwrites the given key/value pairs in the cache, which is much
164
	 * more efficient than setting them one by one using the set() method.
165
	 *
166
	 * @param array $pairs Associative list of key/value pairs. Both must be
167
	 * 	a string
168
	 * @param array $expires Associative list of key/datetime pairs.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $expires not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
169
	 * @param string[] $tags Associative list of key/tag or key/tags pairs that should be
170
	 * 	associated to the values identified by their key. The value associated
171
	 * 	to the key can either be a tag string or an array of tag strings
172
	 * @throws \Aimeos\MW\Cache\Exception If the cache server doesn't respond
173
	 */
174
	public function setMultiple( $pairs, $expires = null, array $tags = array() )
175
	{
176
		$this->getObject()->setMultiple( $pairs, $expires, $tags );
0 ignored issues
show
Documentation introduced by
$pairs is of type array, but the function expects a object<Aimeos\MW\Cache\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
177
	}
178
179
180
	/**
181
	 * Returns the cache object or creates a new one if it doesn't exist yet.
182
	 *
183
	 * @return \Aimeos\MW\Cache\Iface Cache object
184
	 */
185
	protected function getObject()
186
	{
187
		if( !isset( $this->object ) ) {
188
			$this->object = \Aimeos\MAdmin\Cache\Manager\Factory::createManager( $this->context )->getCache();
189
		}
190
191
		return $this->object;
192
	}
193
}
194