Completed
Push — master ( f658d3...26c0e4 )
by Julián
01:22
created

EventIteratorCollection::valid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * event (https://github.com/phpgears/event).
5
 * Event handling.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/event
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\Event;
15
16
use Gears\Event\Exception\InvalidEventException;
17
18
final class EventIteratorCollection implements EventCollection
19
{
20
    /**
21
     * @var \Iterator
22
     */
23
    private $iterator;
24
25
    /**
26
     * EventIteratorCollection constructor.
27
     *
28
     * @param \Iterator $iterator
29
     */
30
    public function __construct(\Iterator $iterator)
31
    {
32
        $this->iterator = $iterator;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     *
38
     * @return Event
39
     */
40
    public function current(): Event
41
    {
42
        $event = $this->iterator->current();
43
44
        if (!$event instanceof Event) {
45
            throw new InvalidEventException(\sprintf(
46
                'Event collection only accepts %s, %s given',
47
                Event::class,
48
                \is_object($event) ? \get_class($event) : \gettype($event)
49
            ));
50
        }
51
52
        return $event;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function next(): void
59
    {
60
        $this->iterator->next();
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     *
66
     * @return string|int|null
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
67
     */
68
    public function key()
69
    {
70
        return $this->iterator->key();
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function valid(): bool
77
    {
78
        return $this->iterator->valid();
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function rewind(): void
85
    {
86
        $this->iterator->rewind();
87
    }
88
}
89