DbalDriver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 2
dl 0
loc 3
c 0
b 0
f 0
cc 1
rs 10
1
<?php
2
3
/**
4
 * This file is part of orm
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Slick\Orm\Infrastructure\Logging;
13
14
use Doctrine\DBAL\Driver as DriverInterface;
15
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
16
use Psr\Log\LoggerInterface;
17
use SensitiveParameter;
0 ignored issues
show
Bug introduced by
The type SensitiveParameter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
19
/**
20
 * DbalDriver
21
 *
22
 * @package Slick\Orm\Infrastructure\Logging
23
 */
24
final class DbalDriver extends AbstractDriverMiddleware
25
{
26
27
    public function __construct(DriverInterface $driver, private readonly LoggerInterface $logger)
28
    {
29
        parent::__construct($driver);
30
    }
31
32
    /**
33
     * {@inheritDoc}
34
     */
35
    public function connect(
36
        #[SensitiveParameter]
37
        array $params,
38
    ): Connection {
39
        $this->logger->info('Connecting with parameters {params}', ['params' => $this->maskPassword($params)]);
40
41
        return new Connection(
42
            parent::connect($params),
43
            $this->logger,
44
        );
45
    }
46
47
    /**
48
     * @param array<string,mixed> $params Connection parameters
49
     *
50
     * @return array<string,mixed>
51
     */
52
    private function maskPassword(
53
        #[SensitiveParameter]
54
        array $params,
55
    ): array {
56
        if (isset($params['password'])) {
57
            $params['password'] = '*********';
58
        }
59
60
        return $params;
61
    }
62
}
63