ElasticController::actionSpool()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 *
4
 * @author Mihkel Viilveer <[email protected]>
5
 * @date 22.08.2014
6
 */
7
8
namespace opus\elastic\spooler;
9
10
use yii\base\ErrorException;
11
use yii\console\Controller;
12
13
/**
14
 * Class ElasticController
15
 *
16
 * @author Mihkel Viilveer <[email protected]>
17
 * @package opus\elastic\spooler
18
 */
19
class ElasticController extends Controller
20
{
21
    /**
22
     * Data providers to index/spool
23
     * @var string[]
24
     */
25
    public $dataProviders = [];
26
    /**
27
     * @throws \yii\base\ErrorException
28
     */
29
    public function actionImport()
30
    {
31
        $elasticManager = new SpoolManager(
32
            [
33
                'dataProviders' => $this->createDataProviders($this->dataProviders)
0 ignored issues
show
Documentation introduced by
$this->dataProviders is of type array<integer,string>, but the function expects a array<integer,object<opu...\AbstractDataProvider>>.

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...
34
            ]
35
        );
36
        $elasticManager->reindex();
37
    }
38
39
    /**
40
     * @throws \yii\base\ErrorException
41
     */
42
    public function actionSpool()
43
    {
44
        $elasticManager = new SpoolManager(
45
            [
46
                'dataProviders' => $this->createDataProviders($this->dataProviders)
0 ignored issues
show
Documentation introduced by
$this->dataProviders is of type array<integer,string>, but the function expects a array<integer,object<opu...\AbstractDataProvider>>.

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...
47
            ]
48
        );
49
        $elasticManager->spool();
50
    }
51
52
    /**
53
     * @param AbstractDataProvider[] $dataProviders
54
     * @throws ErrorException
55
     * @return array
56
     */
57
    private function createDataProviders(array $dataProviders)
58
    {
59
        $dataProviderModels = [];
60
61
        foreach ($dataProviders as $dataProvider) {
62
            $dataProvider = new $dataProvider();
63
            if (!($dataProvider instanceof AbstractDataProvider)) {
64
                throw new ErrorException(
65
                    'dataProvider is not instance of DataProviderInterface'
66
                );
67
            }
68
            $dataProviderModels[] = $dataProvider;
69
        }
70
        return $dataProviderModels;
71
    }
72
}
73