Completed
Push — master ( fe5a1c...a272f5 )
by Dmitry
24:42 queued 09:37
created

ServerQuery::withMonitoringSettings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\server\models\query;
12
13
use hiqdev\hiart\ActiveQuery;
14
use Yii;
15
16
class ServerQuery extends ActiveQuery
17
{
18
    public function withBindings(): self
19
    {
20
        if (Yii::$app->user->can('hub.read')) {
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

20
        if (Yii::$app->user->/** @scrutinizer ignore-call */ can('hub.read')) {

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...
21
            $this->joinWith('bindings');
22
            $this->andWhere(['with_bindings' => true]);
23
        }
24
25
        return $this;
26
    }
27
28
    public function withUses(): self
29
    {
30
        $this->joinWith('uses');
31
        $this->andWhere(['with_uses' => true]);
32
33
        return $this;
34
    }
35
36
    public function withBlocking(): self
37
    {
38
        $this->joinWith('blocking');
39
        $this->andWhere(['with_blocking' => true]);
40
41
        return $this;
42
    }
43
44
    public function withHardwareSettings(): self
45
    {
46
        if (Yii::$app->user->can('part.read')) {
47
            $this->joinWith(['hardwareSettings']);
48
            $this->andWhere(['with_hardwareSettings' => 1]);
49
        }
50
51
        return $this;
52
    }
53
54
    public function withSoftwareSettings(): self
55
    {
56
        if (Yii::$app->user->can('server.manage-settings')) {
57
            $this->joinWith(['softwareSettings']);
58
            $this->andWhere(['with_softwareSettings' => 1]);
59
        }
60
61
        return $this;
62
    }
63
64
    public function withMonitoringSettings(): self
65
    {
66
        if (Yii::$app->user->can('server.manage-settings')) {
67
            $this->joinWith(['monitoringSettings']);
68
            $this->andWhere(['with_monitoringSettings' => 1]);
69
        }
70
71
        return $this;
72
    }
73
74
    public function withConsumptions(): self
75
    {
76
        $this->joinWith('consumptions');
77
        $this->andWhere(['with_consumptions' => true]);
78
79
        return $this;
80
    }
81
82
    public function withHardwarePrices(): self
83
    {
84
        $this->andWhere(['with_hardwarePrices' => true]);
85
86
        return $this;
87
    }
88
}
89