Completed
Push — master ( 1fd713...646730 )
by Vitaly
05:38
created

Entity   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A byIDs() 0 7 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: VITALYIEGOROV
5
 * Date: 09.12.15
6
 * Time: 12:10
7
 */
8
namespace samsoncms\api;
9
10
use samsoncms\api\query\FieldNavigation;
11
use samsonframework\orm\QueryInterface;
12
13
/**
14
 * SamsonCMS Entity that has relation to specific navigation
15
 * and though has additional fields.
16
 *
17
 * @package samsoncms\api
18
 */
19
class Entity extends Material
20
{
21
    /** @var QueryInterface Database query instance */
22
    protected $query;
23
24
    /** @var array Collection of additional fields identifiers */
25
    protected static $fieldIDs;
26
27
    /** @var array Collection of navigation identifiers */
28
    protected static $navigationIDs;
29
30
    public static function byIDs(QueryInterface $query, $ids)
31
    {
32
        // Get additional fields records for passed materials and this entity fields
33
        foreach (MaterialField::byFieldIDAndMaterialID($query, self::$fieldIDs, $ids) as $additionalField) {
0 ignored issues
show
Documentation introduced by
self::$fieldIDs is of type array, 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...
Bug introduced by
The expression \samsoncms\api\MaterialF... self::$fieldIDs, $ids) of type boolean|null|array<integ...cms\api\MaterialField>> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
34
35
        }
36
    }
37
}
38