Database::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 16
rs 9.4286
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
namespace Arrilot\BitrixDataAnonymization;
4
5
use Arrilot\DataAnonymization\Database\SqlDatabase;
6
use Bitrix\Main\Config\Configuration;
7
use Bitrix\Main\DB\Exception;
8
9
class Database extends SqlDatabase
10
{
11
    /**
12
     * Constructor.
13
     *
14
     * @param string $connectionName
15
     *
16
     * @throws Exception
17
     */
18
    public function __construct($connectionName = 'default')
19
    {
20
        $connections = Configuration::getInstance()->get('connections');
21
22
        if (!array_key_exists($connectionName, $connections)) {
23
            throw new Exception("Connection '$connectionName' is not found in .settings.php");
24
        }
25
26
        $connection = $connections[$connectionName];
27
28
        parent::__construct(
29
            "mysql:dbname={$connection['database']};host={$connection['host']}",
30
            $connection['login'],
31
            $connection['password']
32
        );
33
    }
34
}
35