CollectionView::valid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\ContentType\Standard\View;
6
7
use Psi\Component\ContentType\View\ViewFactory;
8
use Psi\Component\ContentType\View\ViewInterface;
9
10
class CollectionView implements ViewInterface, \Iterator
11
{
12
    private $collection;
13
    private $factory;
14
    private $viewType;
15
    private $viewOptions;
16
17
    public function __construct(
18
        ViewFactory $factory,
19
        \Traversable $collection,
20
        string $viewType,
21
        array $viewOptions
22
    ) {
23
        $this->factory = $factory;
24
        $this->collection = new \IteratorIterator($collection);
25
        $this->viewType = $viewType;
26
        $this->viewOptions = $viewOptions;
27
    }
28
29
    public function current()
30
    {
31
        return $this->factory->create(
32
            $this->viewType,
33
            $this->collection->current(),
34
            $this->viewOptions
35
        );
36
    }
37
38
    public function next()
39
    {
40
        return $this->collection->next();
41
    }
42
43
    public function key()
44
    {
45
        return $this->collection->key();
46
    }
47
48
    public function rewind()
49
    {
50
        return $this->collection->rewind();
51
    }
52
53
    public function valid()
54
    {
55
        return $this->collection->valid();
56
    }
57
}
58