Artisan::call()   B
last analyzed

Complexity

Conditions 7
Paths 17

Size

Total Lines 32
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 19
c 2
b 0
f 0
dl 0
loc 32
rs 8.8333
cc 7
nc 17
nop 0
1
<?php
2
namespace Health\Checks\Cli;
3
4
use Health\Checks\BaseCheck;
5
use Health\Checks\HealthCheckInterface;
6
use Illuminate\Support\Facades\Artisan as ArtisanFacade;
7
8
class Artisan 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
            $params = $data['params'] ?? [];
24
            $result = $data['result'] ?? null;
25
26
            $params = ! is_array($params) ? [
27
                $params
28
            ] : $params;
29
30
            try {
31
                ArtisanFacade::call($command, $params);
32
33
                $output = ArtisanFacade::output();
34
35
                if ($output) {
36
                    if ($result && ! preg_match("|{$result}|", $output)) {
37
                        $builder->down();
38
                    }
39
                } else {
40
                    $builder->down();
41
                }
42
            } catch (\Exception $e) {
43
                $builder->down()->withData('error', $e->getMessage());
44
            }
45
        }
46
47
        return $builder->build();
48
    }
49
}
50