Completed
Push — master ( 24a86a...771b97 )
by Aimeos
10:31
created

Standard   A

Complexity

Total Complexity 27

Size/Duplication

Total Lines 218
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 218
rs 10
c 0
b 0
f 0
wmc 27
lcom 1
cbo 1

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getId() 0 6 2
A setId() 0 10 2
A getSiteId() 0 6 2
A getValue() 0 8 2
A setValue() 0 10 2
A getTimeExpire() 0 6 2
A setTimeExpire() 0 10 2
A getTags() 0 8 2
A setTags() 0 7 1
A getResourceType() 0 4 1
A fromArray() 0 19 6
A toArray() 0 15 2
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-2017
7
 * @package MAdmin
8
 * @subpackage Cache
9
 */
10
11
12
namespace Aimeos\MAdmin\Cache\Item;
13
14
15
/**
16
 * Default cache item implementation.
17
 *
18
 * @package MAdmin
19
 * @subpackage Cache
20
 */
21
class Standard
22
	extends \Aimeos\MShop\Common\Item\Base
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces between "Base" and comma; 1 found
Loading history...
23
	implements \Aimeos\MAdmin\Cache\Item\Iface
24
{
25
	private $values;
26
27
28
	/**
29
	 * Initializes the log item.
30
	 *
31
	 * @param array $values Associative list of key/value pairs
32
	 */
33
	public function __construct( array $values = [] )
34
	{
35
		parent::__construct( 'cache.', $values );
36
37
		$this->values = $values;
38
	}
39
40
41
	/**
42
	 * Returns the ID of the item if available.
43
	 *
44
	 * @return string|null ID of the item
45
	 */
46
	public function getId()
47
	{
48
		if( isset( $this->values['id'] ) ) {
49
			return (string) $this->values['id'];
50
		}
51
	}
52
53
54
	/**
55
	 * Sets the unique ID of the item.
56
	 *
57
	 * @param string $id Unique ID of the item
58
	 * @return \Aimeos\MAdmin\Cache\Item\Iface Cache item for chaining method calls
59
	 */
60
	public function setId( $id )
61
	{
62
		if( (string) $id !== $this->getId() )
63
		{
64
			$this->values['id'] = (string) $id;
65
			$this->setModified();
66
		}
67
68
		return $this;
69
	}
70
71
72
	/**
73
	 * Returns the ID of the site the item is stored
74
	 *
75
	 * @return string|null Site ID (or null if not available)
76
	 */
77
	public function getSiteId()
78
	{
79
		if( isset( $this->values['siteid'] ) ) {
80
			return (string) $this->values['siteid'];
81
		}
82
	}
83
84
85
	/**
86
	 * Returns the value associated to the key.
87
	 *
88
	 * @return string Returns the value of the item
89
	 */
90
	public function getValue()
91
	{
92
		if( isset( $this->values['value'] ) ) {
93
			return (string) $this->values['value'];
94
		}
95
96
		return '';
97
	}
98
99
100
	/**
101
	 * Sets the new value of the item.
102
	 *
103
	 * @param string $value Value of the item or null for no expiration
104
	 * @return \Aimeos\MAdmin\Cache\Item\Iface Cache item for chaining method calls
105
	 */
106
	public function setValue( $value )
107
	{
108
		if( (string) $value !== $this->getValue() )
109
		{
110
			$this->values['value'] = (string) $value;
111
			$this->setModified();
112
		}
113
114
		return $this;
115
	}
116
117
118
	/**
119
	 * Returns the expiration time of the item.
120
	 *
121
	 * @return string|null Expiration time of the item or null for no expiration
122
	 */
123
	public function getTimeExpire()
124
	{
125
		if( isset( $this->values['expire'] ) ) {
126
			return (string) $this->values['expire'];
127
		}
128
	}
129
130
131
	/**
132
	 * Sets the new expiration time of the item.
133
	 *
134
	 * @param string|null $timestamp Expiration time of the item
135
	 * @return \Aimeos\MAdmin\Cache\Item\Iface Cache item for chaining method calls
136
	 */
137
	public function setTimeExpire( $timestamp )
138
	{
139
		if( $timestamp !== $this->getValue() )
140
		{
141
			$this->values['expire'] = $this->checkDateFormat( $timestamp );
142
			$this->setModified();
143
		}
144
145
		return $this;
146
	}
147
148
149
	/**
150
	 * Returns the tags associated to the item.
151
	 *
152
	 * @return array Tags associated to the item
153
	 */
154
	public function getTags()
155
	{
156
		if( isset( $this->values['tags'] ) ) {
157
			return (array) $this->values['tags'];
158
		}
159
160
		return [];
161
	}
162
163
164
	/**
165
	 * Sets the new tags associated to the item.
166
	 *
167
	 * @param array Tags associated to the item
168
	 * @return \Aimeos\MAdmin\Cache\Item\Iface Cache item for chaining method calls
169
	 */
170
	public function setTags( array $tags )
171
	{
172
		$this->values['tags'] = $tags;
173
		$this->setModified();
174
175
		return $this;
176
	}
177
178
179
	/**
180
	 * Returns the item type
181
	 *
182
	 * @return string Item type, subtypes are separated by slashes
183
	 */
184
	public function getResourceType()
185
	{
186
		return 'cache';
187
	}
188
189
190
	/**
191
	 * Sets the item values from the given array.
192
	 *
193
	 * @param array $list Associative list of item keys and their values
194
	 * @return array Associative list of keys and their values that are unknown
195
	 */
196
	public function fromArray( array $list )
197
	{
198
		$unknown = [];
199
		$list = parent::fromArray( $list );
200
201
		foreach( $list as $key => $value )
202
		{
203
			switch( $key )
204
			{
205
				case 'cache.id': $this->setId( $value ); break;
206
				case 'cache.value': $this->setValue( $value ); break;
207
				case 'cache.expire': $this->setTimeExpire( $value ); break;
208
				case 'cache.tags': $this->setTags( $value ); break;
209
				default: $unknown[$key] = $value;
0 ignored issues
show
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
210
			}
211
		}
212
213
		return $unknown;
214
	}
215
216
217
	/**
218
	 * Returns the item values as array.
219
	 *
220
	 * @param boolean True to return private properties, false for public only
221
	 * @return array Associative list of item properties and their values
222
	 */
223
	public function toArray( $private = false )
224
	{
225
		$list = [];
226
227
		$list['cache.id'] = $this->getId();
228
		$list['cache.value'] = $this->getValue();
229
		$list['cache.expire'] = $this->getTimeExpire();
230
		$list['cache.tags'] = $this->getTags();
231
232
		if( $private === true ) {
233
			$list['cache.siteid'] = $this->getSiteId();
234
		}
235
236
		return $list;
237
	}
238
}
239