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

MemcacheHealthIndicator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
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