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

FileConnectionConfig   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 39
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSourceString() 0 3 1
A getDsn() 0 3 1
A __construct() 0 5 1
A __set_state() 0 3 1
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
16
class FileConnectionConfig extends ConnectionConfig implements ProvidesSourceString
17
{
18
    /**
19
     * @param string $database The pathname to the SQLite database file.
20
     *        - In case of keyword ":memory:" {@see MemoryConnectionConfig}.
21
     *        - In case of empty string value {@see TempFileConnectionConfig}.
22
     * @param array $options
23
     */
24 26
    public function __construct(
25
        public string $database = '',
26
        array $options = []
27
    ) {
28 26
        parent::__construct($options);
29 26
    }
30
31
    /**
32
     * Returns the SQLite-specific PDO DataSourceName, that looks like:
33
     * <code>
34
     *  sqlite:/path/to/database.db
35
     * </code>
36
     *
37
     * {@inheritDoc}
38
     */
39 8
    public function getDsn(): string
40
    {
41 8
        return \sprintf('%s:%s', $this->getName(), $this->database);
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47 2
    public function getSourceString(): string
48
    {
49 2
        return $this->database;
50
    }
51
52
    public static function __set_state(array $state): self
53
    {
54
        return new self(...$state);
0 ignored issues
show
Bug introduced by
$state is expanded, but the parameter $database 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

54
        return new self(/** @scrutinizer ignore-type */ ...$state);
Loading history...
55
    }
56
}
57