DomainTariffManager::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\logic;
12
13
use hipanel\modules\finance\forms\DomainTariffForm;
14
use hipanel\modules\finance\models\Tariff;
15
use hiqdev\hiart\ConnectionInterface;
16
use Yii;
17
use yii\web\NotFoundHttpException;
18
19
class DomainTariffManager extends AbstractTariffManager
20
{
21
    /**
22
     * @var DomainTariffForm
23
     */
24
    public $form;
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected $type = Tariff::TYPE_DOMAIN;
30
31
    /**
32
     * @var ConnectionInterface
33
     */
34
    private $connection;
35
36
    public function __construct(ConnectionInterface $connection, $config = [])
37
    {
38
        $this->connection = $connection;
39
40
        parent::__construct($config);
41
    }
42
43
    public function init()
44
    {
45
        parent::init();
46
47
        if (!Yii::getAlias('@domain', true)) {
48
            throw new NotFoundHttpException('Domain module is missing');
49
        }
50
51
        $this->formOptions['zones'] = $this->getZones();
52
    }
53
54
    protected function getFormOptions()
55
    {
56
        return array_merge([
57
            'class' => DomainTariffForm::class,
58
            'zones' => $this->getZones(),
59
        ], parent::getFormOptions());
60
    }
61
62
    /**
63
     * @return array
64
     */
65
    protected function getZones()
66
    {
67
        $command = $this->connection->createCommand();
68
69
        return $command->perform('getZones', '')->getData();
70
    }
71
}
72