Completed
Push — master ( 646730...43a697 )
by Vitaly
05:45
created

Entity::find()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
rs 9.4286
cc 3
eloc 9
nc 3
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: VITALYIEGOROV
5
 * Date: 08.12.15
6
 * Time: 23:11
7
 */
8
namespace samsoncms\api\query;
9
10
use samson\activerecord\dbQuery;
11
12
/**
13
 * Material with additional fields query.
14
 * @package samsoncms\api
15
 */
16
class Entity
17
{
18
    /** @var string Entity identifier */
19
    protected static $identifier;
20
21
    /** @var string Entity navigation identifiers */
22
    protected static $navigationIDs;
23
24
    /** @var array Collection of entity field filter */
25
    protected $fieldFilter;
26
27
    /**
28
     * Set additional entity field condition.
29
     *
30
     * @param string $fieldName Field identifier
31
     * @param string $fieldValue Field value
32
     * @return self Chaining
33
     */
34
    public function where($fieldName, $fieldValue)
35
    {
36
        if (property_exists(static::$identifier, $fieldName)) {
37
            $this->fieldFilter[$fieldName] = $fieldValue;
38
        }
39
    }
40
41
    /**
42
     * Perform SamsonCMS query and get entities collection.
43
     *
44
     * @return mixed[] Collection of found entities
45
     */
46
    public function find()
47
    {
48
        $return = array();
49
        /** @var array $idsByNavigation First step - filter by navigation */
50
        if (sizeof($idsByNavigation = (new MaterialNavigation())->idsByRelationID(static::$navigationIDs))) {
51
            // Second step filter by additional field value
52
            if (sizeof($this->fieldFilter)) {
53
                $return = (new MaterialField($idsByNavigation))
0 ignored issues
show
Documentation introduced by
$idsByNavigation is of type boolean|object<samsonfra...rk\orm\RecordInterface>, but the function expects a array.

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...
54
                    ->byRelationID($this->fieldFilter[]);
55
            } else { // Just return entities filtered by navigation
56
                return (new Material($idsByNavigation, static::$identifier))->byIDs($idsByNavigation, 'exec');
0 ignored issues
show
Documentation introduced by
$idsByNavigation is of type boolean|object<samsonfra...rk\orm\RecordInterface>, but the function expects a array.

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 introduced by
$idsByNavigation is of type boolean|object<samsonfra...rk\orm\RecordInterface>, but the function expects a string|array.

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...
57
            }
58
        }
59
60
        return $return;
61
    }
62
}
63