DatabaseTables   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 14
c 2
b 0
f 0
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 25 5
1
<?php
2
namespace Health\Checks\Servers;
3
4
use Health\Checks\HealthCheckInterface;
5
use DB;
6
use Health\HealthCheck;
7
8
/**
9
 * DatabaseTables Check
10
 */
11
class DatabaseTables extends Database implements HealthCheckInterface
12
{
13
14
    /**
15
     *
16
     * {@inheritdoc}
17
     * @see \Health\Checks\HealthCheckInterface::call()
18
     */
19
    public function call()
20
    {
21
        $health = parent::call();
22
23
        if ($health->getState() == HealthCheck::STATE_UP) {
24
            $builder = $this->getBuilder();
25
26
            $tables = $this->getParam('tables', []);
27
            $missing = [];
28
            foreach ($tables as $table) {
29
                if (! DB::getSchemaBuilder()->hasTable($table)) {
30
                    $missing[] = $table;
31
32
                    $builder->down();
33
                }
34
            }
35
36
            if ($missing) {
37
                $builder->withData('missing', $missing);
38
            }
39
40
            $health = $builder->build();
41
        }
42
43
        return $health;
44
    }
45
}
46