ConnectionConfig::getUsername()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
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
abstract class ConnectionConfig
15
{
16
    use RestoreStateTrait;
17
18
    /**
19
     * @var array<non-empty-string>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<non-empty-string> at position 2 could not be parsed: Unknown type name 'non-empty-string' at position 2 in array<non-empty-string>.
Loading history...
20
     */
21
    protected array $nonPrintableOptions = [
22
        // Postgres and MySQL
23
        'password',
24
        // IBM, ODBC and DB2
25
        'PWD',
26
    ];
27
28
    /**
29
     * @param non-empty-string|null $user
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string|null at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string|null.
Loading history...
30 60
     * @param non-empty-string|null $password
31
     */
32
    public function __construct(
33
        public ?string $user = null,
34 60
        public ?string $password = null,
35
    ) {}
36
37
    /**
38
     * @return non-empty-string|null
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string|null at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string|null.
Loading history...
39 62
     */
40
    public function getUsername(): ?string
41 62
    {
42
        return $this->user;
43
    }
44
45
    /**
46
     * @return non-empty-string|null
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string|null at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string|null.
Loading history...
47 62
     */
48
    public function getPassword(): ?string
49 62
    {
50
        return $this->password;
51
    }
52
53
    public function __debugInfo(): array
54
    {
55
        return $this->toArray();
56
    }
57
58
    protected function toArray(bool $secure = true): array
59
    {
60
        $options = \get_object_vars($this);
61
62
        foreach ($options as $key => $value) {
63
            if ($secure && \in_array($key, $this->nonPrintableOptions, true)) {
64
                $value = '<hidden>';
65
            }
66
67
            $options[$key] = $value;
68
        }
69
70
        return $options;
71
    }
72
}
73