Completed
Push — master ( 98eb76...c74b62 )
by Max
01:10
created

HydrateIterator::current()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 *  @copyright (c) 2019 Mendel <[email protected]>
5
 *  @license see license.txt
6
 */
7
8
namespace drycart\data\Iterator;
9
use drycart\data\Hydrator;
10
11
/**
12
 * Hydrate iterator
13
 * wrap iterator of array and return hydrated models
14
 *
15
 * @author mendel
16
 */
17
class HydrateIterator extends \IteratorIterator
18
{
19
    /**
20
     * Model class for hydrated data
21
     * @var string
22
     */
23
    protected $modelClass;
24
    
25
    /**
26
     * Constructor
27
     * @param \Traversable $iterator
28
     * @param string $modelClass
29
     */
30
    public function __construct(\Traversable $iterator, string $modelClass)
31
    {
32
        $this->modelClass = $modelClass;
33
        parent::__construct($iterator);
34
    }
35
36
    /**
37
     * return hydrated object
38
     * 
39
     * @return mixed
40
     */
41
    public function current()
42
    {
43
        $data = parent::current();
44
        return Hydrator::hydrate($this->modelClass, $data);
45
    }
46
}
47