Runtime   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 92%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 123
ccs 23
cts 25
cp 0.92
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A clear() 0 8 1
A getItem() 0 11 2
A deleteItem() 0 10 2
A save() 0 6 1
A hasItem() 0 4 1
A isSupported() 0 4 1
1
<?php
2
/**
3
 * Part of the Joomla Framework Cache Package
4
 *
5
 * @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
6
 * @license    GNU General Public License version 2 or later; see LICENSE
7
 */
8
9
namespace Joomla\Cache\Adapter;
10
11
use Joomla\Cache\AbstractCacheItemPool;
12
use Joomla\Cache\Item\Item;
13
use Psr\Cache\CacheItemInterface;
14
15
/**
16
 * Runtime memory cache driver.
17
 *
18
 * @since       1.0
19
 * @deprecated  The joomla/cache package is deprecated
20
 */
21
class Runtime extends AbstractCacheItemPool
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Cache\AbstractCacheItemPool has been deprecated with message: The joomla/cache package is deprecated

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
22
{
23
	/**
24
	 * Database of cached items, we use ArrayObject so it can be easily passed by reference
25
	 *
26
	 * @var    \ArrayObject
27
	 * @since  __DEPLOY_VERSION__
28
	 */
29
	protected $db;
30
31
	/**
32
	 * Constructor.
33
	 *
34
	 * @param   mixed  $options  An options array, or an object that implements \ArrayAccess
35
	 *
36
	 * @since   __DEPLOY_VERSION__
37
	 */
38 18
	public function __construct($options = array())
39
	{
40 18
		parent::__construct($options);
41
42 18
		$this->db = new \ArrayObject;
43 18
	}
44
45
	/**
46
	 * This will wipe out the entire cache's keys
47
	 *
48
	 * @return  boolean  True if the pool was successfully cleared. False if there was an error.
49
	 *
50
	 * @since   1.0
51
	 */
52 18
	public function clear()
53
	{
54
		// Replace the db with a new blank array
55 18
		$clearData = $this->db->exchangeArray(array());
56 18
		unset($clearData);
57
58 18
		return true;
59
	}
60
61
	/**
62
	 * Returns a Cache Item representing the specified key.
63
	 *
64
	 * @param   string  $key  The key for which to return the corresponding Cache Item.
65
	 *
66
	 * @return  CacheItemInterface  The corresponding Cache Item.
67
	 *
68
	 * @since   __DEPLOY_VERSION__
69
	 */
70 11
	public function getItem($key)
71
	{
72 11
		$item = new Item($key);
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Cache\Item\Item has been deprecated with message: The joomla/cache package is deprecated

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
73
74 11
		if ($this->hasItem($key))
75
		{
76 9
			$item->set($this->db[$key]);
77
		}
78
79 11
		return $item;
80
	}
81
82
	/**
83
	 * Removes the item from the pool.
84
	 *
85
	 * @param   string  $key  The key to delete.
86
	 *
87
	 * @return  boolean  True if the item was successfully removed. False if there was an error.
88
	 *
89
	 * @since   __DEPLOY_VERSION__
90
	 */
91 4
	public function deleteItem($key)
92
	{
93 4
		if ($this->hasItem($key))
94
		{
95 4
			$newCache = array_diff_key($this->db->getArrayCopy(), array($key => $key));
96 4
			$this->db->exchangeArray($newCache);
97
		}
98
99 4
		return true;
100
	}
101
102
	/**
103
	 * Persists a cache item immediately.
104
	 *
105
	 * @param   CacheItemInterface  $item  The cache item to save.
106
	 *
107
	 * @return  boolean  True if the item was successfully persisted. False if there was an error.
108
	 *
109
	 * @since   __DEPLOY_VERSION__
110
	 */
111 15
	public function save(CacheItemInterface $item)
112
	{
113 15
		$this->db[$item->getKey()] = $item->get();
114
115 15
		return true;
116
	}
117
118
	/**
119
	 * Confirms if the cache contains specified cache item.
120
	 *
121
	 * @param   string  $key  The key for which to check existence.
122
	 *
123
	 * @return  boolean  True if item exists in the cache, false otherwise.
124
	 *
125
	 * @since   1.0
126
	 */
127 15
	public function hasItem($key)
128
	{
129 15
		return array_key_exists($key, $this->db);
130
	}
131
132
	/**
133
	 * Test to see if the CacheItemPoolInterface is available
134
	 *
135
	 * @return  boolean  True on success, false otherwise
136
	 *
137
	 * @since   __DEPLOY_VERSION__
138
	 */
139
	public static function isSupported(): bool
140
	{
141
		return true;
142
	}
143
}
144