Exec   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 17
c 2
b 0
f 0
dl 0
loc 36
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 28 6
1
<?php
2
namespace Health\Checks\Cli;
3
4
use Health\Checks\BaseCheck;
5
use Health\Checks\HealthCheckInterface;
6
use Symfony\Component\Process\Process;
7
8
class Exec extends BaseCheck implements HealthCheckInterface
9
{
10
11
    /**
12
     *
13
     * {@inheritdoc}
14
     * @see \Health\Checks\HealthCheckInterface::call()
15
     */
16
    public function call()
17
    {
18
        $builder = $this->getBuilder();
19
20
        $commands = $this->getParam('commands', []);
21
22
        foreach ($commands as $command => $data) {
23
            $result = $data['result'] ?? null;
24
            $dir = $data['dir'] ?? null;
25
            $timeout = $data['timeout'] ?? 5;
26
27
            $process = new Process($command, $dir);
28
            $process->run();
29
30
            if ($timeout) {
31
                $process->setTimeout($timeout);
32
            }
33
34
            $output = $process->getOutput();
35
36
            if (! $process->isSuccessful()) {
37
                $builder->down();
38
            } elseif ($result && ! preg_match("|{$result}|", $output)) {
39
                $builder->down();
40
            }
41
        }
42
43
        return $builder->build();
44
    }
45
}
46