QueryReader::key()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace pastuhov\ymlcatalog\readers;
4
5
use pastuhov\ymlcatalog\ReaderInterface;
6
use yii\base\Exception;
7
use yii\db\ActiveQuery;
8
9
/**
10
 * Класс выборки данных с помощью Query.
11
 *
12
 * @package pastuhov\ymlcatalog\readers
13
 */
14
class QueryReader implements ReaderInterface
15
{
16
    /**
17
     * @var ActiveQuery|null
18
     */
19
    protected $query = null;
20
21
    /**
22
     * @var null|\yii\db\BatchQueryResult
23
     */
24
    protected $iterator = null;
25
26
    /**
27
     * @inheritdoc
28
     *
29
     * @param ActiveQuery   $query
30
     * @param int           $pageSize
31
     */
32 5
    public function __construct(ActiveQuery $query = null, $pageSize = self::DEFAULT_PAGE_SIZE)
33
    {
34 5
        if (is_null($query)) {
35
            throw new Exception('Query can`t be empty.');
36
        }
37
38 5
        $this->query = $query;
39 5
        $this->iterator = $this->query->batch($pageSize);
40 5
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45 5
    public function rewind()
46
    {
47 5
        $this->iterator->rewind();
48 5
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53 5
    public function next()
54
    {
55 5
        $this->iterator->next();
56 5
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61 5
    public function valid()
62
    {
63 5
        return $this->iterator->valid();
64
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69 5
    public function current()
70
    {
71 5
        return $this->iterator->current();
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77
    public function key()
78
    {
79
        return $this->iterator->key();
80
    }
81
}
82