Completed
Push — master ( 06b50b...ceafbf )
by Vitaly
03:00
created

MaterialField   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
B idsByRelationID() 0 24 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
13
/**
14
 * Retrieve materials by additional fields.
15
 * @package samsoncms\api
16
 */
17
class MaterialField extends Base
18
{
19
    /** MaterialQuery constructor */
20
    public function __construct()
21
    {
22
        parent::__construct(
23
            new dbQuery(),
24
            __NAMESPACE__.'\Material',
25
            Field::$_primary,
26
            CMS::MATERIAL_FIELD_RELATION_ENTITY
27
        );
28
    }
29
30
    /**
31
     * Get current entity identifiers collection by relation identifier ans its value.
32
     *
33
     * @param string $relationID Relation entity identifier
34
     * @param mixed $relationValue Relation entity value
35
     * @param array $filteringIDs Collection of entity identifiers for filtering query
36
     * @return array Collection of entity identifiers filtered by navigation identifier.
37
     */
38
    public function idsByRelationID($relationID, $relationValue = null, $filteringIDs = null)
39
    {
40
        $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 60 which is incompatible with the return type of the parent method samsoncms\api\query\Base::idsByRelationID of type boolean|samsonframework\orm\RecordInterface.
Loading history...
41
42
        /** @var Field $fieldRecord We need to have field record */
43
        $fieldRecord = null;
44
        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...
45
            // Get material identifiers by field
46
            $this->query->entity($this->relationIdentifier)
47
                ->where(self::DELETE_FLAG_FIELD, 1)
48
                ->where($this->relationIdentifier, $relationID)
49
                ->where($fieldRecord->valueFieldName(), $relationValue);
50
51
            // Add material identifier filter if passed
52
            if (isset($filteringIDs)) {
53
                $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...
54
            }
55
56
            // Perform database query and get only material identifiers collection
57
            $return = $this->query->fields($this->primaryField);
58
        }
59
60
        return $return;
61
    }
62
}
63