Completed
Push — master ( 477ca5...2d5ed5 )
by Daniel
10s
created

CollectionView   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 56
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A getTemplate() 0 4 1
A current() 0 8 1
A next() 0 4 1
A key() 0 4 1
A rewind() 0 4 1
A valid() 0 4 1
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 $template;
15
    private $viewType;
16
    private $viewOptions;
17
18
    public function __construct(
19
        string $template,
20
        ViewFactory $factory,
21
        \Traversable $collection,
22
        string $viewType,
23
        array $viewOptions
24
    ) {
25
        $this->template = $template;
26
        $this->factory = $factory;
27
        $this->collection = $collection;
28
        $this->viewType = $viewType;
29
        $this->viewOptions = $viewOptions;
30
    }
31
32
    public function getTemplate(): string
33
    {
34
        return $this->template;
35
    }
36
37
    public function current()
38
    {
39
        return $this->factory->create(
40
            $this->viewType,
41
            current($this->collection),
42
            $this->viewOptions
43
        );
44
    }
45
46
    public function next()
47
    {
48
        next($this->collection);
49
    }
50
51
    public function key()
52
    {
53
        return key($this->collection);
54
    }
55
56
    public function rewind()
57
    {
58
        reset($this->collection);
59
    }
60
61
    public function valid()
62
    {
63
        return key($this->collection) !== null;
64
    }
65
}
66