PdoSqliteDriverConfiguration::getParameters()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 17
rs 9.9
ccs 13
cts 13
cp 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Doctrine\Configuration\Driver;
15
16
use Micro\Framework\Kernel\Configuration\PluginRoutingKeyConfiguration;
17
18
class PdoSqliteDriverConfiguration extends PluginRoutingKeyConfiguration implements DriverConfigurationInterface
19
{
20
    use UserPasswordTrait;
21
22
    public const CFG_PATH = 'ORM_%s_PATH';
23
    public const CFG_IN_MEMORY = 'ORM_%s_IN_MEMORY';
24
25 1
    public function getPath(): ?string
26
    {
27 1
        return $this->get(self::CFG_PATH, null, false);
28
    }
29
30
    /**
31
     * True if the SQLite database should be in-memory (non-persistent). Mutually exclusive with path. path takes precedence.
32
     */
33 3
    public function inMemory(): bool
34
    {
35 3
        return $this->get(self::CFG_IN_MEMORY, false);
36
    }
37
38 3
    public function getParameters(): array
39
    {
40 3
        $memP = [
41 3
            'memory' => true,
42 3
        ];
43
44 3
        $isInMemory = $this->inMemory();
45 3
        if (!$isInMemory) {
46 1
            $memP['memory'] = false;
47 1
            $memP['path'] = $this->getPath();
48
        }
49
50 3
        return [
51 3
            'driver' => static::name(),
52 3
            'user' => $this->getUser(),
53 3
            'password' => $this->getPassword(),
54 3
            ...$memP,
55 3
        ];
56
    }
57
58 3
    public static function name(): string
59
    {
60 3
        return 'pdo_sqlite';
61
    }
62
}
63