Failed Conditions
Pull Request — master (#23)
by Adrien
03:02
created

Driver::maskPassword()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
ccs 0
cts 4
cp 0
cc 2
nc 2
nop 1
crap 6
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 SensitiveParameter;
10
11
final class Driver extends AbstractDriverMiddleware
12
{
13
    public function __construct(DriverInterface $driver)
14
    {
15
        parent::__construct($driver);
16
    }
17
18
    public function connect(#[SensitiveParameter] array $params): Connection
19
    {
20
        _log()->info('Connecting with parameters {params}', ['params' => $this->maskPassword($params)]);
21
22
        return new Connection(parent::connect($params));
23
    }
24
25
    /**
26
     * @param array<string,mixed> $params
27
     *
28
     * @return array<string,mixed>
29
     */
30
    private function maskPassword(#[SensitiveParameter] array $params): array
31
    {
32
        if (isset($params['password'])) {
33
            $params['password'] = '***REDACTED***';
34
        }
35
36
        return $params;
37
    }
38
}
39