|
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); |
|
|
|
|
|
|
64
|
|
|
} catch (ErrorResponseException $e) { |
|
65
|
|
|
throw new UnprocessableEntityHttpException($e->getMessage(), 0, $e); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return true; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.