Completed
Push — master ( 6db6da...5370d9 )
by Angel
03:42
created

Index   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 8 2
A run() 0 13 2
1
<?php
2
3
namespace roaresearch\yii2\roa\actions;
4
5
use Yii;
6
use yii\{base\InvalidConfigException, data\ActiveDataProvider};
7
8
/**
9
 * Action to retreive a filtered and sorted collection based on a `$searchClass`
10
 *
11
 * @author Angel (Faryshta) Guevara <[email protected]>
12
 */
13
class Index extends Action
14
{
15
    /**
16
     * @var string model class to retreive the records on the collection.
17
     */
18
    public $searchClass;
19
20
    /**
21
     * @var string name of the form containing the filter data.
22
     */
23
    public $formName = '';
24
25
    /**
26
     * @inheritdoc
27
     */
28
    public function init()
29
    {
30
        if (empty($this->searchClass)) {
31
            throw new InvalidConfigException(
32
                get_class($this) . '::$searchClass must be set.'
33
            );
34
        }
35
    }
36
37
    /**
38
     * @return ActiveDataProvider|ActiveRecord
39
     */
40
    public function run()
41
    {
42
        $searchClass = $this->searchClass;
43
        /* @var $searchModel \yii\db\ActiveRecordInterface */
44
        $searchModel = new $searchClass();
45
        $dataProvider = $searchModel->search(
0 ignored issues
show
Bug introduced by
The method search() does not seem to exist on object<yii\db\ActiveRecordInterface>.

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...
46
            Yii::$app->request->queryParams,
47
            $this->formName
48
        );
49
        $this->checkAccess($searchModel, Yii::$app->request->getQueryParams());
50
51
        return $dataProvider ?: $searchModel;
52
    }
53
}
54