Artisan   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
eloc 20
c 2
b 0
f 0
dl 0
loc 40
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B call() 0 32 7
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