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.
Completed
Push — master ( c7c1c4...7f7967 )
by Vadim
02:31
created

BeforeQueryTrait::find()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 26
rs 6.7272
cc 7
eloc 17
nc 12
nop 0
1
<?php
2
3
namespace sibds\components;
4
5
trait BeforeQueryTrait
6
{
7
8
    public static function find()
9
    {
10
        /**
11
         * @var $obj ActiveRecord
12
         */
13
        $obj = new static;
14
        $class = new \ReflectionClass($obj);
15
        $condition = [];
16
        foreach ($class->getProperties(\ReflectionProperty::IS_STATIC) as $property) {
17
            if (strpos($property->getName(), 'BEFORE_QUERY') !== false && is_array($property->getValue($obj))) {
18
                $params = $property->getValue($obj);
19
                foreach($params as $key => $value){
20
                    $params[$obj::tableName().'.'.$key] = $value;
21
                    unset($params[$key]);
22
                }
23
                $condition = array_merge($condition, $params);
24
            }
25
        }
26
27
        if ($obj->hasAttribute($obj->removedAttribute))
28
            return (new DynamicQuery($obj))->findRemoved()->andFilterWhere($condition);
0 ignored issues
show
Documentation introduced by
$obj is of type object<sibds\components\ActiveRecord>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation Bug introduced by
The method findRemoved does not exist on object<sibds\components\DynamicQuery>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
29
        elseif ($obj->isNestedSet())
30
            return (new DynamicQuery($obj))->andFilterWhere($condition);
0 ignored issues
show
Documentation introduced by
$obj is of type object<sibds\components\ActiveRecord>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
31
        else
32
            return parent::find()->andFilterWhere($condition);
33
    }
34
}
35