Failed Conditions
Push — master ( 5f5e96...daf37e )
by Adrien
03:02
created

Driver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
ccs 0
cts 2
cp 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\DBAL\Logging;
6
7
use Doctrine\DBAL\Driver as DriverInterface;
8
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
9
use Ecodev\Felix\Log\Handler\DbHandler;
10
use SensitiveParameter;
11
12
final class Driver extends AbstractDriverMiddleware
13
{
14
    public function __construct(DriverInterface $driver, private readonly DbHandler $dbHandler)
15
    {
16
        parent::__construct($driver);
17
    }
18
19
    public function connect(#[SensitiveParameter] array $params): Connection
20
    {
21
        _log()->debug('Connecting to DB', $this->maskPassword($params));
22
23
        $connection = new Connection(parent::connect($params));
24
25
        $this->dbHandler->enable();
26
27
        return $connection;
28
    }
29
30
    /**
31
     * @param array<string,mixed> $params
32
     *
33
     * @return array<string,mixed>
34
     */
35
    private function maskPassword(#[SensitiveParameter] array $params): array
36
    {
37
        if (isset($params['password'])) {
38
            $params['password'] = '***REDACTED***';
39
        }
40
41
        return $params;
42
    }
43
}
44