Completed
Push — master ( 56b3e0...fb6bd6 )
by Dmitry
04:00
created

ServerQuery::withHardwarePrices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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('admin')) {
57
            $this->joinWith(['softwareSettings']);
58
            $this->andWhere(['with_softwareSettings' => 1]);
59
        }
60
61
        return $this;
62
    }
63
64
    public function withConsumptions(): self
65
    {
66
        $this->joinWith('consumptions');
67
        $this->andWhere(['with_consumptions' => true]);
68
69
        return $this;
70
    }
71
72
    public function withHardwarePrices(): self
73
    {
74
        $this->andWhere(['with_hardwarePrices' => true]);
75
76
        return $this;
77
    }
78
}
79