Database::call()   A
last analyzed

Complexity

Conditions 3
Paths 5

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 14
rs 10
cc 3
nc 5
nop 0
1
<?php
2
namespace Health\Checks\Servers;
3
4
use DB;
5
use Health\Checks\BaseCheck;
6
use Health\Checks\HealthCheckInterface;
7
8
/**
9
 * Database Check
10
 */
11
class Database extends BaseCheck implements HealthCheckInterface
12
{
13
14
    /**
15
     *
16
     * {@inheritdoc}
17
     * @see \Health\Checks\HealthCheckInterface::call()
18
     */
19
    public function call()
20
    {
21
        $builder = $this->getBuilder();
22
23
        try {
24
            DB::connection()->getPdo();
25
            if (! DB::connection()->getDatabaseName()) {
26
                $builder->down()->withData("error", "Could not find the database.");
27
            }
28
        } catch (\Exception $e) {
29
            $builder->down()->withData("error", "Could not open connection to database server.");
30
        }
31
32
        return $builder->build();
33
    }
34
}
35