IndexAction   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 7
eloc 17
c 5
b 0
f 0
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 17 6
A getSearchModel() 0 3 1
1
<?php
2
3
4
namespace carono\yii2crud\actions;
5
6
7
use carono\yii2crud\CrudController;
8
use Closure;
9
use yii\db\ActiveRecord;
10
11
/**
12
 * Class IndexAction
13
 *
14
 * @package carono\yii2crud\actions
15
 * @property CrudController $controller
16
 */
17
class IndexAction extends Action
18
{
19
    public $view = 'index';
20
    public $modelSearchClass;
21
    public $query;
22
    public $dataProvider;
23
    public $condition;
24
    public $params;
25
    protected $searchModel;
26
27
    public function getSearchModel()
28
    {
29
        return $this->searchModel;
30
    }
31
32
    public function run()
33
    {
34
        /**
35
         * @var ActiveRecord $searchModel
36
         */
37
        $this->searchModel = $this->modelSearchClass ? new $this->modelSearchClass : null;
38
        $query = is_callable($this->query) ? call_user_func($this->query, $this->modelClass, $this) : $this->query;
39
40
        if (is_callable($this->condition)) {
41
            call_user_func($this->condition, $query, $this);
42
        } elseif ($this->condition) {
43
            $query->andWhere($this->condition);
44
        }
45
46
        $dataProvider = is_callable($this->dataProvider) ? call_user_func($this->dataProvider, $query, $this) : $this->dataProvider;
47
48
        return $this->render($this->view, ['searchModel' => $this->searchModel, 'dataProvider' => $dataProvider]);
49
    }
50
}