DriverConfig::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 11
ccs 0
cts 0
cp 0
crap 2
rs 10

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/**
4
 * This file is part of Cycle Database package.
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 Cycle\Database\Config;
13
14
use Cycle\Database\Driver\DriverInterface;
15
16
/**
17
 * Connection configuration described in DBAL config file. Any driver can be
18
 * used as data source for multiple databases as table prefix and quotation
19
 * defined on Database instance level.
20
 *
21
 * @template T of PDOConnectionConfig
22
 */
23
abstract class DriverConfig
24
{
25
    use RestoreStateTrait;
26
27
    public array $options = [];
28
    protected array $defaultOptions = [
29
        'withDatetimeMicroseconds' => false,
30
        'logInterpolatedQueries' => false,
31
        'logQueryParameters' => false,
32
    ];
33
34
    /**
35 60
     * @param T $connection
36
     * @param class-string<DriverInterface> $driver
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<DriverInterface> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<DriverInterface>.
Loading history...
37
     * @param bool $reconnect Allow reconnects
38
     * @param non-empty-string $timezone All datetime objects will be converted
39
     *        relative to this timezone (must match with DB timezone!)
40
     * @param bool $queryCache Enables query caching
41
     * @param bool $readonlySchema Disable schema modifications
42
     * @param bool $readonly Disable write expressions
43
     * @param array{
44 60
     *     withDatetimeMicroseconds?: bool,
45
     *     logInterpolatedQueries?: bool,
46
     *     logQueryParameters?: bool
47
     * } $options
48
     */
49
    public function __construct(
50
        public ConnectionConfig $connection,
51
        public string $driver,
52
        public bool $reconnect = true,
53
        public string $timezone = 'UTC',
54
        public bool $queryCache = true,
55
        public bool $readonlySchema = false,
56
        public bool $readonly = false,
57
        array $options = [],
58
    ) {
59
        $this->options = $options + $this->defaultOptions;
60
    }
61
}
62