Elasticsearch   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A command() 0 12 2
A resolve() 0 12 2
1
<?php
2
3
namespace Spatie\ServerMonitor\CheckDefinitions;
4
5
use Illuminate\Support\Str;
6
use Symfony\Component\Process\Process;
7
8
class Elasticsearch extends CheckDefinition
9
{
10
    public $command = 'curl --silent http://localhost:9200';
11
12
    public function command(): string
13
    {
14
        $command = $this->command;
15
16
        $customIp = $this->check->getCustomProperty('ip');
17
18
        if (! empty($customIp)) {
19
            $command = str_replace('localhost', $customIp, $command);
20
        }
21
22
        return $command;
23
    }
24
25
    public function resolve(Process $process)
26
    {
27
        $checkSucceeded = Str::contains($process->getOutput(), 'lucene_version');
28
29
        if ($checkSucceeded) {
30
            $this->check->succeed('is running');
31
32
            return;
33
        }
34
35
        $this->check->fail('is not running');
36
    }
37
}
38