TaxonomyDefSearch::search()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 9.456
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace nkostadinov\taxonomy\models;
4
5
use Yii;
6
use yii\base\Model;
7
use yii\data\ActiveDataProvider;
8
use nkostadinov\taxonomy\models\TaxonomyDef;
9
10
/**
11
 * TaxonomyDefSearch represents the model behind the search form about `nkostadinov\taxonomy\models\TaxonomyDef`.
12
 */
13
class TaxonomyDefSearch extends TaxonomyDef
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function rules()
19
    {
20
        return [
21
            [['id', 'total_count'], 'integer'],
22
            [['name', 'class', 'created_at', 'data_table', 'ref_table'], 'safe'],
23
        ];
24
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function scenarios()
30
    {
31
        // bypass scenarios() implementation in the parent class
32
        return Model::scenarios();
33
    }
34
35
    /**
36
     * Creates data provider instance with search query applied
37
     *
38
     * @param array $params
39
     *
40
     * @return ActiveDataProvider
41
     */
42
    public function search($params)
43
    {
44
        $query = TaxonomyDef::find();
45
46
        $dataProvider = new ActiveDataProvider([
47
            'query' => $query,
48
        ]);
49
50
        $this->load($params);
51
52
        if (!$this->validate()) {
53
            // uncomment the following line if you do not want to any records when validation fails
54
            // $query->where('0=1');
55
            return $dataProvider;
56
        }
57
58
        $query->andFilterWhere([
59
            'id' => $this->id,
60
            'created_at' => $this->created_at,
61
            'total_count' => $this->total_count,
62
        ]);
63
64
        $query->andFilterWhere(['like', 'name', $this->name])
65
            ->andFilterWhere(['like', 'class', $this->class])
66
            ->andFilterWhere(['like', 'data_table', $this->data_table])
0 ignored issues
show
Documentation introduced by
The property data_table does not exist on object<nkostadinov\taxon...dels\TaxonomyDefSearch>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
67
            ->andFilterWhere(['like', 'ref_table', $this->ref_table]);
0 ignored issues
show
Documentation introduced by
The property ref_table does not exist on object<nkostadinov\taxon...dels\TaxonomyDefSearch>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
68
69
        return $dataProvider;
70
    }
71
}
72