AssignSwitchesPage   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 1
b 0
f 0
dl 0
loc 44
ccs 0
cts 19
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasPort() 0 3 1
A run() 0 5 1
A getFormFields() 0 9 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
        'net2' => '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