Completed
Branch master (f2efac)
by John
02:31
created

MemcacheHealthIndicator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 42
loc 42
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A doHealthCheck() 16 16 3

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
namespace Actuator\Health\Indicator;
4
5
use Actuator\Health\HealthBuilder;
6
7
/**
8
 * Simple implementation of a HealthIndicator returning status information for
9
 * Memcache in-memory data stores.
10
 *
11
 * @package Actuator\Health\Indicator
12
 */
13 View Code Duplication
class MemcacheHealthIndicator extends AbstractHealthIndicator
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...
14
{
15
    /**
16
     * @var \Memcache
17
     */
18
    private $memcache;
19
20
    /**
21
     * MemcacheHealthIndicator constructor.
22
     * @param \Memcache $memcache
23
     */
24 9
    public function __construct(\Memcache $memcache)
25
    {
26 9
        assert(!is_null($memcache), 'Memcache must not be null');
27
28 9
        $this->memcache = $memcache;
29 9
    }
30
31
    /**
32
     * Actual health check logic.
33
     *
34
     * @param HealthBuilder $builder
35
     * @throws \Exception any Exception that should create a Status::DOWN
36
     * system status.
37
     */
38 9
    protected function doHealthCheck(HealthBuilder $builder)
39
    {
40
        try {
41 9
            $version = $this->memcache->getversion();
42 9
        } catch (\Exception $e) {
43 3
            $builder->down($e);
44 3
            return;
45
        }
46
47 6
        if (!$version) {
48 3
            $builder->down();
49 3
            return;
50
        }
51
52 3
        $builder->up()->withDetail('version', $version);
53 3
    }
54
}
55