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

Driver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
dl 0
loc 30
rs 10
c 1
b 0
f 0
ccs 0
cts 11
cp 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A connect() 0 9 1
A maskPassword() 0 7 2
A __construct() 0 3 1
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