DatabaseContributor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A run() 0 12 2
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
36
        return [
37 1
            'database' => $this->config->get('database.default'),
38
        ];
39
    }
40
}
41