Test Failed
Pull Request — master (#2)
by Angel
04:11
created

CreditSearch::attributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace app\api\models;
4
5
use roaresearch\yii2\roa\ResourceSearch;
6
use roaresearch\yii2\workflow\models\Stage;
7
use yii\data\ActiveDataProvider;
8
9
class CreditSearch extends Credit implements ResourceSearch
10
{
11
    /**
12
     * @inhertidoc
13
     */
14
    public function attributes()
15
    {
16
        return array_merge(parent::attributes(), ['activeStage']);
17
    }
18
19
    /**
20
     * @inhertidoc
21
     */
22
    protected $autogenerateInitialWorklog = false;
23
24
    /**
25
     * @inhertidoc
26
     */
27
    public function rules()
28
    {
29
        return [
30
            [['created_by'], 'integer'],
31
            [
32
                ['activeStage'],
33
                'each',
34
                'allowMessageFromRule' => true,
35
                'rule' => [
36
                    'integer',
37
                    'message' => '{value} is not an integer',
38
                ],
39
            ],
40
        ];
41
    }
42
43
    /**
44
     * @inhertidoc
45
     */
46
    public function search(
47
        array $params,
48
        ?string $formName = ''
49
    ): ?ActiveDataProvider {
50
        $this->load($params, $formName);
51
        if (!$this->validate()) {
52
            return null;
53
        }
54
55
        $class = get_parent_class();
56
        return new ActiveDataProvider([
57
            'query' => $class::find()
58
                ->joinWith('activeWorkLog')
59
                ->andFilterWhere([
60
                    'credit.created_by' => $this->created_by,
0 ignored issues
show
Bug Best Practice introduced by
The property created_by does not exist on app\api\models\CreditSearch. Since you implemented __get, consider adding a @property annotation.
Loading history...
61
                    'activeWorkLog.stage_id' => $this->activeStage,
0 ignored issues
show
Bug Best Practice introduced by
The property activeStage does not exist on app\api\models\CreditSearch. Since you implemented __get, consider adding a @property annotation.
Loading history...
62
                ])
63
        ]);
64
    }
65
}
66