Completed
Push — master ( 9fec5b...0ee870 )
by Andrii
06:47 queued 10s
created

AssignSwitchesPage::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Server module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-server
6
 * @package   hipanel-module-server
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\server\widgets;
12
13
use yii\base\Widget;
14
15
class AssignSwitchesPage extends Widget
16
{
17
    /**
18
     * Rack -> location Location -> location
19
     * @var
20
     */
21
    public $form;
22
23
    /**
24
     * @var
25
     */
26
    public $models;
27
28
    /**
29
     * @var array
30
     */
31
    public $variantMap = [
32
        'pdu2' => 'pdu',
33
        'ipmi' => 'net',
34
        'nic2' => 'net',
35
    ];
36
37
    public function run()
38
    {
39
        return $this->render('AssignSwitchesPage', [
40
            'form' => $this->form,
41
            'models' => $this->models,
42
        ]);
43
    }
44
45
    public function getFormFields(): array
46
    {
47
        $fields = [];
48
        foreach (reset($this->models)->switchVariants as $name) {
49
            $fields[] = $name . '_id';
50
            $fields[] = $name . '_port';
51
        }
52
53
        return array_merge(['id'], $fields);
54
    }
55
56
    public function hasPort(string $variant): bool
57
    {
58
        return $variant !== 'location';
59
    }
60
}
61