Completed
Push — master ( b660c0...31ecd4 )
by Freek
01:48
created

Elasticsearch   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
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 Symfony\Component\Process\Process;
6
7
class Elasticsearch extends CheckDefinition
8
{
9
    public $command = 'curl --silent http://localhost:9200';
10
11
    public function command(): string
12
    {
13
        $command = $this->command;
14
15
        $customIp = $this->check->getCustomProperty('ip');
16
17
        if (! empty($customIp)) {
18
            $command = str_replace('localhost', $customIp, $command);
19
        }
20
21
        return $command;
22
    }
23
24
    public function resolve(Process $process)
25
    {
26
        $checkSucceeded = str_contains($process->getOutput(), 'lucene_version');
27
28
        if ($checkSucceeded) {
29
            $this->check->succeed('is running');
30
31
            return;
32
        }
33
34
        $this->check->fail('is not running');
35
    }
36
}
37