DatabaseContributor::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 5
cts 5
cp 1
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 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