Completed
Push — develop ( f37ae4...1d947e )
by Nate
18:30
created

ElementCriteriaTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 38
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
getCriteria() 0 1 ?
A resolveCriteria() 0 24 5
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\hubspot\services\resources\traits;
10
11
use flipbox\hubspot\criteria\ResourceCriteriaInterface;
12
use flipbox\hubspot\fields\Resources;
13
use flipbox\ember\helpers\ObjectHelper;
14
use yii\base\InvalidConfigException;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
trait ElementCriteriaTrait
21
{
22
    /**
23
     * @param array $criteria
24
     * @return ResourceCriteriaInterface
25
     */
26
    public abstract function getCriteria(array $criteria = []): ResourceCriteriaInterface;
27
28
    /**
29
     * @param Resources $field
30
     * @param null $criteria
31
     * @return ResourceCriteriaInterface
32
     */
33
    protected function resolveCriteria(Resources $field, $criteria = null): ResourceCriteriaInterface
34
    {
35
        if ($criteria instanceof ResourceCriteriaInterface) {
36
            return $criteria;
37
        }
38
39
        if ($criteria === null) {
40
            return $field->createResourceCriteria();
41
        }
42
43
        if (!is_array($criteria)) {
44
            $criteria = ['class' => $criteria];
45
        }
46
47
        try {
48
            $criteria = ObjectHelper::create($criteria, ResourceCriteriaInterface::class);
49
        } catch (InvalidConfigException $e) {
50
            $criteria = $this->getCriteria($criteria);
0 ignored issues
show
Documentation introduced by
$criteria is of type object<yii\base\BaseObject>, 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...
51
        }
52
53
        /** @var ResourceCriteriaInterface $criteria */
54
55
        return $criteria;
56
    }
57
}
58