Completed
Branch release-2.1 (e49a83)
by Mert
04:10
created

apcu_cache   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 40.82 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 20
loc 49
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isSupported() 10 10 4
A getData() 0 6 1
A putData() 10 10 2
A cleanCache() 0 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * Simple Machines Forum (SMF)
5
 *
6
 * @package SMF
7
 * @author Simple Machines http://www.simplemachines.org
8
 * @copyright 2016 Simple Machines and individual contributors
9
 * @license http://www.simplemachines.org/about/smf/license.php BSD
10
 *
11
 * @version 2.1 Beta 3
12
 */
13
14
if (!defined('SMF'))
15
	die('Hacking attempt...');
16
17
/**
18
 * Our Cache API class
19
 * @package cacheAPI
20
 */
21
class apcu_cache extends cache_api
22
{
23
	/**
24
	 * {@inheritDoc}
25
	 */
26 View Code Duplication
	public function isSupported($test = false)
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...
27
	{
28
		global $cache_memcached;
29
30
		$supported = function_exists('apcu_fetch') && function_exists('apcu_store');
31
32
		if ($test)
33
			return $supported;
34
		return parent::isSupported() && $supported;
35
	}
36
37
	/**
38
	 * {@inheritDoc}
39
	 */
40
	public function getData($key, $ttl = null)
41
	{
42
		$key = $this->prefix . strtr($key, ':/', '-_');
43
44
		return apcu_fetch($key . 'smf');
45
	}
46
47
	/**
48
	 * {@inheritDoc}
49
	 */
50 View Code Duplication
	public function putData($key, $value, $ttl = null)
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...
51
	{
52
		$key = $this->prefix . strtr($key, ':/', '-_');
53
54
		// An extended key is needed to counteract a bug in APC.
55
		if ($value === null)
56
			return apcu_delete($key . 'smf');
0 ignored issues
show
Bug Compatibility introduced by
The expression apcu_delete($key . 'smf'); of type boolean|string[] adds the type string[] to the return on line 56 which is incompatible with the return type declared by the interface cache_api_interface::putData of type boolean.
Loading history...
57
		else
58
			return apcu_store($key . 'smf', $value, $ttl);
0 ignored issues
show
Bug Compatibility introduced by
The expression apcu_store($key . 'smf', $value, $ttl); of type boolean|array adds the type array to the return on line 58 which is incompatible with the return type declared by the interface cache_api_interface::putData of type boolean.
Loading history...
59
	}
60
61
	/**
62
	 * {@inheritDoc}
63
	 */
64
	public function cleanCache($type = '')
65
	{
66
		$this->invalidateCache();
67
		return apcu_clear_cache();
68
	}
69
}