Completed
Push — master ( 0622f1...018a2f )
by Dmitry
04:34
created

VdsTariffManager::buildForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
cc 1
eloc 5
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
        if (!Yii::getAlias('@server', true)) {
28
            throw new NotFoundHttpException('Domain module is missing');
29
        }
30
31
        parent::init();
32
    }
33
34
    public function insert()
35
    {
36
        $data = $this->form->toArray();
37
38
        try {
39
            $result = Tariff::perform('Create', $data);
40
        } catch (ErrorResponseException $e) {
41
            throw new UnprocessableEntityHttpException($e->getMessage(), 0, $e);
42
        }
43
44
        $this->form->id = $result['id'];
45
46
        return true;
47
    }
48
49
    public function update()
50
    {
51
        $data = $this->form->toArray();
52
53
        try {
54
            $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...
55
        } catch (ErrorResponseException $e) {
56
            throw new UnprocessableEntityHttpException($e->getMessage(), 0, $e);
57
        }
58
59
        return true;
60
    }
61
}
62