Completed
Push — develop ( ea9a36...1bc5bd )
by Neomerx
05:01
created

DoctrineSettings::get()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 7
nc 1
nop 0
1
<?php namespace Limoncello\Application\Packages\Data;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Contracts\Settings\SettingsInterface;
20
21
/**
22
 * @package Limoncello\Application
23
 */
24
class DoctrineSettings implements SettingsInterface
25
{
26
    /** Settings key */
27
    const KEY_USER_NAME = 0;
28
29
    /** Settings key */
30
    const KEY_PASSWORD = self::KEY_USER_NAME + 1;
31
32
    /** Settings key */
33
    const KEY_DATABASE_NAME = self::KEY_PASSWORD + 1;
34
35
    /** Settings key */
36
    const KEY_HOST = self::KEY_DATABASE_NAME + 1;
37
38
    /** Settings key */
39
    const KEY_PORT = self::KEY_HOST + 1;
40
41
    /** Settings key */
42
    const KEY_CHARSET = self::KEY_PORT + 1;
43
44
    /** Settings key */
45
    const KEY_DRIVER = self::KEY_CHARSET + 1;
46
47
    /** Settings key */
48
    const KEY_URL = self::KEY_DRIVER + 1;
49
50
    /** Settings key */
51
    const KEY_MEMORY = self::KEY_URL + 1;
52
53
    /** Settings key */
54
    const KEY_EXTRA = self::KEY_MEMORY + 1;
55
56
    /** Settings key */
57
    const KEY_PATH = self::KEY_EXTRA + 1;
58
59
    /** Settings key */
60
    const KEY_LAST = self::KEY_PATH;
61
62
    /**
63
     * @inheritdoc
64
     */
65
    final public function get(): array
66
    {
67
        $defaults = $this->getSettings();
68
69
        $pathToDbFile = $defaults[static::KEY_PATH] ?? null;
70
        assert(
71
            ($pathToDbFile === null || file_exists($pathToDbFile) === true),
72
            "Invalid database file `$pathToDbFile`."
73
        );
74
75
        return $defaults;
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    protected function getSettings(): array
82
    {
83
        return [];
84
    }
85
}
86