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

PdoSettings   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 42
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 9 1
A getSettings() 0 8 1
1
<?php namespace Limoncello\Application\Packages\PDO;
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
use PDO;
21
22
/**
23
 * @package Limoncello\Application
24
 */
25
class PdoSettings implements SettingsInterface
26
{
27
    /** Settings key */
28
    const KEY_USER_NAME = 0;
29
30
    /** Settings key */
31
    const KEY_PASSWORD = self::KEY_USER_NAME + 1;
32
33
    /** Settings key */
34
    const KEY_CONNECTION_STRING = self::KEY_PASSWORD + 1;
35
36
    /** Settings key */
37
    const KEY_OPTIONS = self::KEY_CONNECTION_STRING + 1;
38
39
    /** Settings key */
40
    const KEY_LAST = self::KEY_OPTIONS;
41
42
    /**
43
     * @inheritdoc
44
     */
45
    final public function get(): array
46
    {
47
        $defaults = $this->getSettings();
48
49
        $connectionString = $defaults[static::KEY_CONNECTION_STRING] ?? null;
50
        assert(empty($connectionString) === false, "Invalid connection string `$connectionString`.");
51
52
        return $defaults;
53
    }
54
55
    /**
56
     * @return array
57
     */
58
    protected function getSettings(): array
59
    {
60
        return [
61
            static::KEY_OPTIONS => [
62
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
63
            ],
64
        ];
65
    }
66
}
67