Config::init()   C
last analyzed

Complexity

Conditions 14
Paths 2

Size

Total Lines 20
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 14

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 14
eloc 18
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 20
ccs 17
cts 17
cp 1
crap 14
rs 6.2666

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace kalanis\kw_pedigree;
4
5
6
use kalanis\kw_mapper\Interfaces\IDriverSources;
7
use kalanis\kw_mapper\MapperException;
8
use kalanis\kw_mapper\Storage\Database;
9
10
11
/**
12
 * Class Config
13
 * @package kalanis\kw_pedigree
14
 * Default configuration for testing DB in kw_pedigree
15
 * You can call your own implementation and settings in bootstrap
16
 * This is mainly example of configuration, but you can use it
17
 */
18
class Config
19
{
20 2
    public static function init(string $sourceName = 'pedigree'): void
21
    {
22
        try { // try if this config exists
23 2
            Database\ConfigStorage::getInstance()->getConfig($sourceName);
24 2
        } catch (MapperException $ex) { // if not use our own - with possibility to set it from environment variables
25 2
            $type = getenv('KW_PEDIGREE_DB_TYPE');
26 2
            $host = getenv('KW_PEDIGREE_DB_HOST');
27 2
            $port = getenv('KW_PEDIGREE_DB_PORT');
28 2
            $user = getenv('KW_PEDIGREE_DB_USER');
29 2
            $pass = getenv('KW_PEDIGREE_DB_PASS');
30 2
            $db = getenv('KW_PEDIGREE_DB_NAME');
31 2
            Database\ConfigStorage::getInstance()->addConfig(
32 2
                Database\Config::init()->setTarget(
33 2
                    ((false !== $type) && !is_array($type)) ? strval($type) : IDriverSources::TYPE_PDO_MYSQL,
34
                    $sourceName,
35 2
                    ((false !== $host) && !is_array($host)) ? strval($host) : 'kwcms-mariadb',
36 2
                    ((false !== $port) && !is_array($port)) ? intval($port) : 3306,
37 2
                    ((false !== $user) && !is_array($user)) ? strval($user) : 'root',
38 2
                    ((false !== $pass) && !is_array($pass)) ? strval($pass) : '951357456852',
39 2
                    ((false !== $db) && !is_array($db)) ? strval($db) : 'kwcms'
40
                )
41
            );
42
        }
43 2
    }
44
}
45