Completed
Push — master ( 19307d...e58f7e )
by Nekrasov
04:19 queued 02:31
created

Database::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
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
     * @throws Exception
16
     */
17
    public function __construct($connectionName = 'default')
18
    {
19
        $connections = Configuration::getInstance()->get('connections');
20
21
        if (!array_key_exists($connectionName, $connections)) {
22
            throw new Exception("Connection '$connectionName' is not found in .settings.php");
23
        }
24
25
        $connection = $connections[$connectionName];
26
27
        parent::__construct(
28
            "mysql:dbname={$connection['database']};host={$connection['host']}",
29
            $connection['login'],
30
            $connection['password']
31
        );
32
    }
33
}
34