DomainTariffManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 53
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A init() 0 10 2
A getFormOptions() 0 7 1
A getZones() 0 6 1
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