Passed
Pull Request — 2.x (#83)
by Maxim
36:42 queued 16:48
created

DsnConnectionConfig::__set_state()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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 string|null
21
     */
22
    private ?string $database = null;
23
24
    /**
25
     * @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...
26
     * @psalm-allow-private-mutation
27
     */
28
    public string $dsn;
29
30
    /**
31
     * @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...
32
     * @param array $options
33
     */
34
    public function __construct(
35
        string|\Stringable $dsn,
36
        array $options = []
37
    ) {
38
        parent::__construct($options);
39
40
        /** @psalm-suppress ArgumentTypeCoercion */
41
        $this->dsn = DataSourceName::normalize((string)$dsn, $this->getName());
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47
    public function getSourceString(): string
48
    {
49
        /** @psalm-suppress ArgumentTypeCoercion */
50
        return $this->database ??= \substr($this->getDsn(), \strlen($this->getName()) + 1);
51
    }
52
53
    /**
54
     * {@inheritDoc}
55
     */
56
    public function getDsn(): string
57
    {
58
        return $this->dsn;
59
    }
60
61
    public static function __set_state(array $state): self
62
    {
63
        return new self(...$state);
0 ignored issues
show
Bug introduced by
$state is expanded, but the parameter $dsn of Cycle\Database\Config\SQ...onConfig::__construct() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

63
        return new self(/** @scrutinizer ignore-type */ ...$state);
Loading history...
64
    }
65
}
66