Completed
Push — master ( f24d29...af6f31 )
by Kirill
12s
created

ReaderFactory::build()   C

Complexity

Conditions 7
Paths 10

Size

Total Lines 33
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 21
nc 10
nop 4
1
<?php
2
3
namespace pastuhov\ymlcatalog;
4
5
use pastuhov\ymlcatalog\readers\DataProviderReader;
6
use pastuhov\ymlcatalog\readers\QueryReader;
7
use yii\data\ActiveDataProvider;
8
use yii\db\ActiveQuery;
9
10
class ReaderFactory
11
{
12
    /**
13
     * Reader Factory builder.
14
     *
15
     * @param BaseFindYmlInterface      $class
16
     * @param ActiveDataProvider|null   $dataProvider
17
     * @param ActiveQuery|null          $query
18
     * @param mixed                     $findParams
19
     *
20
     * @return ReaderInterface
21
     */
22
    public static function build(
23
        BaseFindYmlInterface $class,
24
        ActiveDataProvider $dataProvider = null,
25
        ActiveQuery $query = null,
26
        $findParams = []
27
    )
28
    {
29
        if (!empty($dataProvider)) {
30
            if ($dataProvider instanceof ActiveDataProvider) {
31
                $reader = new DataProviderReader($dataProvider);
32
            } elseif ($dataProvider === true) {
33
                if (!$query) {
34
                    $query = $class::findYml($findParams);
35
                }
36
                $reader = new DataProviderReader(
37
                    new ActiveDataProvider([
38
                        'query' => $query,
39
                        'pagination' => [
40
                            'pageSize' => 1000,
41
                        ]
42
                    ])
43
                );
44
            } else {
45
                $dataProvider = null;
0 ignored issues
show
Unused Code introduced by
$dataProvider is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
46
            }
47
        }
48
49
        if (empty($reader)) {
50
            $reader = new QueryReader($query ? : $class::findYml($findParams));
51
        }
52
53
        return $reader;
54
    }
55
}
56