Completed
Pull Request — master (#36)
by Daniel
03:38
created

CollectionView::buildView()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 20
Code Lines 12

Duplication

Lines 6
Ratio 30 %

Importance

Changes 0
Metric Value
dl 6
loc 20
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 12
nc 3
nop 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A CollectionView::getTemplate() 0 4 1
1
<?php
2
3
namespace Psi\Component\ContentType\Standard\View;
4
5
use Psi\Component\ContentType\View\ViewFactory;
6
use Psi\Component\ContentType\View\ViewInterface;
7
8
class CollectionView implements ViewInterface, \Iterator
9
{
10
    private $collection;
11
    private $factory;
12
    private $template;
13
    private $viewType;
14
    private $viewOptions;
15
16
    public function __construct(
17
        string $template,
18
        ViewFactory $factory,
19
        \Traversable $collection,
20
        string $viewType,
21
        array $viewOptions
22
    )
23
    {
24
        $this->template = $template;
25
        $this->factory = $factory;
26
        $this->collection = $collection;
27
        $this->viewType = $viewType;
28
        $this->viewOptions = $viewOptions;
29
    }
30
31
    public function getTemplate(): string
32
    {
33
        return $this->template;
34
    }
35
36
    public function current()
37
    {
38
        return $this->factory->create(
39
            $this->viewType,
40
            current($this->collection),
41
            $this->viewOptions
42
        );
43
    }
44
45
    public function next()
46
    {
47
        next($this->collection);
48
    }
49
50
    public function key()
51
    {
52
        return key($this->collection);
53
    }
54
55
    public function rewind()
56
    {
57
        reset($this->collection);
58
    }
59
60
    public function valid()
61
    {
62
        return key($this->collection) !== null;
63
    }
64
}
65