Completed
Push — master ( 0edfe9...83485f )
by Dmitry
08:42
created

VdsTariffManager::getZones()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace hipanel\modules\finance\logic;
4
5
use hipanel\modules\finance\forms\DomainTariffForm;
6
use hipanel\modules\finance\forms\VdsTariffForm;
7
use hipanel\modules\finance\models\Tariff;
8
use hiqdev\hiart\ErrorResponseException;
9
use Yii;
10
use yii\web\NotFoundHttpException;
11
use yii\web\UnprocessableEntityHttpException;
12
13
class VdsTariffManager extends AbstractTariffManager
14
{
15
    /**
16
     * @var VdsTariffForm
17
     */
18
    public $form;
19
20
    /**
21
     * @inheritdoc
22
     */
23
    protected $type = 'server';
24
25
    public function init()
26
    {
27
        parent::init();
28
29
        if (!Yii::getAlias('@server', true)) {
30
            throw new NotFoundHttpException('Domain module is missing');
31
        }
32
    }
33
34
    protected function buildForm()
35
    {
36
        $this->form = new VdsTariffForm([
37
            'scenario' => $this->scenario,
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);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
64
        } catch (ErrorResponseException $e) {
65
            throw new UnprocessableEntityHttpException($e->getMessage(), 0, $e);
66
        }
67
68
        return true;
69
    }
70
}
71