GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#191)
by Herbert
10:39
created

AuditTrailSearch::search()   C

Complexity

Conditions 7
Paths 14

Size

Total Lines 38
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 7.0283

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 7
eloc 24
nc 14
nop 2
dl 0
loc 38
ccs 22
cts 24
cp 0.9167
crap 7.0283
rs 6.7272
c 2
b 1
f 0
1
<?php
2
3
namespace bedezign\yii2\audit\models;
4
5
6
use yii\base\Model;
7
use yii\data\ActiveDataProvider;
8
9
/**
10
 * AuditTrailSearch
11
 * @package bedezign\yii2\audit\models
12
 */
13
class AuditTrailSearch extends AuditTrail
14
{
15
    /**
16
     * @return array
17
     */
18 6
    public function rules()
19
    {
20
        // Note: The model is used by both the entry and the trail index pages, hence the separate use of `id` and `entry_id`
21
        return [
22 6
            [['id', 'user_id', 'entry_id', 'action', 'model', 'model_id', 'field', 'created'], 'safe'],
23 6
        ];
24
    }
25
26
    /**
27
     * @return array
28
     */
29 6
    public function scenarios()
30
    {
31
        // bypass scenarios() implementation in the parent class
32 6
        return Model::scenarios();
33
    }
34
35
    /**
36
     * @param $params
37
     * @param null $query
38
     * @return ActiveDataProvider
39
     */
40 6
    public function search($params, $query = null)
41
    {
42 6
        $query = $query ? $query : $this->find();
43
44 6
        $dataProvider = new ActiveDataProvider([
45 6
            'query' => $query,
46
            'sort' => [
47
                'defaultOrder' => [
48
                    'id' => SORT_DESC
49 6
                ]
50 6
            ]
51 6
        ]);
52
53
        // load the search form data and validate
54 6
        if (!($this->load($params) && $this->validate())) {
55 4
            return $dataProvider;
56
        }
57
58
        // adjust the query by adding the filters
59 2
        $userId = $this->user_id;
60 2
        if (strlen($this->user_id))
61 2
            $userId = intval($this->user_id) ?: 0;
62
63 2
        $query->andFilterWhere(['id' => $this->id]);
64 2
        $query->andFilterWhere(['entry_id' => $this->entry_id]);
65 2
        $query->andFilterWhere(['user_id' => $userId]);
66 2
        $query->andFilterWhere(['action' => $this->action]);
67 2
        $query->andFilterWhere(['like', 'model', $this->model]);
68 2
        $query->andFilterWhere(['model_id' => $this->model_id]);
69 2
        if (is_array($this->field)) {
70
            $query->andFilterWhere(['in', 'field', $this->field]);
71
        } else {
72 2
            $query->andFilterWhere(['field' => $this->field]);
73
        }
74 2
        $query->andFilterWhere(['like', 'created', $this->created]);
75
76 2
        return $dataProvider;
77
    }
78
79
    /**
80
     * @return array
81
     */
82 6
    static public function actionFilter()
83
    {
84 6
        return \yii\helpers\ArrayHelper::map(
85 6
            self::find()->select('action')->groupBy('action')->orderBy('action ASC')->all(),
86 6
            'action',
87
            'action'
88 6
        );
89
    }
90
}
91