Completed
Push — master ( 3cc013...251925 )
by Vitaly
02:41
created

MaterialField::idsByRelationID()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 24
rs 8.9714
cc 3
eloc 12
nc 3
nop 3
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
use samsoncms\api\Field;
12
use samsoncms\api\CMS;
13
14
/**
15
 * Retrieve materials by additional fields.
16
 * @package samsoncms\api
17
 */
18
class MaterialField extends Base
19
{
20
    /**
21
     * MaterialField constructor
22
     * @param array $filteringIDs Collection of entity identifiers for filtering
23
     */
24
    public function __construct($filteringIDs = array())
25
    {
26
        parent::__construct(
27
            new dbQuery(),
28
            '\samsoncms\api\Material',
29
            Field::$_primary,
30
            CMS::MATERIAL_FIELD_RELATION_ENTITY,
31
            $filteringIDs
32
        );
33
    }
34
35
    /**
36
     * Get current entity identifiers collection by relation identifier ans its value.
37
     *
38
     * @param string $relationID Relation entity identifier
39
     * @param mixed $relationValue Relation entity value
40
     * @param array $filteringIDs Collection of entity identifiers for filtering query
41
     * @return array Collection of entity identifiers filtered by navigation identifier.
42
     */
43
    public function idsByRelationID($relationID, $relationValue = null, array $filteringIDs = array())
44
    {
45
        $return = array();
0 ignored issues
show
Bug Compatibility introduced by
The expression array(); of type array adds the type array to the return on line 65 which is incompatible with the return type of the parent method samsoncms\api\query\Base::idsByRelationID of type boolean|samsonframework\orm\RecordInterface.
Loading history...
46
47
        /** @var Field $fieldRecord We need to have field record */
48
        $fieldRecord = null;
49
        if (Field::byID($this->query, $relationID, $fieldRecord)) {
0 ignored issues
show
Documentation introduced by
$fieldRecord is of type object<samsoncms\api\Field>, but the function expects a null|object<self>.

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...
50
            // Get material identifiers by field
51
            $this->query->entity($this->relationIdentifier)
52
                ->where(self::DELETE_FLAG_FIELD, 1)
53
                ->where($this->relationPrimary, $relationID)
54
                ->where($fieldRecord->valueFieldName(), $relationValue);
55
56
            // Add material identifier filter if passed
57
            if (isset($filteringIDs)) {
58
                $this->query->where($this->primaryField, $filteringIDs);
0 ignored issues
show
Documentation introduced by
$filteringIDs is of type array, but the function expects a string|null.

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...
59
            }
60
61
            // Perform database query and get only material identifiers collection
62
            $return = $this->query->fields($this->primaryField);
63
        }
64
65
        return $return;
66
    }
67
}
68