DsnConnectionConfig::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 8
ccs 0
cts 2
cp 0
crap 2
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\SQLite;
13
14
use Cycle\Database\Config\ProvidesSourceString;
15
use Cycle\Database\Config\Support\DataSourceName;
16
17
class DsnConnectionConfig extends ConnectionConfig implements ProvidesSourceString
18
{
19
    /**
20
     * @var non-empty-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
21
     *
22
     * @psalm-allow-private-mutation
23
     */
24
    public string $dsn;
25
26
    private ?string $database = null;
27
28
    /**
29
     * @param non-empty-string|\Stringable $dsn
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string|\Stringable at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string|\Stringable.
Loading history...
30
     */
31
    public function __construct(
32
        string|\Stringable $dsn,
33
        array $options = [],
34
    ) {
35
        parent::__construct($options);
36
37
        /** @psalm-suppress ArgumentTypeCoercion */
38
        $this->dsn = DataSourceName::normalize((string) $dsn, $this->getName());
39
    }
40
41
    public function getSourceString(): string
42
    {
43
        /** @psalm-suppress ArgumentTypeCoercion */
44
        return $this->database ??= \substr($this->getDsn(), \strlen($this->getName()) + 1);
45
    }
46
47
    public function getDsn(): string
48
    {
49
        return $this->dsn;
50
    }
51
}
52