QueryReader   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 53.56%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 68
ccs 15
cts 28
cp 0.5356
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A rewind() 0 4 1
A next() 0 4 1
A valid() 0 4 1
A current() 0 4 1
A key() 0 4 1
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