Completed
Push — master ( f0c489...94b4bf )
by Nicolas
08:29
created

DatabaseContributor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nwidart\Actuator\Health;
6
7
use Illuminate\Contracts\Config\Repository;
8
use Illuminate\Database\DatabaseManager;
9
use PDOException;
10
11
class DatabaseContributor implements HealthContributor
12
{
13
    /**
14
     * @var Repository
15
     */
16
    private $config;
17
    /**
18
     * @var DatabaseManager
19
     */
20
    private $db;
21
22 2
    public function __construct(Repository $config, DatabaseManager $db)
23
    {
24 2
        $this->config = $config;
25 2
        $this->db = $db;
26 2
    }
27
28 2
    public function run()
29
    {
30
        try {
31 2
            $this->db->reconnect()->getPdo();
32 1
        } catch (PDOException $e) {
33 1
            return 'Not connected';
34
        }
35
        return [
36 1
            'database' => $this->config->get('database.default'),
37
        ];
38
    }
39
}
40