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.
Test Setup Failed
Push — filters ( 0da638...f31b5a )
by
unknown
16:04
created

SearchModelTrait::addCondition()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6667
cc 2
eloc 6
nc 2
nop 4
1
<?php
2
3
namespace app\backgroundtasks\traits;
4
5
use yii\data\ActiveDataProvider;
6
use yii\db\ActiveQueryInterface;
7
8
/**
9
 * Class SearchModelTrait
10
 * @package app\backgroundtasks\traits
11
 * @author evgen-d <[email protected]>
12
 */
13
trait SearchModelTrait
14
{
15
16
    public function search($params)
17
    {
18
        /* @var $query \yii\db\ActiveQuery */
19
        $query = self::find();
20
21
        $dataProvider = new ActiveDataProvider(
22
            [
23
                'query' => $query,
24
            ]
25
        );
26
27
        /* @var \yii\db\ActiveRecord|SearchModelTrait $this */
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
28
        if (!($this->load($params) && $this->validate())) {
0 ignored issues
show
Bug introduced by
It seems like load() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like validate() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
29
            return $dataProvider;
30
        }
31
32
        foreach ($this->scenarios()['search'] as $field) {
0 ignored issues
show
Bug introduced by
It seems like scenarios() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
33
            $this->addCondition($query, $this->tableName(), $field);
0 ignored issues
show
Bug introduced by
It seems like tableName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
34
        }
35
36
        return $dataProvider;
37
    }
38
39
    protected function addCondition(ActiveQueryInterface $query, $tableName, $attribute, $partialMatch = false)
40
    {
41
        $value = $this->$attribute;
42
        if ($partialMatch) {
43
            $query->andFilterWhere(['like', $tableName . '.' . $attribute, $value]);
44
        } else {
45
            $query->andFilterWhere([$tableName . '.' . $attribute => $value]);
46
        }
47
    }
48
}
49