Completed
Push — master ( 49a516...79d061 )
by Marco
04:40
created

Apc   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 35
loc 35
ccs 12
cts 15
cp 0.8
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 15 15 2
A getStats() 15 15 2

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 namespace Comodojo\SimpleCache\Providers;
2
3
use \Comodojo\Cache\Drivers\Apc as ApcDriver;
4
use \Comodojo\Cache\Components\EnhancedCacheItemPoolStats;
5
use \Psr\Log\LoggerInterface;
6
use \Comodojo\Exception\SimpleCacheException;
7
use \Exception;
8
9
/**
10
 * Apcu provider
11
 *
12
 * @package     Comodojo Spare Parts
13
 * @author      Marco Giovinazzi <[email protected]>
14
 * @license     MIT
15
 *
16
 * LICENSE:
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27 View Code Duplication
class Apc extends AbstractEnhancedProvider {
0 ignored issues
show
Duplication introduced by
This class 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...
28
29 34
    public function __construct(LoggerInterface $logger = null) {
30
31
        try {
32
33 34
            $this->driver = new ApcDriver();
34
35 34
            parent::__construct($logger);
36
37
        } catch (Exception $e) {
38
39
            throw new SimpleCacheException($e->getMessage());
40
41
        }
42
43 34
    }
44
45 2
    public function getStats() {
46
47 2
        $info = $this->driver->stats();
48
49 2
        $entries = isset($info['num_entries']) ? $info['num_entries'] : null;
50
51 2
        return new EnhancedCacheItemPoolStats(
52 2
            $this->getId(),
53 2
            $this->driver->getName(),
54 2
            $this->getState(),
55
            $entries,
56 2
            $info
57
        );
58
59
    }
60
61
}
62