Code Duplication    Length = 67-67 lines in 2 locations

src/logic/DomainTariffManager.php 1 location

@@ 12-78 (lines=67) @@
9
use yii\web\NotFoundHttpException;
10
use yii\web\UnprocessableEntityHttpException;
11
12
class DomainTariffManager extends AbstractTariffManager
13
{
14
    /**
15
     * @var DomainTariffForm
16
     */
17
    public $form;
18
19
    /**
20
     * @inheritdoc
21
     */
22
    protected $type = 'domain';
23
24
    public function init()
25
    {
26
        parent::init();
27
28
        if (!Yii::getAlias('@domain', true)) {
29
            throw new NotFoundHttpException('Domain module is missing');
30
        }
31
    }
32
33
    protected function buildForm()
34
    {
35
        $this->form = new DomainTariffForm([
36
            'scenario' => $this->scenario,
37
            'zones' => $this->getZones(),
38
            'baseTariffs' => $this->baseTariffs,
39
            'tariff' => $this->tariff
40
        ]);
41
    }
42
43
    public function insert()
44
    {
45
        $data = $this->form->toArray();
46
47
        try {
48
            $result = Tariff::perform('Create', $data);
49
        } catch (ErrorResponseException $e) {
50
            throw new UnprocessableEntityHttpException($e->getMessage(), 0, $e);
51
        }
52
53
        $this->form->id = $result['id'];
54
55
        return true;
56
    }
57
58
    public function update()
59
    {
60
        $data = $this->form->toArray();
61
62
        try {
63
            $result = Tariff::perform('Update', $data);
64
        } catch (ErrorResponseException $e) {
65
            throw new UnprocessableEntityHttpException($e->getMessage(), 0, $e);
66
        }
67
68
        return true;
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    protected function getZones()
75
    {
76
        return Yii::$app->hiart->get('getZones');
77
    }
78
}
79

src/logic/VdsTariffManager.php 1 location

@@ 12-78 (lines=67) @@
9
use yii\web\NotFoundHttpException;
10
use yii\web\UnprocessableEntityHttpException;
11
12
class VdsTariffManager extends AbstractTariffManager
13
{
14
    /**
15
     * @var VdsTariffForm
16
     */
17
    public $form;
18
19
    /**
20
     * @inheritdoc
21
     */
22
    protected $type = 'server';
23
24
    public function init()
25
    {
26
        parent::init();
27
28
        if (!Yii::getAlias('@server', true)) {
29
            throw new NotFoundHttpException('Domain module is missing');
30
        }
31
    }
32
33
    protected function buildForm()
34
    {
35
        $this->form = new DomainTariffForm([
36
            'scenario' => $this->scenario,
37
            'zones' => $this->getZones(),
38
            'baseTariffs' => $this->baseTariffs,
39
            'tariff' => $this->tariff
40
        ]);
41
    }
42
43
    public function insert()
44
    {
45
        $data = $this->form->toArray();
46
47
        try {
48
            $result = Tariff::perform('Create', $data);
49
        } catch (ErrorResponseException $e) {
50
            throw new UnprocessableEntityHttpException($e->getMessage(), 0, $e);
51
        }
52
53
        $this->form->id = $result['id'];
54
55
        return true;
56
    }
57
58
    public function update()
59
    {
60
        $data = $this->form->toArray();
61
62
        try {
63
            $result = Tariff::perform('Update', $data);
64
        } catch (ErrorResponseException $e) {
65
            throw new UnprocessableEntityHttpException($e->getMessage(), 0, $e);
66
        }
67
68
        return true;
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    protected function getZones()
75
    {
76
        return Yii::$app->hiart->get('getZones');
77
    }
78
}
79