ServerTypeRefCombo   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 3
b 0
f 0
dl 0
loc 20
ccs 0
cts 7
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A prepareData() 0 15 3
1
<?php
2
3
namespace hipanel\modules\server\widgets\combo;
4
5
use hipanel\modules\server\helpers\ServerHelper;
6
use hipanel\widgets\RefCombo;
7
use Yii;
8
9
class ServerTypeRefCombo extends RefCombo
10
{
11
    /**
12
     * @return array
13
     */
14
    public function prepareData(): array
15
    {
16
        $refs = parent::prepareData();
17
        if (Yii::$app->user->can('ref.view.not-used')) {
0 ignored issues
show
Bug introduced by
The method can() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
        if (Yii::$app->user->/** @scrutinizer ignore-call */ can('ref.view.not-used')) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
18
            return $refs;
19
        }
20
        $usedTypes = ServerHelper::getUsedTypes();
21
        $allowedTypes = ['dedicated', 'unmanaged', 'setup', 'jbod', 'remote', 'vds', 'avds', 'ovds', 'svds', 'cdn', 'cdnpix', 'nic', 'uplink3'];
22
        if (empty($usedTypes)) {
23
            $usedTypes = $allowedTypes;
24
        }
25
26
        return array_filter($refs, static function (string $k) use ($usedTypes): bool {
27
            return in_array($k, $usedTypes, true);
28
        }, ARRAY_FILTER_USE_KEY);
29
    }
30
}
31