Wincache::getItem()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 0
cts 7
cp 0
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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\HasExpirationDateInterface;
13
use Joomla\Cache\Item\Item;
14
use Psr\Cache\CacheItemInterface;
15
16
/**
17
 * WinCache cache driver for the Joomla Framework.
18
 *
19
 * @since       1.0
20
 * @deprecated  The joomla/cache package is deprecated
21
 */
22
class Wincache 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...
23
{
24
	/**
25
	 * This will wipe out the entire cache's keys
26
	 *
27
	 * @return  boolean  True if the pool was successfully cleared. False if there was an error.
28
	 *
29
	 * @since   1.0
30
	 */
31
	public function clear()
32
	{
33
		return wincache_ucache_clear();
34
	}
35
36
	/**
37
	 * Returns a Cache Item representing the specified key.
38
	 *
39
	 * @param   string  $key  The key for which to return the corresponding Cache Item.
40
	 *
41
	 * @return  CacheItemInterface  The corresponding Cache Item.
42
	 *
43
	 * @since   __DEPLOY_VERSION__
44
	 */
45 View Code Duplication
	public function getItem($key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
	{
47
		$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...
48
		$success = true;
49
		$value = wincache_ucache_get($key, $success);
50
51
		if ($success)
52
		{
53
			$item->set($value);
54
		}
55
56
		return $item;
57
	}
58
59
	/**
60
	 * Removes the item from the pool.
61
	 *
62
	 * @param   string  $key  The key to delete.
63
	 *
64
	 * @return  boolean  True if the item was successfully removed. False if there was an error.
65
	 *
66
	 * @since   __DEPLOY_VERSION__
67
	 */
68
	public function deleteItem($key)
69
	{
70
		if ($this->hasItem($key))
71
		{
72
			return wincache_ucache_delete($key);
73
		}
74
75
		// If the item doesn't exist, no error
76
		return true;
77
	}
78
79
	/**
80
	 * Persists a cache item immediately.
81
	 *
82
	 * @param   CacheItemInterface  $item  The cache item to save.
83
	 *
84
	 * @return  boolean  True if the item was successfully persisted. False if there was an error.
85
	 *
86
	 * @since   __DEPLOY_VERSION__
87
	 */
88 View Code Duplication
	public function save(CacheItemInterface $item)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
	{
90
		// If we are able to find out when the item expires - find out. Else bail.
91
		if ($item instanceof HasExpirationDateInterface)
92
		{
93
			$ttl = $this->convertItemExpiryToSeconds($item);
94
		}
95
		else
96
		{
97
			$ttl = 0;
98
		}
99
100
		return wincache_ucache_set($item->getKey(), $item->get(), $ttl);
101
	}
102
103
	/**
104
	 * Confirms if the cache contains specified cache item.
105
	 *
106
	 * @param   string  $key  The key for which to check existence.
107
	 *
108
	 * @return  boolean  True if item exists in the cache, false otherwise.
109
	 *
110
	 * @since   1.0
111
	 */
112
	public function hasItem($key)
113
	{
114
		return wincache_ucache_exists($key);
115
	}
116
117
	/**
118
	 * Test to see if the CacheItemPoolInterface is available
119
	 *
120
	 * @return  boolean  True on success, false otherwise
121
	 *
122
	 * @since   __DEPLOY_VERSION__
123
	 */
124
	public static function isSupported(): bool
125
	{
126
		return extension_loaded('wincache') && function_exists('wincache_ucache_get') && !strcmp(ini_get('wincache.ucenabled'), "1");
127
	}
128
}
129